@kong-ui-public/analytics-metric-provider 9.1.2-pr.2030.3ee7f86d0.0 → 9.1.2-pr.2292.8d06b7c8a.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/style.css +1 -0
  2. package/dist/types/components/MetricCardContainer.vue.d.ts +91 -0
  3. package/dist/types/components/MetricCardContainer.vue.d.ts.map +1 -0
  4. package/dist/types/components/MetricsConsumer.vue.d.ts +41 -0
  5. package/dist/types/components/MetricsConsumer.vue.d.ts.map +1 -0
  6. package/dist/types/components/MetricsProvider.vue.d.ts +70 -0
  7. package/dist/types/components/MetricsProvider.vue.d.ts.map +1 -0
  8. package/dist/types/components/MetricsTestHarness.vue.d.ts +33 -0
  9. package/dist/types/components/MetricsTestHarness.vue.d.ts.map +1 -0
  10. package/dist/types/components/display/MetricCardLoadingSkeleton.vue.d.ts +3 -0
  11. package/dist/types/components/display/MetricCardLoadingSkeleton.vue.d.ts.map +1 -0
  12. package/dist/types/components/display/MetricsCard.vue.d.ts +397 -0
  13. package/dist/types/components/display/MetricsCard.vue.d.ts.map +1 -0
  14. package/dist/types/components/metricsProviderUtil.d.ts +36 -0
  15. package/dist/types/components/metricsProviderUtil.d.ts.map +1 -0
  16. package/dist/types/composables/index.d.ts +12 -0
  17. package/dist/types/composables/index.d.ts.map +1 -0
  18. package/dist/types/composables/useI18n.d.ts +9 -0
  19. package/dist/types/composables/useI18n.d.ts.map +1 -0
  20. package/dist/types/composables/useMetricCardBuilder.d.ts +20 -0
  21. package/dist/types/composables/useMetricCardBuilder.d.ts.map +1 -0
  22. package/dist/types/composables/useMetricFetcher.d.ts +19 -0
  23. package/dist/types/composables/useMetricFetcher.d.ts.map +1 -0
  24. package/dist/types/composables/useRequest.d.ts +12 -0
  25. package/dist/types/composables/useRequest.d.ts.map +1 -0
  26. package/dist/types/constants.d.ts +7 -0
  27. package/dist/types/constants.d.ts.map +1 -0
  28. package/dist/types/enums/index.d.ts +3 -0
  29. package/dist/types/enums/index.d.ts.map +1 -0
  30. package/dist/types/enums/metric-card-size.enum.d.ts +7 -0
  31. package/dist/types/enums/metric-card-size.enum.d.ts.map +1 -0
  32. package/dist/types/enums/metric-card-type.enum.d.ts +7 -0
  33. package/dist/types/enums/metric-card-type.enum.d.ts.map +1 -0
  34. package/dist/types/index.d.ts +8 -0
  35. package/dist/types/index.d.ts.map +1 -0
  36. package/dist/types/mockExploreResponse.d.ts +10 -0
  37. package/dist/types/mockExploreResponse.d.ts.map +1 -0
  38. package/dist/types/types/fetcher-types.d.ts +17 -0
  39. package/dist/types/types/fetcher-types.d.ts.map +1 -0
  40. package/dist/types/types/index.d.ts +3 -0
  41. package/dist/types/types/index.d.ts.map +1 -0
  42. package/dist/types/types/metric-card.d.ts +36 -0
  43. package/dist/types/types/metric-card.d.ts.map +1 -0
  44. package/dist/types/utilities/index.d.ts +2 -0
  45. package/dist/types/utilities/index.d.ts.map +1 -0
  46. package/dist/types/utilities/trend-display.d.ts +24 -0
  47. package/dist/types/utilities/trend-display.d.ts.map +1 -0
  48. package/dist/vitals-metric-provider.es.js +1191 -0
  49. package/dist/vitals-metric-provider.umd.js +1 -0
  50. package/package.json +8 -8
