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