@@ -0,0 +1,1191 @@
1
+ import { ref as H, watchEffect as Me, computed as h, getCurrentInstance as xe, reactive as qe, onMounted as Ue, onUnmounted as ze, watch as Ke, isReadonly as Pe, toRefs as $e, defineComponent as Q, inject as _e, toRef as X, provide as Be, renderSlot as Ie, resolveComponent as Ae, createElementBlock as _, openBlock as T, normalizeClass as K, createElementVNode as x, createCommentVNode as V, createBlock as q, unref as E, resolveDynamicComponent as re, withCtx as ye, createTextVNode as De, toDisplayString as w, createVNode as F, Fragment as he, renderList as Xe, mergeProps as Ge, normalizeProps as je, guardReactiveProps as He } from "vue";
2
+ import { stripUnknownFilters as Ye, TimeframeKeys as se, queryableExploreDimensions as Qe, TimePeriods as be, DeltaQueryTime as We, UnaryQueryTime as Je } from "@kong-ui-public/analytics-utilities";
3
+ import { createI18n as Ze, i18nTComponent as er } from "@kong-ui-public/i18n";
4
+ import "axios";
5
+ import { useAnalyticsConfigStore as rr } from "@kong-ui-public/analytics-config-store";
6
+ import { TrendUpIcon as tr, TrendDownIcon as nr, IndeterminateSmallIcon as we, VitalsIcon as ar, CloudUploadIcon as ir, WarningOutlineIcon as or, ResponseIcon as sr, InfoIcon as ur, WarningIcon as Oe, EqualIcon as lr } from "@kong/icons";
7
+ const cr = {
8
+ notAvailable: "N/A"
9
+ }, dr = {
10
+ small: {
11
+ traffic: "Requests",
12
+ errorRate: "Error rate",
13
+ averageLatency: "Avg. latency",
14
+ p99Latency: "P99 latency"
15
+ },
16
+ short: {
17
+ traffic: "Requests",
18
+ errorRate: "Error rate",
19
+ averageLatency: "Average latency",
20
+ p99Latency: "P99 latency"
21
+ },
22
+ long: {
23
+ traffic: "Number of requests",
24
+ errorRate: "Average error rate",
25
+ averageLatency: "Average latency",
26
+ p99Latency: "P99 latency"
27
+ }
28
+ }, fr = {
29
+ custom: "vs previous {numDays, plural, =1 {day} other {# days}}",
30
+ "15m": "vs previous 15 minutes",
31
+ "1h": "vs previous hour",
32
+ "6h": "vs previous 6 hours",
33
+ "12h": "vs previous 12 hours",
34
+ "24h": "vs previous 24 hours",
35
+ "7d": "vs previous 7 days",
36
+ "30d": "vs previous 30 days",
37
+ current_week: "vs previous week",
38
+ current_month: "vs previous month",
39
+ current_quarter: "vs previous quarter",
40
+ previous_week: "vs previous time period",
41
+ previous_month: "vs previous time period",
42
+ previous_quarter: "vs previous quarter"
43
+ }, vr = {
44
+ general: cr,
45
+ metricCard: dr,
46
+ trendRange: fr
47
+ };
48
+ function mr() {
49
+ const e = Ze("en-us", vr);
50
+ return {
51
+ i18n: e,
52
+ i18nT: er(e)
53
+ // Translation component <i18n-t>
54
+ };
55
+ }
56
+ const yr = 2, $ = ["1XX", "2XX", "3XX", "4XX", "5XX"], ge = ["4XX", "5XX"], pt = ["1XX", "2XX", "3XX"], hr = 30 * 1e3, gr = "analytics-query-provider";
57
+ var Le = /* @__PURE__ */ ((e) => (e.VALIDATING = "VALIDATING", e.VALIDATING_HAS_DATA = "VALIDATING_HAS_DATA", e.PENDING = "PENDING", e.SUCCESS = "SUCCESS", e.SUCCESS_HAS_DATA = "SUCCESS_HAS_DATA", e.ERROR = "ERROR", e.STALE_IF_ERROR = "STALE_IF_ERROR", e))(Le || {});
58
+ const pr = (e) => {
59
+ var r, t, o, a, n;
60
+ return e ? !!// TODO: revisit: currently only the first check ever matters?
61
+ ((r = Object.keys(e)) != null && r.length || (t = e.data) != null && t.length || (a = (o = e.data) == null ? void 0 : o.data) != null && a.length || !((n = e.data) != null && n.data) && typeof e.data == "object" && Object.keys(e == null ? void 0 : e.data).length) : !1;
62
+ };
63
+ function Rr(e = H({}), r, t, o = pr) {
64
+ const a = H(
65
+ "PENDING"
66
+ /* PENDING */
67
+ );
68
+ return Me(() => {
69
+ const n = o(e.value);
70
+ if (e.value && n && t.value) {
71
+ a.value = "VALIDATING_HAS_DATA";
72
+ return;
73
+ }
74
+ if (e.value && t.value) {
75
+ a.value = "VALIDATING";
76
+ return;
77
+ }
78
+ if (e.value && r.value) {
79
+ a.value = "STALE_IF_ERROR";
80
+ return;
81
+ }
82
+ if (e.value === void 0 && !r.value) {
83
+ a.value = "PENDING";
84
+ return;
85
+ }
86
+ if (e.value && !r.value && n) {
87
+ a.value = "SUCCESS_HAS_DATA";
88
+ return;
89
+ }
90
+ if (e.value && !r.value) {
91
+ a.value = "SUCCESS";
92
+ return;
93
+ }
94
+ e.value === void 0 && r && (a.value = "ERROR");
95
+ }), {
96
+ state: a,
97
+ swrvState: Le
98
+ };
99
+ }
100
+ const L = Symbol("default"), te = "status_code_grouped", pe = (e, r, t, o, a) => {
101
+ e[r][t] || (e[r][t] = {}), e[r][t][o] = a;
102
+ };
103
+ function Tr(e, r) {
104
+ var c;
105
+ const t = ((c = e.meta.metric_names) == null ? void 0 : c[0]) || "", o = e.meta.start_ms, a = Object.keys(e.meta.display || {}), n = !!a.find((f) => f === te), l = a.find((f) => f !== te);
106
+ return a.length > 2 || a.length > 1 && !n ? (console.error("Don't know how to work with provided dimensions:", a), {
107
+ previous: { [L]: { [L]: 0 } },
108
+ current: { [L]: { [L]: 0 } }
109
+ }) : e.data.reduce((f, i) => {
110
+ const s = i.event[t], u = l ? i.event[l] : L, d = n ? i.event[te] : L;
111
+ return new Date(i.timestamp).getTime() === o && r ? pe(f, "previous", u, d, s) : pe(f, "current", u, d, s), f;
112
+ }, {
113
+ previous: {},
114
+ current: {}
115
+ });
116
+ }
117
+ function Er(e) {
118
+ e.queryReady === void 0 && (e.queryReady = h(() => !0));
119
+ const { i18n: r } = N.useI18n(), t = h(() => {
120
+ var u, d;
121
+ return {
122
+ metrics: e.metrics.value,
123
+ dimensions: [
124
+ ...(u = e.dimensions) != null && u.length ? [...e.dimensions] : [],
125
+ ...e.withTrend.value ? ["time"] : []
126
+ ],
127
+ granularity: e.withTrend.value ? "trend" : void 0,
128
+ ...(d = e.filter.value) != null && d.length ? { filters: e.filter.value } : {},
129
+ time_range: e.timeframe.value.v4Query(e.tz.value)
130
+ };
131
+ }), o = h(() => {
132
+ var d, v, g, R;
133
+ if (!((d = e.queryReady) != null && d.value))
134
+ return null;
135
+ const u = (v = e.filter) != null && v.value ? JSON.stringify(e.filter.value) : "";
136
+ return `metric-fetcher-${e.timeframe.value.cacheKey()}-${(g = e.dimensions) == null ? void 0 : g.join("-")}-${(R = e.metrics.value) == null ? void 0 : R.join("-")}-${u}-${e.refreshCounter.value}`;
137
+ }), { response: a, error: n, isValidating: l } = N.useRequest(
138
+ () => o.value,
139
+ () => e.queryFn({
140
+ // TODO: Use a type guard to validate that if the datasource is basic,
141
+ // the query is a valid basic explore query.
142
+ datasource: e.datasource.value,
143
+ query: t.value
144
+ }, e.abortController ?? new AbortController()),
145
+ {
146
+ refreshInterval: e.refreshInterval,
147
+ revalidateOnFocus: !1,
148
+ errorRetryCount: yr
149
+ }
150
+ ), { state: c, swrvState: f } = Rr(a, n, l), i = h(() => {
151
+ var u, d, v, g, R, m, C;
152
+ return !((d = (u = a.value) == null ? void 0 : u.data) != null && d.length) || !((g = (v = a.value) == null ? void 0 : v.meta) != null && g.display) || !((C = (m = (R = a.value) == null ? void 0 : R.meta) == null ? void 0 : m.metric_names) != null && C.length) ? { current: {}, previous: {} } : Tr(a.value, e.withTrend.value);
153
+ }), s = h(() => {
154
+ var u, d;
155
+ if (e.timeframe.value.key === "custom") {
156
+ if (!((d = (u = a.value) == null ? void 0 : u.meta) != null && d.start_ms))
157
+ return "";
158
+ const { start_ms: v, end_ms: g } = a.value.meta;
159
+ let R = (g - v) / (1e3 * 60 * 60 * 24);
160
+ return e.withTrend.value && (R /= 2), r.t("trendRange.custom", { numDays: Math.round(R) });
161
+ } else
162
+ return e.withTrend.value ? r.t(`trendRange.${e.timeframe.value.key}`) : "";
163
+ });
164
+ return {
165
+ isLoading: h(() => f.PENDING === c.value),
166
+ hasError: h(() => f.ERROR === c.value),
167
+ raw: a,
168
+ mapped: i,
169
+ trendRange: s
170
+ };
171
+ }
172
+ const P = (e, r, t = L, o) => (o ?? [L]).reduce((n, l) => {
173
+ const c = e[r][t];
174
+ return c ? n + (c[l] || 0) : n;
175
+ }, 0);
176
+ function Cr(e) {
177
+ const {
178
+ cardType: r,
179
+ title: t,
180
+ description: o,
181
+ record: a,
182
+ hasError: n,
183
+ increaseIsBad: l,
184
+ formatValueFn: c,
185
+ trendRange: f
186
+ } = e;
187
+ return h(() => {
188
+ let i = 0, s = 0;
189
+ if (a != null && a.value)
190
+ try {
191
+ i = P(a.value, "current", e.lookupKey, e.sumGroupedValues), s = P(a.value, "previous", e.lookupKey, e.sumGroupedValues);
192
+ } catch (u) {
193
+ console.error(
194
+ "Metric card data doesn't have the expected structure:",
195
+ u
196
+ );
197
+ }
198
+ return {
199
+ cardType: r,
200
+ hasError: n.value,
201
+ currentValue: i,
202
+ previousValue: s,
203
+ title: t.value,
204
+ description: o,
205
+ increaseIsBad: !!l,
206
+ // Coerce undefined to false
207
+ formatValueFn: c,
208
+ trendRange: f == null ? void 0 : f.value
209
+ };
210
+ });
211
+ }
212
+ var ne = /* @__PURE__ */ new WeakMap(), Re = 0;
213
+ function Sr(e) {
214
+ if (!e.length)
215
+ return "";
216
+ for (var r = "arg", t = 0; t < e.length; ++t) {
217
+ var o = void 0;
218
+ e[t] === null || typeof e[t] != "object" && typeof e[t] != "function" ? typeof e[t] == "string" ? o = '"' + e[t] + '"' : o = String(e[t]) : ne.has(e[t]) ? o = ne.get(e[t]) : (o = Re, ne.set(e[t], Re++)), r += "@" + o;
219
+ }
220
+ return r;
221
+ }
222
+ function _r(e) {
223
+ if (typeof e == "function")
224
+ try {
225
+ e = e();
226
+ } catch {
227
+ e = "";
228
+ }
229
+ return Array.isArray(e) ? e = Sr(e) : e = String(e || ""), e;
230
+ }
231
+ var ue = (
232
+ /** @class */
233
+ function() {
234
+ function e(r) {
235
+ r === void 0 && (r = 0), this.items = /* @__PURE__ */ new Map(), this.ttl = r;
236
+ }
237
+ return e.prototype.serializeKey = function(r) {
238
+ return _r(r);
239
+ }, e.prototype.get = function(r) {
240
+ var t = this.serializeKey(r);
241
+ return this.items.get(t);
242
+ }, e.prototype.set = function(r, t, o) {
243
+ var a = this.serializeKey(r), n = o || this.ttl, l = Date.now(), c = {
244
+ data: t,
245
+ createdAt: l,
246
+ expiresAt: n ? l + n : 1 / 0
247
+ };
248
+ this.dispatchExpire(n, c, a), this.items.set(a, c);
249
+ }, e.prototype.dispatchExpire = function(r, t, o) {
250
+ var a = this;
251
+ r && setTimeout(function() {
252
+ var n = Date.now(), l = n >= t.expiresAt;
253
+ l && a.delete(o);
254
+ }, r);
255
+ }, e.prototype.delete = function(r) {
256
+ this.items.delete(r);
257
+ }, e;
258
+ }()
259
+ );
260
+ function Ir() {
261
+ return typeof navigator.onLine < "u" ? navigator.onLine : !0;
262
+ }
263
+ function Ar() {
264
+ return typeof document < "u" && typeof document.visibilityState < "u" ? document.visibilityState !== "hidden" : !0;
265
+ }
266
+ var Dr = function(e) {
267
+ return fetch(e).then(function(r) {
268
+ return r.json();
269
+ });
270
+ };
271
+ const ae = {
272
+ isOnline: Ir,
273
+ isDocumentVisible: Ar,
274
+ fetcher: Dr
275
+ };
276
+ var b = function() {
277
+ return b = Object.assign || function(e) {
278
+ for (var r, t = 1, o = arguments.length; t < o; t++) {
279
+ r = arguments[t];
280
+ for (var a in r) Object.prototype.hasOwnProperty.call(r, a) && (e[a] = r[a]);
281
+ }
282
+ return e;
283
+ }, b.apply(this, arguments);
284
+ }, U = function(e, r, t, o) {
285
+ function a(n) {
286
+ return n instanceof t ? n : new t(function(l) {
287
+ l(n);
288
+ });
289
+ }
290
+ return new (t || (t = Promise))(function(n, l) {
291
+ function c(s) {
292
+ try {
293
+ i(o.next(s));
294
+ } catch (u) {
295
+ l(u);
296
+ }
297
+ }
298
+ function f(s) {
299
+ try {
300
+ i(o.throw(s));
301
+ } catch (u) {
302
+ l(u);
303
+ }
304
+ }
305
+ function i(s) {
306
+ s.done ? n(s.value) : a(s.value).then(c, f);
307
+ }
308
+ i((o = o.apply(e, r || [])).next());
309
+ });
310
+ }, z = function(e, r) {
311
+ var t = { label: 0, sent: function() {
312
+ if (n[0] & 1) throw n[1];
313
+ return n[1];
314
+ }, trys: [], ops: [] }, o, a, n, l;
315
+ return l = { next: c(0), throw: c(1), return: c(2) }, typeof Symbol == "function" && (l[Symbol.iterator] = function() {
316
+ return this;
317
+ }), l;
318
+ function c(i) {
319
+ return function(s) {
320
+ return f([i, s]);
321
+ };
322
+ }
323
+ function f(i) {
324
+ if (o) throw new TypeError("Generator is already executing.");
325
+ for (; t; ) try {
326
+ if (o = 1, a && (n = i[0] & 2 ? a.return : i[0] ? a.throw || ((n = a.return) && n.call(a), 0) : a.next) && !(n = n.call(a, i[1])).done) return n;
327
+ switch (a = 0, n && (i = [i[0] & 2, n.value]), i[0]) {
328
+ case 0:
329
+ case 1:
330
+ n = i;
331
+ break;
332
+ case 4:
333
+ return t.label++, { value: i[1], done: !1 };
334
+ case 5:
335
+ t.label++, a = i[1], i = [0];
336
+ continue;
337
+ case 7:
338
+ i = t.ops.pop(), t.trys.pop();
339
+ continue;
340
+ default:
341
+ if (n = t.trys, !(n = n.length > 0 && n[n.length - 1]) && (i[0] === 6 || i[0] === 2)) {
342
+ t = 0;
343
+ continue;
344
+ }
345
+ if (i[0] === 3 && (!n || i[1] > n[0] && i[1] < n[3])) {
346
+ t.label = i[1];
347
+ break;
348
+ }
349
+ if (i[0] === 6 && t.label < n[1]) {
350
+ t.label = n[1], n = i;
351
+ break;
352
+ }
353
+ if (n && t.label < n[2]) {
354
+ t.label = n[2], t.ops.push(i);
355
+ break;
356
+ }
357
+ n[2] && t.ops.pop(), t.trys.pop();
358
+ continue;
359
+ }
360
+ i = r.call(e, t);
361
+ } catch (s) {
362
+ i = [6, s], a = 0;
363
+ } finally {
364
+ o = n = 0;
365
+ }
366
+ if (i[0] & 5) throw i[1];
367
+ return { value: i[0] ? i[1] : void 0, done: !0 };
368
+ }
369
+ }, br = function(e, r) {
370
+ var t = typeof Symbol == "function" && e[Symbol.iterator];
371
+ if (!t) return e;
372
+ var o = t.call(e), a, n = [], l;
373
+ try {
374
+ for (; (r === void 0 || r-- > 0) && !(a = o.next()).done; ) n.push(a.value);
375
+ } catch (c) {
376
+ l = { error: c };
377
+ } finally {
378
+ try {
379
+ a && !a.done && (t = o.return) && t.call(o);
380
+ } finally {
381
+ if (l) throw l.error;
382
+ }
383
+ }
384
+ return n;
385
+ }, wr = function(e, r, t) {
386
+ if (t || arguments.length === 2) for (var o = 0, a = r.length, n; o < a; o++)
387
+ (n || !(o in r)) && (n || (n = Array.prototype.slice.call(r, 0, o)), n[o] = r[o]);
388
+ return e.concat(n || Array.prototype.slice.call(r));
389
+ }, Ve = new ue(), Y = new ue(), ie = new ue(), ke = {
390
+ cache: Ve,
391
+ refreshInterval: 0,
392
+ ttl: 0,
393
+ serverTTL: 1e3,
394
+ dedupingInterval: 2e3,
395
+ revalidateOnFocus: !0,
396
+ revalidateDebounce: 0,
397
+ shouldRetryOnError: !0,
398
+ errorRetryInterval: 5e3,
399
+ errorRetryCount: 5,
400
+ fetcher: ae.fetcher,
401
+ isOnline: ae.isOnline,
402
+ isDocumentVisible: ae.isDocumentVisible
403
+ };
404
+ function Or(e, r, t) {
405
+ var o = Y.get(e);
406
+ if (o)
407
+ o.data.push(r);
408
+ else {
409
+ var a = 5e3;
410
+ Y.set(e, [r], t > 0 ? t + a : t);
411
+ }
412
+ }
413
+ function Lr(e, r, t) {
414
+ if (t.isDocumentVisible() && !(t.errorRetryCount !== void 0 && r > t.errorRetryCount)) {
415
+ var o = Math.min(r || 0, t.errorRetryCount), a = o * t.errorRetryInterval;
416
+ setTimeout(function() {
417
+ e(null, { errorRetryCount: o + 1, shouldRetryOnError: !0 });
418
+ }, a);
419
+ }
420
+ }
421
+ var Te = function(e, r, t, o) {
422
+ return t === void 0 && (t = Ve), o === void 0 && (o = ke.ttl), U(void 0, void 0, void 0, function() {
423
+ var a, n, l, c, f, i, s;
424
+ return z(this, function(u) {
425
+ switch (u.label) {
426
+ case 0:
427
+ if (!kr(r)) return [3, 5];
428
+ u.label = 1;
429
+ case 1:
430
+ return u.trys.push([1, 3, , 4]), [4, r];
431
+ case 2:
432
+ return a = u.sent(), [3, 4];
433
+ case 3:
434
+ return c = u.sent(), n = c, [3, 4];
435
+ case 4:
436
+ return [3, 6];
437
+ case 5:
438
+ a = r, u.label = 6;
439
+ case 6:
440
+ if (l = !1, f = { data: a, error: n, isValidating: l }, typeof a < "u")
441
+ try {
442
+ t.set(e, f, o);
443
+ } catch (d) {
444
+ console.error("swrv(mutate): failed to set cache", d);
445
+ }
446
+ return i = Y.get(e), i && i.data.length && (s = i.data.filter(function(d) {
447
+ return d.key === e;
448
+ }), s.forEach(function(d, v) {
449
+ typeof f.data < "u" && (d.data = f.data), d.error = f.error, d.isValidating = f.isValidating, d.isLoading = f.isValidating;
450
+ var g = v === s.length - 1;
451
+ g || delete s[v];
452
+ }), s = s.filter(Boolean)), [2, f];
453
+ }
454
+ });
455
+ });
456
+ };
457
+ function Vr() {
458
+ for (var e = this, r = [], t = 0; t < arguments.length; t++)
459
+ r[t] = arguments[t];
460
+ var o, a, n = b({}, ke), l = !1, c = !1, f = xe(), i = (f == null ? void 0 : f.proxy) || f;
461
+ if (!i)
462
+ return console.error("Could not get current instance, check to make sure that `useSwrv` is declared in the top level of the setup function."), null;
463
+ var s = (i == null ? void 0 : i.$isServer) || !1;
464
+ r.length >= 1 && (o = r[0]), r.length >= 2 && (a = r[1]), r.length > 2 && (n = b(b({}, n), r[2]));
465
+ var u = s ? n.serverTTL : n.ttl, d = typeof o == "function" ? o : H(o);
466
+ typeof a > "u" && (a = n.fetcher);
467
+ var v = null;
468
+ v || (v = qe({
469
+ data: void 0,
470
+ error: void 0,
471
+ isValidating: !0,
472
+ isLoading: !0,
473
+ key: null
474
+ }));
475
+ var g = function(p, y) {
476
+ return U(e, void 0, void 0, function() {
477
+ var I, S, A, M, W, de, J, fe = this;
478
+ return z(this, function(Z) {
479
+ switch (Z.label) {
480
+ case 0:
481
+ return I = v.data === void 0, S = d.value, S ? (A = n.cache.get(S), M = A && A.data, v.isValidating = !0, v.isLoading = !M, M && (v.data = M.data, v.error = M.error), W = p || a, !W || !n.isDocumentVisible() && !I || (y == null ? void 0 : y.forceRevalidate) !== void 0 && !(y != null && y.forceRevalidate) ? (v.isValidating = !1, v.isLoading = !1, [
482
+ 2
483
+ /*return*/
484
+ ]) : A && (de = !!(Date.now() - A.createdAt >= n.dedupingInterval || y != null && y.forceRevalidate), !de) ? (v.isValidating = !1, v.isLoading = !1, [
485
+ 2
486
+ /*return*/
487
+ ]) : (J = function() {
488
+ return U(fe, void 0, void 0, function() {
489
+ var k, ve, ee, me;
490
+ return z(this, function(B) {
491
+ switch (B.label) {
492
+ case 0:
493
+ return k = ie.get(S), k ? [3, 2] : (ve = Array.isArray(S) ? S : [S], ee = W.apply(void 0, wr([], br(ve), !1)), ie.set(S, ee, n.dedupingInterval), [4, Te(S, ee, n.cache, u)]);
494
+ case 1:
495
+ return B.sent(), [3, 4];
496
+ case 2:
497
+ return [4, Te(S, k.data, n.cache, u)];
498
+ case 3:
499
+ B.sent(), B.label = 4;
500
+ case 4:
501
+ return v.isValidating = !1, v.isLoading = !1, ie.delete(S), v.error !== void 0 && (me = !l && n.shouldRetryOnError && (y ? y.shouldRetryOnError : !0), me && Lr(g, y ? y.errorRetryCount : 1, n)), [
502
+ 2
503
+ /*return*/
504
+ ];
505
+ }
506
+ });
507
+ });
508
+ }, M && n.revalidateDebounce ? (setTimeout(function() {
509
+ return U(fe, void 0, void 0, function() {
510
+ return z(this, function(k) {
511
+ switch (k.label) {
512
+ case 0:
513
+ return l ? [3, 2] : [4, J()];
514
+ case 1:
515
+ k.sent(), k.label = 2;
516
+ case 2:
517
+ return [
518
+ 2
519
+ /*return*/
520
+ ];
521
+ }
522
+ });
523
+ });
524
+ }, n.revalidateDebounce), [3, 3]) : [3, 1])) : [
525
+ 2
526
+ /*return*/
527
+ ];
528
+ case 1:
529
+ return [4, J()];
530
+ case 2:
531
+ Z.sent(), Z.label = 3;
532
+ case 3:
533
+ return [
534
+ 2
535
+ /*return*/
536
+ ];
537
+ }
538
+ });
539
+ });
540
+ }, R = function() {
541
+ return U(e, void 0, void 0, function() {
542
+ return z(this, function(p) {
543
+ return [2, g(null, { shouldRetryOnError: !1 })];
544
+ });
545
+ });
546
+ }, m = null;
547
+ Ue(function() {
548
+ var p = function() {
549
+ return U(e, void 0, void 0, function() {
550
+ return z(this, function(y) {
551
+ switch (y.label) {
552
+ case 0:
553
+ return !v.error && n.isOnline() ? [4, g()] : [3, 2];
554
+ case 1:
555
+ return y.sent(), [3, 3];
556
+ case 2:
557
+ m && clearTimeout(m), y.label = 3;
558
+ case 3:
559
+ return n.refreshInterval && !l && (m = setTimeout(p, n.refreshInterval)), [
560
+ 2
561
+ /*return*/
562
+ ];
563
+ }
564
+ });
565
+ });
566
+ };
567
+ n.refreshInterval && (m = setTimeout(p, n.refreshInterval)), n.revalidateOnFocus && (document.addEventListener("visibilitychange", R, !1), window.addEventListener("focus", R, !1));
568
+ }), ze(function() {
569
+ l = !0, m && clearTimeout(m), n.revalidateOnFocus && (document.removeEventListener("visibilitychange", R, !1), window.removeEventListener("focus", R, !1));
570
+ var p = Y.get(d.value);
571
+ p && (p.data = p.data.filter(function(y) {
572
+ return y !== v;
573
+ }));
574
+ });
575
+ try {
576
+ Ke(d, function(p) {
577
+ Pe(d) || (d.value = p), v.key = p, v.isValidating = !!p, Or(d.value, v, u), !s && !c && d.value && g(), c = !1;
578
+ }, {
579
+ immediate: !0
580
+ });
581
+ } catch {
582
+ }
583
+ var C = b(b({}, $e(v)), { mutate: function(p, y) {
584
+ return g(p, b(b({}, y), { forceRevalidate: !0 }));
585
+ } });
586
+ return C;
587
+ }
588
+ function kr(e) {
589
+ return e !== null && typeof e == "object" && typeof e.then == "function";
590
+ }
591
+ function Nr(e, r, t) {
592
+ const {
593
+ data: o,
594
+ error: a,
595
+ isValidating: n,
596
+ mutate: l
597
+ } = Vr(e, r, {
598
+ revalidateDebounce: 500,
599
+ revalidateOnFocus: !1,
600
+ dedupingInterval: 100,
601
+ ...t
602
+ });
603
+ return {
604
+ data: h(() => o.value),
605
+ response: o,
606
+ error: a,
607
+ isValidating: n,
608
+ revalidate: l
609
+ };
610
+ }
611
+ const N = {
612
+ useI18n: mr,
613
+ useMetricCardBuilder: Cr,
614
+ useMetricFetcher: Er,
615
+ useRequest: Nr
616
+ }, Ne = Symbol("METRICS_PROVIDER_KEY"), Fr = (e) => {
617
+ const {
618
+ datasource: r,
619
+ dimension: t,
620
+ dimensionFilterValue: o,
621
+ additionalFilter: a,
622
+ queryReady: n,
623
+ timeframe: l,
624
+ tz: c,
625
+ hasTrendAccess: f,
626
+ refreshInterval: i,
627
+ abortController: s,
628
+ queryFn: u,
629
+ averageLatencies: d
630
+ } = e;
631
+ if (o && !t)
632
+ throw new Error("Must provide a dimension if filtering by a value");
633
+ const v = !!(t && o), g = !!(t && !o), R = h(() => {
634
+ const I = [];
635
+ return v && I.push({
636
+ field: t,
637
+ operator: "in",
638
+ value: [o]
639
+ }), a.value && I.push(...Ye(r.value, a.value)), I;
640
+ }), m = {
641
+ datasource: r,
642
+ metrics: H([
643
+ "request_count"
644
+ ]),
645
+ // Traffic and error rate cards should only try to query for the dimension if it's going to be used.
646
+ // It isn't used for single entity queries.
647
+ dimensions: [
648
+ ...t && !v ? [t] : [],
649
+ "status_code_grouped"
650
+ ],
651
+ filter: R,
652
+ queryReady: n,
653
+ timeframe: l,
654
+ tz: c,
655
+ // Traffic and error rate cards can't query trend if multiple entities are expected.
656
+ withTrend: h(() => f.value && !g),
657
+ refreshInterval: i,
658
+ queryFn: u,
659
+ abortController: s,
660
+ refreshCounter: e.refreshCounter
661
+ }, C = {
662
+ datasource: r,
663
+ metrics: h(() => [
664
+ d.value ? "response_latency_average" : "response_latency_p99"
665
+ ]),
666
+ // To keep single-entity queries consistent, don't bother querying the dimension for latency
667
+ // in the single-entity case, even though it's possible.
668
+ ...t && !v ? { dimensions: [t] } : {},
669
+ filter: R,
670
+ queryReady: n,
671
+ timeframe: l,
672
+ tz: c,
673
+ // Don't query latency trends in the multi-entity case: it's possible, but wasteful.
674
+ withTrend: h(() => f.value && !g),
675
+ refreshInterval: i,
676
+ queryFn: u,
677
+ abortController: s,
678
+ refreshCounter: e.refreshCounter
679
+ }, p = N.useMetricFetcher(m), y = N.useMetricFetcher(C);
680
+ return {
681
+ trafficData: p,
682
+ latencyData: y
683
+ };
684
+ }, Rt = /* @__PURE__ */ Q({
685
+ __name: "MetricsProvider",
686
+ props: {
687
+ datasource: { default: void 0 },
688
+ maxTimeframe: { default: se.THIRTY_DAY },
689
+ overrideTimeframe: { default: void 0 },
690
+ tz: { default: void 0 },
691
+ dimension: { default: void 0 },
692
+ filterValue: { default: void 0 },
693
+ additionalFilter: { default: void 0 },
694
+ queryReady: { type: Boolean, default: !0 },
695
+ refreshInterval: { default: hr },
696
+ longCardTitles: { type: Boolean, default: !1 },
697
+ containerTitle: { default: void 0 },
698
+ description: { default: void 0 },
699
+ percentileLatency: { type: Boolean, default: void 0 },
700
+ abortController: { default: void 0 },
701
+ refreshCounter: { default: 0 }
702
+ },
703
+ setup(e) {
704
+ const r = e;
705
+ if (r.dimension && Qe.findIndex((v) => v === r.dimension) === -1)
706
+ throw new Error(`Attempted to use MetricsProvider with an invalid dimension: ${r.dimension}`);
707
+ const t = _e(gr);
708
+ let o;
709
+ t ? o = t.queryFn : (console.warn("Analytics dashboards require a query bridge supplied via provide / inject."), console.warn("Please ensure your application has a query bridge provided under the key 'analytics-query-provider', as described in"), console.warn("https://github.com/Kong/public-ui-components/blob/main/packages/analytics/analytics-metric-provider/README.md#requirements"), o = () => Promise.reject(new Error("Query bridge required")));
710
+ const a = rr(), n = h(() => !0), l = h(() => !a.loading && r.queryReady), c = h(() => r.tz ? r.tz : new Intl.DateTimeFormat().resolvedOptions().timeZone), f = h(() => r.datasource ? r.datasource : "basic"), i = h(() => r.overrideTimeframe || be.get(se.SEVEN_DAY)), s = h(() => !r.percentileLatency), {
711
+ trafficData: u,
712
+ latencyData: d
713
+ } = Fr({
714
+ datasource: f,
715
+ dimension: r.dimension,
716
+ dimensionFilterValue: r.filterValue,
717
+ additionalFilter: X(r, "additionalFilter"),
718
+ queryReady: l,
719
+ timeframe: i,
720
+ tz: c,
721
+ hasTrendAccess: n,
722
+ refreshInterval: r.refreshInterval,
723
+ queryFn: o,
724
+ averageLatencies: s,
725
+ abortController: r.abortController,
726
+ refreshCounter: X(r, "refreshCounter")
727
+ });
728
+ return Be(Ne, {
729
+ data: {
730
+ traffic: u,
731
+ latency: d
732
+ },
733
+ description: X(() => r.description),
734
+ containerTitle: X(() => r.containerTitle),
735
+ hasTrendAccess: n,
736
+ longCardTitles: r.longCardTitles,
737
+ averageLatencies: s
738
+ }), (v, g) => Ie(v.$slots, "default", {
739
+ hasTrendAccess: n.value,
740
+ timeframe: i.value
741
+ });
742
+ }
743
+ });
744
+ function Mr(e) {
745
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
746
+ }
747
+ var Fe = { exports: {} };
748
+ (function(e) {
749
+ (function() {
750
+ function r(i, s) {
751
+ if (s.separator === !1 || i < 1e3)
752
+ return i.toString();
753
+ var u = typeof s.separator == "string" ? s.separator : ",", d = [], v = Math.round(i).toString().split("");
754
+ return v.reverse().forEach(function(g, R) {
755
+ R && R % 3 === 0 && d.push(u), d.push(g);
756
+ }), d.reverse().join("");
757
+ }
758
+ function t(i, s, u) {
759
+ var d = i / s, v = u.round ? "round" : "floor";
760
+ return u.decimal === !1 ? (i = Math[v](d), i.toString()) : (u.precision ? i = d : i = d < 10 ? Math[v](d * 10) / 10 : Math[v](d), i = i.toString(), typeof u.decimal == "string" && (i = i.replace(".", u.decimal)), i);
761
+ }
762
+ var o = 1e3, a = 1e4, n = 1e6, l = 1e9, c = 1e12;
763
+ function f(i, s) {
764
+ var u;
765
+ s = s || {};
766
+ var d = i < 0;
767
+ d && (i = Math.abs(i)), s.precision && (i = parseFloat(i.toPrecision(s.precision)));
768
+ var v = s.min10k ? a : o;
769
+ return i < v || s.precision && s.precision > Math.log10(i) ? u = r(t(i, 1, s), s) : i < n ? u = t(i, o, s) + "k" : i < l ? u = t(i, n, s) + "m" : i < c ? u = r(t(i, l, s), s) + "b" : u = r(t(i, c, s), s) + "t", d && (u = "-" + u), s.capital && (u = u.toUpperCase()), s.prefix && (u = s.prefix + u), s.suffix && (u = u + s.suffix), u;
770
+ }
771
+ f.addCommas = r, e.exports = f;
772
+ })();
773
+ })(Fe);
774
+ var xr = Fe.exports;
775
+ const qr = /* @__PURE__ */ Mr(xr);
776
+ var O = /* @__PURE__ */ ((e) => (e.GENERIC_COUNT = "GenericCount", e.TRAFFIC = "Traffic", e.ERROR_RATE = "ErrorRate", e.LATENCY = "Latency", e))(O || {}), D = /* @__PURE__ */ ((e) => (e.Small = "sm", e.Medium = "md", e.Large = "lg", e.ExtraLarge = "xl", e))(D || {});
777
+ const le = 2, Ee = le + 2, Ur = (e, r, t = !1) => {
778
+ let o = !r || Number(e.toFixed(Ee)) === 0 ? 0 : Number(e.toFixed(Ee)) > 0 ? 1 : -1;
779
+ return t && (o *= -1), o;
780
+ }, zr = (e, r, t) => r ? `${Math.abs(e * 100).toFixed(le)}%` : t, Kr = (e, r) => r === 0 ? 0 : e / r - 1, Pr = (e, r = !1) => (r && (e *= -1), e > 0 ? tr : e < 0 ? nr : we), $r = "#ad000e", oe = "#6c7489", Ce = "#52596e", Br = "#007d60", G = "16px", Xr = "20px", Gr = {
781
+ key: 0,
782
+ class: "metricscard-description"
783
+ }, jr = { class: "metricscard-valuetrend" }, Hr = {
784
+ key: 0,
785
+ class: "metricscard-error"
786
+ }, Yr = {
787
+ key: 2,
788
+ class: "metricscard-trend"
789
+ }, Qr = { "data-testid": "metric-trend-change" }, Wr = {
790
+ key: 0,
791
+ class: "metricscard-trend-range"
792
+ }, Jr = /* @__PURE__ */ Q({
793
+ __name: "MetricsCard",
794
+ props: {
795
+ cardType: {
796
+ type: String,
797
+ required: !0,
798
+ default: O.GENERIC_COUNT
799
+ },
800
+ title: {
801
+ type: String,
802
+ default: "0%",
803
+ required: !0
804
+ },
805
+ description: {
806
+ type: String,
807
+ default: "",
808
+ required: !1
809
+ },
810
+ tooltip: {
811
+ type: String,
812
+ required: !1,
813
+ default: ""
814
+ },
815
+ timeframe: {
816
+ type: String,
817
+ required: !1,
818
+ default: ""
819
+ },
820
+ metricValue: {
821
+ type: String,
822
+ default: ""
823
+ },
824
+ metricChange: {
825
+ type: String,
826
+ required: !0
827
+ },
828
+ changePolarity: {
829
+ type: Number,
830
+ required: !0
831
+ },
832
+ trendIcon: {
833
+ type: Object,
834
+ default: we
835
+ },
836
+ trendRange: {
837
+ type: String,
838
+ default: ""
839
+ },
840
+ hasError: {
841
+ type: Boolean,
842
+ default: !1
843
+ },
844
+ errorMessage: {
845
+ type: String,
846
+ default: "Vitals data error"
847
+ },
848
+ cardSize: {
849
+ type: String,
850
+ required: !1,
851
+ default: () => D.Large
852
+ },
853
+ hasContainerTitle: {
854
+ type: Boolean,
855
+ required: !1,
856
+ default: !1
857
+ },
858
+ titleTag: {
859
+ type: String,
860
+ default: "span"
861
+ }
862
+ },
863
+ setup(e) {
864
+ const r = /* @__PURE__ */ new Map([
865
+ [O.GENERIC_COUNT, ar],
866
+ [O.TRAFFIC, ir],
867
+ [O.ERROR_RATE, or],
868
+ [O.LATENCY, sr]
869
+ ]), t = e, o = (c) => {
870
+ const f = {
871
+ red: `var(--kui-color-text-danger-strong, ${$r})`,
872
+ green: `var(--kui-color-text-success, ${Br})`,
873
+ grey: `var(--kui-color-text-neutral-strong, ${Ce})`
874
+ };
875
+ return c > 0 ? f.green : c < 0 ? f.red : f.grey;
876
+ }, a = (c) => c > 0 ? "positive" : c < 0 ? "negative" : "neutral", n = [D.Medium, D.Large].includes(t.cardSize), l = [D.Small].includes(t.cardSize);
877
+ return (c, f) => {
878
+ const i = Ae("KTooltip");
879
+ return T(), _("div", {
880
+ class: K(["metricscard", e.cardSize])
881
+ }, [
882
+ x("div", {
883
+ class: K(["metricscard-title", e.cardSize])
884
+ }, [
885
+ E(l) ? V("", !0) : (T(), q(re(E(r).get(e.cardType)), {
886
+ key: 0,
887
+ class: "metricscard-icon",
888
+ color: `var(--kui-color-text-neutral, ${E(oe)})`,
889
+ size: E(G)
890
+ }, null, 8, ["color", "size"])),
891
+ (T(), q(re(e.titleTag), null, {
892
+ default: ye(() => [
893
+ De(w(e.title), 1)
894
+ ]),
895
+ _: 1
896
+ })),
897
+ e.tooltip ? (T(), q(i, {
898
+ key: 1,
899
+ class: "metricscard-tooltip",
900
+ placement: "right",
901
+ text: e.tooltip
902
+ }, {
903
+ default: ye(() => [
904
+ F(E(ur), {
905
+ color: `var(--kui-color-text-neutral, ${E(oe)})`,
906
+ size: E(G)
907
+ }, null, 8, ["color", "size"])
908
+ ]),
909
+ _: 1
910
+ }, 8, ["text"])) : V("", !0)
911
+ ], 2),
912
+ e.description && E(n) ? (T(), _("div", Gr, [
913
+ x("span", null, w(e.description), 1)
914
+ ])) : V("", !0),
915
+ x("div", jr, [
916
+ e.hasError ? (T(), _("div", Hr, [
917
+ F(E(Oe), {
918
+ color: `var(--kui-color-text-neutral, ${E(oe)})`,
919
+ size: E(Xr)
920
+ }, null, 8, ["color", "size"]),
921
+ x("div", null, " " + w(e.errorMessage), 1)
922
+ ])) : (T(), _("div", {
923
+ key: 1,
924
+ class: K(["metricscard-value", e.cardSize]),
925
+ "data-testid": "metric-value"
926
+ }, w(e.metricValue), 3)),
927
+ E(n) ? (T(), _("div", Yr, [
928
+ x("div", {
929
+ class: K(["metricscard-trend-change", a(e.changePolarity)]),
930
+ "data-testid": "metric-trend-parent"
931
+ }, [
932
+ e.changePolarity !== 0 ? (T(), q(re(e.trendIcon), {
933
+ key: 0,
934
+ color: o(e.changePolarity),
935
+ size: E(G)
936
+ }, null, 8, ["color", "size"])) : (T(), q(E(lr), {
937
+ key: 1,
938
+ color: `var(--kui-color-text-neutral-strong, ${E(Ce)})`,
939
+ size: E(G)
940
+ }, null, 8, ["color", "size"])),
941
+ x("div", Qr, w(e.metricChange), 1)
942
+ ], 2),
943
+ e.trendRange ? (T(), _("div", Wr, w(e.trendRange), 1)) : V("", !0)
944
+ ])) : V("", !0)
945
+ ])
946
+ ], 2);
947
+ };
948
+ }
949
+ }), ce = (e, r) => {
950
+ const t = e.__vccOpts || e;
951
+ for (const [o, a] of r)
952
+ t[o] = a;
953
+ return t;
954
+ }, Zr = /* @__PURE__ */ ce(Jr, [["__scopeId", "data-v-b1513f6f"]]), et = {}, rt = { class: "loading-tabs" };
955
+ function tt(e, r) {
956
+ const t = Ae("KSkeletonBox");
957
+ return T(), _("div", rt, [
958
+ F(t, { width: "100" }),
959
+ F(t, { width: "75" })
960
+ ]);
961
+ }
962
+ const nt = /* @__PURE__ */ ce(et, [["render", tt], ["__scopeId", "data-v-9c7113d7"]]), at = {
963
+ key: 0,
964
+ class: "container-title"
965
+ }, it = {
966
+ key: 0,
967
+ class: "container-description"
968
+ }, ot = {
969
+ key: 1,
970
+ class: "error-display"
971
+ }, st = {
972
+ key: 0,
973
+ class: "error-display-message"
974
+ }, ut = {
975
+ key: 2,
976
+ class: "cards-wrapper"
977
+ }, lt = /* @__PURE__ */ Q({
978
+ __name: "MetricCardContainer",
979
+ props: {
980
+ fallbackDisplayText: {
981
+ type: String,
982
+ required: !0
983
+ },
984
+ cards: {
985
+ type: Array,
986
+ required: !0
987
+ },
988
+ errorMessage: {
989
+ type: String,
990
+ required: !1,
991
+ default: ""
992
+ },
993
+ loading: {
994
+ type: Boolean,
995
+ required: !1,
996
+ default: !1
997
+ },
998
+ hasTrendAccess: {
999
+ type: Boolean,
1000
+ required: !1,
1001
+ default: !0
1002
+ },
1003
+ cardSize: {
1004
+ type: String,
1005
+ required: !1,
1006
+ default: () => D.Large
1007
+ },
1008
+ containerTitle: {
1009
+ type: String,
1010
+ required: !1,
1011
+ default: ""
1012
+ },
1013
+ containerDescription: {
1014
+ type: String,
1015
+ required: !1,
1016
+ default: ""
1017
+ }
1018
+ },
1019
+ setup(e) {
1020
+ const r = e, t = h(() => r.cards.every((a) => (a == null ? void 0 : a.hasError) === !0)), o = (a) => {
1021
+ const n = Kr(a.currentValue, a.previousValue) || 0, l = Ur(n, r.hasTrendAccess, a.increaseIsBad);
1022
+ return {
1023
+ metricValue: a.formatValueFn ? a.formatValueFn(a.currentValue) : qr(a.currentValue, { capital: !0, round: !0 }) || "0",
1024
+ metricChange: a.formatChangeFn ? a.formatChangeFn(n) : zr(n, r.hasTrendAccess, r.fallbackDisplayText),
1025
+ changePolarity: l,
1026
+ trendIcon: Pr(l, a.increaseIsBad),
1027
+ cardSize: r.cardSize,
1028
+ hasContainerTitle: !!r.containerTitle
1029
+ };
1030
+ };
1031
+ return (a, n) => (T(), _("div", {
1032
+ class: K(["kong-ui-public-metric-card-container", e.cardSize])
1033
+ }, [
1034
+ r.containerTitle || r.containerDescription ? (T(), _("div", at, [
1035
+ De(w(r.containerTitle) + " ", 1),
1036
+ r.containerDescription ? (T(), _("div", it, w(r.containerDescription), 1)) : V("", !0)
1037
+ ])) : V("", !0),
1038
+ t.value ? (T(), _("div", ot, [
1039
+ F(E(Oe), { class: "error-display-icon" }),
1040
+ e.errorMessage ? (T(), _("div", st, w(e.errorMessage), 1)) : V("", !0)
1041
+ ])) : (T(), _("div", ut, [
1042
+ (T(!0), _(he, null, Xe(e.cards, (l, c) => (T(), _(he, null, [
1043
+ e.loading ? (T(), _("div", {
1044
+ key: `skeleton-${c}`,
1045
+ class: "loading-tab"
1046
+ }, [
1047
+ F(nt, {
1048
+ class: K(e.cardSize === E(D).Small ? "loading-tabs-small" : "loading-tabs-large")
1049
+ }, null, 8, ["class"])
1050
+ ])) : (T(), q(Zr, Ge({
1051
+ key: c,
1052
+ ref_for: !0
1053
+ }, o(l), {
1054
+ "card-size": e.cardSize,
1055
+ "card-type": l.cardType,
1056
+ description: l.description,
1057
+ "error-message": e.errorMessage,
1058
+ "has-error": l.hasError,
1059
+ title: l.title,
1060
+ "title-tag": l.titleTag,
1061
+ tooltip: l.tooltip,
1062
+ "trend-range": l.trendRange
1063
+ }), null, 16, ["card-size", "card-type", "description", "error-message", "has-error", "title", "title-tag", "tooltip", "trend-range"]))
1064
+ ], 64))), 256))
1065
+ ]))
1066
+ ], 2));
1067
+ }
1068
+ }), ct = /* @__PURE__ */ ce(lt, [["__scopeId", "data-v-7080ba56"]]), Tt = /* @__PURE__ */ Q({
1069
+ __name: "MetricsConsumer",
1070
+ props: {
1071
+ lookupKey: { default: void 0 },
1072
+ cardSize: { default: D.Large },
1073
+ cardToDisplay: { default: void 0 }
1074
+ },
1075
+ setup(e) {
1076
+ const r = e, t = _e(Ne);
1077
+ if (!t)
1078
+ throw new Error("MetricsConsumer must be nested inside a MetricsProvider instance.");
1079
+ const { traffic: o, latency: a } = t.data, { i18n: n } = N.useI18n(), l = h(() => t.containerTitle.value ? D.Medium : r.cardSize), c = N.useMetricCardBuilder({
1080
+ cardType: O.TRAFFIC,
1081
+ title: h(() => t.longCardTitles ? n.t("metricCard.long.traffic") : n.t("metricCard.short.traffic")),
1082
+ record: o.mapped,
1083
+ hasError: o.hasError,
1084
+ lookupKey: r.lookupKey,
1085
+ sumGroupedValues: $,
1086
+ trendRange: o.trendRange
1087
+ }), f = (m) => `${m.toFixed(le)}%`, i = h(() => {
1088
+ const m = o.mapped.value, C = P(m, "current", r.lookupKey, ge), p = P(m, "current", r.lookupKey, $), y = C / p * 100 || 0, I = P(m, "previous", r.lookupKey, ge), S = P(m, "previous", r.lookupKey, $), A = I / S * 100 || 0;
1089
+ return {
1090
+ cardType: O.ERROR_RATE,
1091
+ hasError: o.hasError.value,
1092
+ currentValue: y,
1093
+ previousValue: A,
1094
+ formatValueFn: f,
1095
+ title: t.longCardTitles ? n.t("metricCard.long.errorRate") : n.t("metricCard.short.errorRate"),
1096
+ increaseIsBad: !0,
1097
+ trendRange: o.trendRange.value
1098
+ };
1099
+ }), s = (m) => `${m}ms`, u = N.useMetricCardBuilder({
1100
+ cardType: O.LATENCY,
1101
+ title: h(() => {
1102
+ const { longCardTitles: m, averageLatencies: C } = t, p = C.value ? "averageLatency" : "p99Latency";
1103
+ return m ? n.t(`metricCard.long.${p}`) : l.value === D.Small ? n.t(`metricCard.small.${p}`) : n.t(`metricCard.short.${p}`);
1104
+ }),
1105
+ hasError: a.hasError,
1106
+ record: a.mapped,
1107
+ lookupKey: r.lookupKey,
1108
+ increaseIsBad: !0,
1109
+ formatValueFn: s,
1110
+ trendRange: a.trendRange
1111
+ }), d = h(() => r.cardToDisplay === "TRAFFIC" ? [c.value] : r.cardToDisplay === "ERROR_RATE" ? [i.value] : r.cardToDisplay === "LATENCY" ? [u.value] : [c.value, i.value, u.value]), v = h(() => r.cardToDisplay === "TRAFFIC" || r.cardToDisplay === "ERROR_RATE" ? o.isLoading.value : r.cardToDisplay === "LATENCY" ? a.isLoading.value : o.isLoading.value || a.isLoading.value), g = h(() => ({
1112
+ cards: d.value,
1113
+ containerTitle: t.containerTitle.value,
1114
+ containerDescription: t.description.value,
1115
+ loading: v.value,
1116
+ hasTrendAccess: t.hasTrendAccess.value,
1117
+ fallbackDisplayText: n.t("general.notAvailable"),
1118
+ cardSize: l.value,
1119
+ hideTitle: !0
1120
+ })), R = h(() => ({
1121
+ loading: g.value.loading,
1122
+ trafficCard: c.value,
1123
+ errorRateCard: i.value,
1124
+ latencyCard: u.value,
1125
+ errorRateFormatted: f(i.value.currentValue),
1126
+ latencyFormatted: s(u.value.currentValue)
1127
+ }));
1128
+ return (m, C) => Ie(m.$slots, "default", { cardValues: R.value }, () => [
1129
+ F(ct, je(He(g.value)), null, 16)
1130
+ ]);
1131
+ }
1132
+ }), j = (e) => new Date(e), Et = (e, r) => {
1133
+ const t = e.body;
1134
+ e.reply({
1135
+ statusCode: 200,
1136
+ body: dt(t, r)
1137
+ });
1138
+ }, Se = (e) => e.reduce((r, t) => (r[t] = { name: t }, r), {}), dt = (e, r) => {
1139
+ var g, R;
1140
+ const t = be.get(se.ONE_DAY), o = e.granularity === "trend" ? new We(t) : new Je(t), a = o.endMs(), n = o.startMs(), l = o.granularityMs(), c = e.granularity === "trend" ? 2 : 1;
1141
+ if ((e.dimensions ?? []).length > 2)
1142
+ throw new Error(`Explore only supports 0-2 dimensions; got: ${JSON.stringify(e.dimensions)}`);
1143
+ const f = (e.dimensions ?? []).find((m) => m !== "time"), i = (r == null ? void 0 : r.dimensionNames) ?? [], s = Math.max(i.length, 1), u = e.metrics || [], d = [];
1144
+ for (let m = 0; m < c; m++)
1145
+ for (let C = 0; C < s; C++) {
1146
+ const p = f ? { [f]: i[C] } : {};
1147
+ (g = e.dimensions) != null && g.includes("status_code_grouped") ? $.forEach((y) => {
1148
+ const I = u.reduce((S, A) => ((r == null ? void 0 : r.deterministic) ?? !0 ? S[A] = (c - m) * 1e3 + 100 * C + 1 : S[A] = Math.round(Math.random() * 1e3), S), { ...p, status_code_grouped: y });
1149
+ d.push({
1150
+ version: "v1",
1151
+ timestamp: m === 0 ? j(n).toISOString() : j(n + l).toISOString(),
1152
+ event: I
1153
+ });
1154
+ }) : d.push({
1155
+ version: "v1",
1156
+ timestamp: m === 0 ? j(n).toISOString() : j(n + l).toISOString(),
1157
+ event: u.reduce((y, I) => ((r == null ? void 0 : r.deterministic) ?? !0 ? y[I] = (c - m) * 1e3 + 100 * C + 1 : y[I] = Math.round(Math.random() * 1e3), y), { ...p })
1158
+ });
1159
+ }
1160
+ const v = {
1161
+ start_ms: n,
1162
+ end_ms: a,
1163
+ start: new Date(n).toISOString(),
1164
+ end: new Date(a).toISOString(),
1165
+ granularity_ms: l,
1166
+ display: f ? {
1167
+ [f]: Se(i),
1168
+ ...(R = e.dimensions) != null && R.includes("status_code_grouped") ? { status_code_grouped: Se($) } : {}
1169
+ } : {},
1170
+ metric_names: e.metrics,
1171
+ query_id: "test"
1172
+ };
1173
+ return {
1174
+ data: d,
1175
+ meta: v
1176
+ };
1177
+ };
1178
+ export {
1179
+ $ as ALL_STATUS_CODE_GROUPS,
1180
+ hr as DEFAULT_REFRESH_INTERVAL,
1181
+ gr as INJECT_QUERY_PROVIDER,
1182
+ yr as MAX_ANALYTICS_REQUEST_RETRIES,
1183
+ D as MetricCardSize,
1184
+ O as MetricCardType,
1185
+ Tt as MetricsConsumer,
1186
+ Rt as MetricsProvider,
1187
+ ge as STATUS_CODES_FAILED,
1188
+ pt as STATUS_CODES_SUCCESS,
1189
+ dt as mockExploreResponse,
1190
+ Et as mockExploreResponseFromCypress
1191
+ };