@kong-ui-public/analytics-metric-provider 8.9.12 → 8.9.13-pr.2132.867abf815.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 +7 -7
  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 -1186
  50. package/dist/vitals-metric-provider.umd.js +0 -1
@@ -1,1186 +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 "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 } = F.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 } = F.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 z = (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 = z(a.value, "current", e.lookupKey, e.sumGroupedValues), s = z(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
- }, x = 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
- }, q = 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), x(void 0, void 0, void 0, function() {
423
- var a, n, l, c, f, i, s;
424
- return q(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;
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
- key: null
473
- }));
474
- var g = function(p, y) {
475
- return x(e, void 0, void 0, function() {
476
- var I, S, A, P, W, de, J, fe = this;
477
- return q(this, function(Z) {
478
- switch (Z.label) {
479
- case 0:
480
- 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, [
481
- 2
482
- /*return*/
483
- ]) : A && (de = !!(Date.now() - A.createdAt >= n.dedupingInterval || y != null && y.forceRevalidate), !de) ? (v.isValidating = !1, [
484
- 2
485
- /*return*/
486
- ]) : (J = function() {
487
- return x(fe, void 0, void 0, function() {
488
- var k, ve, ee, me;
489
- return q(this, function(B) {
490
- switch (B.label) {
491
- case 0:
492
- 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)]);
493
- case 1:
494
- return B.sent(), [3, 4];
495
- case 2:
496
- return [4, Te(S, k.data, n.cache, u)];
497
- case 3:
498
- B.sent(), B.label = 4;
499
- case 4:
500
- 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)), [
501
- 2
502
- /*return*/
503
- ];
504
- }
505
- });
506
- });
507
- }, P && n.revalidateDebounce ? (setTimeout(function() {
508
- return x(fe, void 0, void 0, function() {
509
- return q(this, function(k) {
510
- switch (k.label) {
511
- case 0:
512
- return l ? [3, 2] : [4, J()];
513
- case 1:
514
- k.sent(), k.label = 2;
515
- case 2:
516
- return [
517
- 2
518
- /*return*/
519
- ];
520
- }
521
- });
522
- });
523
- }, n.revalidateDebounce), [3, 3]) : [3, 1])) : [
524
- 2
525
- /*return*/
526
- ];
527
- case 1:
528
- return [4, J()];
529
- case 2:
530
- Z.sent(), Z.label = 3;
531
- case 3:
532
- return [
533
- 2
534
- /*return*/
535
- ];
536
- }
537
- });
538
- });
539
- }, R = function() {
540
- return x(e, void 0, void 0, function() {
541
- return q(this, function(p) {
542
- return [2, g(null, { shouldRetryOnError: !1 })];
543
- });
544
- });
545
- }, m = null;
546
- Ue(function() {
547
- var p = function() {
548
- return x(e, void 0, void 0, function() {
549
- return q(this, function(y) {
550
- switch (y.label) {
551
- case 0:
552
- return !v.error && n.isOnline() ? [4, g()] : [3, 2];
553
- case 1:
554
- return y.sent(), [3, 3];
555
- case 2:
556
- m && clearTimeout(m), y.label = 3;
557
- case 3:
558
- return n.refreshInterval && !l && (m = setTimeout(p, n.refreshInterval)), [
559
- 2
560
- /*return*/
561
- ];
562
- }
563
- });
564
- });
565
- };
566
- n.refreshInterval && (m = setTimeout(p, n.refreshInterval)), n.revalidateOnFocus && (document.addEventListener("visibilitychange", R, !1), window.addEventListener("focus", R, !1));
567
- }), ze(function() {
568
- l = !0, m && clearTimeout(m), n.revalidateOnFocus && (document.removeEventListener("visibilitychange", R, !1), window.removeEventListener("focus", R, !1));
569
- var p = Y.get(d.value);
570
- p && (p.data = p.data.filter(function(y) {
571
- return y !== v;
572
- }));
573
- });
574
- try {
575
- Ke(d, function(p) {
576
- Pe(d) || (d.value = p), v.key = p, v.isValidating = !!p, Or(d.value, v, u), !s && !c && d.value && g(), c = !1;
577
- }, {
578
- immediate: !0
579
- });
580
- } catch {
581
- }
582
- var C = b(b({}, $e(v)), { mutate: function(p, y) {
583
- return g(p, b(b({}, y), { forceRevalidate: !0 }));
584
- } });
585
- return C;
586
- }
587
- function kr(e) {
588
- return e !== null && typeof e == "object" && typeof e.then == "function";
589
- }
590
- function Nr(e, r, t) {
591
- const {
592
- data: o,
593
- error: a,
594
- isValidating: n,
595
- mutate: l
596
- } = Vr(e, r, {
597
- revalidateDebounce: 500,
598
- revalidateOnFocus: !1,
599
- dedupingInterval: 100,
600
- ...t
601
- });
602
- return {
603
- data: h(() => o.value),
604
- response: o,
605
- error: a,
606
- isValidating: n,
607
- revalidate: l
608
- };
609
- }
610
- const F = {
611
- useI18n: mr,
612
- useMetricCardBuilder: Cr,
613
- useMetricFetcher: Er,
614
- useRequest: Nr
615
- }, Ne = Symbol("METRICS_PROVIDER_KEY"), Fr = (e) => {
616
- const {
617
- datasource: r,
618
- dimension: t,
619
- dimensionFilterValue: o,
620
- additionalFilter: a,
621
- queryReady: n,
622
- timeframe: l,
623
- tz: c,
624
- hasTrendAccess: f,
625
- refreshInterval: i,
626
- abortController: s,
627
- queryFn: u,
628
- averageLatencies: d
629
- } = e;
630
- if (o && !t)
631
- throw new Error("Must provide a dimension if filtering by a value");
632
- const v = !!(t && o), g = !!(t && !o), R = h(() => {
633
- const I = [];
634
- return v && I.push({
635
- field: t,
636
- operator: "in",
637
- value: [o]
638
- }), a.value && I.push(...Ye(r.value, a.value)), I;
639
- }), m = {
640
- datasource: r,
641
- metrics: H([
642
- "request_count"
643
- ]),
644
- // Traffic and error rate cards should only try to query for the dimension if it's going to be used.
645
- // It isn't used for single entity queries.
646
- dimensions: [
647
- ...t && !v ? [t] : [],
648
- "status_code_grouped"
649
- ],
650
- filter: R,
651
- queryReady: n,
652
- timeframe: l,
653
- tz: c,
654
- // Traffic and error rate cards can't query trend if multiple entities are expected.
655
- withTrend: h(() => f.value && !g),
656
- refreshInterval: i,
657
- queryFn: u,
658
- abortController: s,
659
- refreshCounter: e.refreshCounter
660
- }, C = {
661
- datasource: r,
662
- metrics: h(() => [
663
- d.value ? "response_latency_average" : "response_latency_p99"
664
- ]),
665
- // To keep single-entity queries consistent, don't bother querying the dimension for latency
666
- // in the single-entity case, even though it's possible.
667
- ...t && !v ? { dimensions: [t] } : {},
668
- filter: R,
669
- queryReady: n,
670
- timeframe: l,
671
- tz: c,
672
- // Don't query latency trends in the multi-entity case: it's possible, but wasteful.
673
- withTrend: h(() => f.value && !g),
674
- refreshInterval: i,
675
- queryFn: u,
676
- abortController: s,
677
- refreshCounter: e.refreshCounter
678
- }, p = F.useMetricFetcher(m), y = F.useMetricFetcher(C);
679
- return {
680
- trafficData: p,
681
- latencyData: y
682
- };
683
- }, Rt = /* @__PURE__ */ Q({
684
- __name: "MetricsProvider",
685
- props: {
686
- datasource: { default: void 0 },
687
- maxTimeframe: { default: se.THIRTY_DAY },
688
- overrideTimeframe: { default: void 0 },
689
- tz: { default: void 0 },
690
- dimension: { default: void 0 },
691
- filterValue: { default: void 0 },
692
- additionalFilter: { default: void 0 },
693
- queryReady: { type: Boolean, default: !0 },
694
- refreshInterval: { default: hr },
695
- longCardTitles: { type: Boolean, default: !1 },
696
- containerTitle: { default: void 0 },
697
- description: { default: void 0 },
698
- percentileLatency: { type: Boolean, default: void 0 },
699
- abortController: { default: void 0 },
700
- refreshCounter: { default: 0 }
701
- },
702
- setup(e) {
703
- const r = e;
704
- if (r.dimension && Qe.findIndex((v) => v === r.dimension) === -1)
705
- throw new Error(`Attempted to use MetricsProvider with an invalid dimension: ${r.dimension}`);
706
- const t = _e(gr);
707
- let o;
708
- 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")));
709
- 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), {
710
- trafficData: u,
711
- latencyData: d
712
- } = Fr({
713
- datasource: f,
714
- dimension: r.dimension,
715
- dimensionFilterValue: r.filterValue,
716
- additionalFilter: X(r, "additionalFilter"),
717
- queryReady: l,
718
- timeframe: i,
719
- tz: c,
720
- hasTrendAccess: n,
721
- refreshInterval: r.refreshInterval,
722
- queryFn: o,
723
- averageLatencies: s,
724
- abortController: r.abortController,
725
- refreshCounter: X(r, "refreshCounter")
726
- });
727
- return Be(Ne, {
728
- data: {
729
- traffic: u,
730
- latency: d
731
- },
732
- description: X(() => r.description),
733
- containerTitle: X(() => r.containerTitle),
734
- hasTrendAccess: n,
735
- longCardTitles: r.longCardTitles,
736
- averageLatencies: s
737
- }), (v, g) => Ie(v.$slots, "default", {
738
- hasTrendAccess: n.value,
739
- timeframe: i.value
740
- });
741
- }
742
- });
743
- function Mr(e) {
744
- return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
745
- }
746
- var Fe = { exports: {} };
747
- (function(e) {
748
- (function() {
749
- function r(i, s) {
750
- if (s.separator === !1 || i < 1e3)
751
- return i.toString();
752
- var u = typeof s.separator == "string" ? s.separator : ",", d = [], v = Math.round(i).toString().split("");
753
- return v.reverse().forEach(function(g, R) {
754
- R && R % 3 === 0 && d.push(u), d.push(g);
755
- }), d.reverse().join("");
756
- }
757
- function t(i, s, u) {
758
- var d = i / s, v = u.round ? "round" : "floor";
759
- 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);
760
- }
761
- var o = 1e3, a = 1e4, n = 1e6, l = 1e9, c = 1e12;
762
- function f(i, s) {
763
- var u;
764
- s = s || {};
765
- var d = i < 0;
766
- d && (i = Math.abs(i)), s.precision && (i = parseFloat(i.toPrecision(s.precision)));
767
- var v = s.min10k ? a : o;
768
- 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;
769
- }
770
- f.addCommas = r, e.exports = f;
771
- })();
772
- })(Fe);
773
- var xr = Fe.exports;
774
- const qr = /* @__PURE__ */ Mr(xr);
775
- 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 || {});
776
- const le = 2, Ee = le + 2, Ur = (e, r, t = !1) => {
777
- let o = !r || Number(e.toFixed(Ee)) === 0 ? 0 : Number(e.toFixed(Ee)) > 0 ? 1 : -1;
778
- return t && (o *= -1), o;
779
- }, 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 = {
780
- key: 0,
781
- class: "metricscard-description"
782
- }, jr = { class: "metricscard-valuetrend" }, Hr = {
783
- key: 0,
784
- class: "metricscard-error"
785
- }, Yr = {
786
- key: 2,
787
- class: "metricscard-trend"
788
- }, Qr = { "data-testid": "metric-trend-change" }, Wr = {
789
- key: 0,
790
- class: "metricscard-trend-range"
791
- }, Jr = /* @__PURE__ */ Q({
792
- __name: "MetricsCard",
793
- props: {
794
- cardType: {
795
- type: String,
796
- required: !0,
797
- default: O.GENERIC_COUNT
798
- },
799
- title: {
800
- type: String,
801
- default: "0%",
802
- required: !0
803
- },
804
- description: {
805
- type: String,
806
- default: "",
807
- required: !1
808
- },
809
- tooltip: {
810
- type: String,
811
- required: !1,
812
- default: ""
813
- },
814
- timeframe: {
815
- type: String,
816
- required: !1,
817
- default: ""
818
- },
819
- metricValue: {
820
- type: String,
821
- default: ""
822
- },
823
- metricChange: {
824
- type: String,
825
- required: !0
826
- },
827
- changePolarity: {
828
- type: Number,
829
- required: !0
830
- },
831
- trendIcon: {
832
- type: Object,
833
- default: we
834
- },
835
- trendRange: {
836
- type: String,
837
- default: ""
838
- },
839
- hasError: {
840
- type: Boolean,
841
- default: !1
842
- },
843
- errorMessage: {
844
- type: String,
845
- default: "Vitals data error"
846
- },
847
- cardSize: {
848
- type: String,
849
- required: !1,
850
- default: () => D.Large
851
- },
852
- hasContainerTitle: {
853
- type: Boolean,
854
- required: !1,
855
- default: !1
856
- },
857
- titleTag: {
858
- type: String,
859
- default: "span"
860
- }
861
- },
862
- setup(e) {
863
- const r = /* @__PURE__ */ new Map([
864
- [O.GENERIC_COUNT, ar],
865
- [O.TRAFFIC, ir],
866
- [O.ERROR_RATE, or],
867
- [O.LATENCY, sr]
868
- ]), t = e, o = (c) => {
869
- const f = {
870
- red: `var(--kui-color-text-danger-strong, ${$r})`,
871
- green: `var(--kui-color-text-success, ${Br})`,
872
- grey: `var(--kui-color-text-neutral-strong, ${Ce})`
873
- };
874
- return c > 0 ? f.green : c < 0 ? f.red : f.grey;
875
- }, a = (c) => c > 0 ? "positive" : c < 0 ? "negative" : "neutral", n = [D.Medium, D.Large].includes(t.cardSize), l = [D.Small].includes(t.cardSize);
876
- return (c, f) => {
877
- const i = Ae("KTooltip");
878
- return T(), _("div", {
879
- class: U(["metricscard", e.cardSize])
880
- }, [
881
- M("div", {
882
- class: U(["metricscard-title", e.cardSize])
883
- }, [
884
- E(l) ? V("", !0) : (T(), N(re(E(r).get(e.cardType)), {
885
- key: 0,
886
- class: "metricscard-icon",
887
- color: `var(--kui-color-text-neutral, ${E(oe)})`,
888
- size: E(G)
889
- }, null, 8, ["color", "size"])),
890
- (T(), N(re(e.titleTag), null, {
891
- default: ye(() => [
892
- De(w(e.title), 1)
893
- ]),
894
- _: 1
895
- })),
896
- e.tooltip ? (T(), N(i, {
897
- key: 1,
898
- class: "metricscard-tooltip",
899
- placement: "right",
900
- text: e.tooltip
901
- }, {
902
- default: ye(() => [
903
- K(E(ur), {
904
- color: `var(--kui-color-text-neutral, ${E(oe)})`,
905
- size: E(G)
906
- }, null, 8, ["color", "size"])
907
- ]),
908
- _: 1
909
- }, 8, ["text"])) : V("", !0)
910
- ], 2),
911
- e.description && E(n) ? (T(), _("div", Gr, [
912
- M("span", null, w(e.description), 1)
913
- ])) : V("", !0),
914
- M("div", jr, [
915
- e.hasError ? (T(), _("div", Hr, [
916
- K(E(Oe), {
917
- color: `var(--kui-color-text-neutral, ${E(oe)})`,
918
- size: E(Xr)
919
- }, null, 8, ["color", "size"]),
920
- M("div", null, " " + w(e.errorMessage), 1)
921
- ])) : (T(), _("div", {
922
- key: 1,
923
- class: U(["metricscard-value", e.cardSize]),
924
- "data-testid": "metric-value"
925
- }, w(e.metricValue), 3)),
926
- E(n) ? (T(), _("div", Yr, [
927
- M("div", {
928
- class: U(["metricscard-trend-change", a(e.changePolarity)]),
929
- "data-testid": "metric-trend-parent"
930
- }, [
931
- e.changePolarity !== 0 ? (T(), N(re(e.trendIcon), {
932
- key: 0,
933
- color: o(e.changePolarity),
934
- size: E(G)
935
- }, null, 8, ["color", "size"])) : (T(), N(E(lr), {
936
- key: 1,
937
- color: `var(--kui-color-text-neutral-strong, ${E(Ce)})`,
938
- size: E(G)
939
- }, null, 8, ["color", "size"])),
940
- M("div", Qr, w(e.metricChange), 1)
941
- ], 2),
942
- e.trendRange ? (T(), _("div", Wr, w(e.trendRange), 1)) : V("", !0)
943
- ])) : V("", !0)
944
- ])
945
- ], 2);
946
- };
947
- }
948
- }), ce = (e, r) => {
949
- const t = e.__vccOpts || e;
950
- for (const [o, a] of r)
951
- t[o] = a;
952
- return t;
953
- }, Zr = /* @__PURE__ */ ce(Jr, [["__scopeId", "data-v-b1513f6f"]]), et = {}, rt = { class: "loading-tabs" };
954
- function tt(e, r) {
955
- const t = Ae("KSkeletonBox");
956
- return T(), _("div", rt, [
957
- K(t, { width: "100" }),
958
- K(t, { width: "75" })
959
- ]);
960
- }
961
- const nt = /* @__PURE__ */ ce(et, [["render", tt], ["__scopeId", "data-v-50eab68c"]]), at = {
962
- key: 0,
963
- class: "container-title"
964
- }, it = {
965
- key: 0,
966
- class: "container-description"
967
- }, ot = {
968
- key: 1,
969
- class: "error-display"
970
- }, st = {
971
- key: 0,
972
- class: "error-display-message"
973
- }, ut = {
974
- key: 2,
975
- class: "cards-wrapper"
976
- }, lt = /* @__PURE__ */ Q({
977
- __name: "MetricCardContainer",
978
- props: {
979
- fallbackDisplayText: {
980
- type: String,
981
- required: !0
982
- },
983
- cards: {
984
- type: Array,
985
- required: !0
986
- },
987
- errorMessage: {
988
- type: String,
989
- required: !1,
990
- default: ""
991
- },
992
- loading: {
993
- type: Boolean,
994
- required: !1,
995
- default: !1
996
- },
997
- hasTrendAccess: {
998
- type: Boolean,
999
- required: !1,
1000
- default: !0
1001
- },
1002
- cardSize: {
1003
- type: String,
1004
- required: !1,
1005
- default: () => D.Large
1006
- },
1007
- containerTitle: {
1008
- type: String,
1009
- required: !1,
1010
- default: ""
1011
- },
1012
- containerDescription: {
1013
- type: String,
1014
- required: !1,
1015
- default: ""
1016
- }
1017
- },
1018
- setup(e) {
1019
- const r = e, t = h(() => r.cards.every((a) => (a == null ? void 0 : a.hasError) === !0)), o = (a) => {
1020
- const n = Kr(a.currentValue, a.previousValue) || 0, l = Ur(n, r.hasTrendAccess, a.increaseIsBad);
1021
- return {
1022
- metricValue: a.formatValueFn ? a.formatValueFn(a.currentValue) : qr(a.currentValue, { capital: !0, round: !0 }) || "0",
1023
- metricChange: a.formatChangeFn ? a.formatChangeFn(n) : zr(n, r.hasTrendAccess, r.fallbackDisplayText),
1024
- changePolarity: l,
1025
- trendIcon: Pr(l, a.increaseIsBad),
1026
- cardSize: r.cardSize,
1027
- hasContainerTitle: !!r.containerTitle
1028
- };
1029
- };
1030
- return (a, n) => (T(), _("div", {
1031
- class: U(["kong-ui-public-metric-card-container", e.cardSize])
1032
- }, [
1033
- r.containerTitle || r.containerDescription ? (T(), _("div", at, [
1034
- De(w(r.containerTitle) + " ", 1),
1035
- r.containerDescription ? (T(), _("div", it, w(r.containerDescription), 1)) : V("", !0)
1036
- ])) : V("", !0),
1037
- t.value ? (T(), _("div", ot, [
1038
- K(E(Oe), { class: "error-display-icon" }),
1039
- e.errorMessage ? (T(), _("div", st, w(e.errorMessage), 1)) : V("", !0)
1040
- ])) : (T(), _("div", ut, [
1041
- (T(!0), _(he, null, Xe(e.cards, (l, c) => (T(), _(he, null, [
1042
- e.loading ? (T(), N(nt, {
1043
- key: `skeleton-${c}`,
1044
- class: U(e.cardSize === E(D).Small ? "loading-tabs-small" : "loading-tabs-large")
1045
- }, null, 8, ["class"])) : (T(), N(Zr, Ge({
1046
- key: c,
1047
- ref_for: !0
1048
- }, o(l), {
1049
- "card-size": e.cardSize,
1050
- "card-type": l.cardType,
1051
- description: l.description,
1052
- "error-message": e.errorMessage,
1053
- "has-error": l.hasError,
1054
- title: l.title,
1055
- "title-tag": l.titleTag,
1056
- tooltip: l.tooltip,
1057
- "trend-range": l.trendRange
1058
- }), null, 16, ["card-size", "card-type", "description", "error-message", "has-error", "title", "title-tag", "tooltip", "trend-range"]))
1059
- ], 64))), 256))
1060
- ]))
1061
- ], 2));
1062
- }
1063
- }), ct = /* @__PURE__ */ ce(lt, [["__scopeId", "data-v-eac0ca04"]]), Tt = /* @__PURE__ */ Q({
1064
- __name: "MetricsConsumer",
1065
- props: {
1066
- lookupKey: { default: void 0 },
1067
- cardSize: { default: D.Large },
1068
- cardToDisplay: { default: void 0 }
1069
- },
1070
- setup(e) {
1071
- const r = e, t = _e(Ne);
1072
- if (!t)
1073
- throw new Error("MetricsConsumer must be nested inside a MetricsProvider instance.");
1074
- const { traffic: o, latency: a } = t.data, { i18n: n } = F.useI18n(), l = h(() => t.containerTitle.value ? D.Medium : r.cardSize), c = F.useMetricCardBuilder({
1075
- cardType: O.TRAFFIC,
1076
- title: h(() => t.longCardTitles ? n.t("metricCard.long.traffic") : n.t("metricCard.short.traffic")),
1077
- record: o.mapped,
1078
- hasError: o.hasError,
1079
- lookupKey: r.lookupKey,
1080
- sumGroupedValues: $,
1081
- trendRange: o.trendRange
1082
- }), f = (m) => `${m.toFixed(le)}%`, i = h(() => {
1083
- 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;
1084
- return {
1085
- cardType: O.ERROR_RATE,
1086
- hasError: o.hasError.value,
1087
- currentValue: y,
1088
- previousValue: A,
1089
- formatValueFn: f,
1090
- title: t.longCardTitles ? n.t("metricCard.long.errorRate") : n.t("metricCard.short.errorRate"),
1091
- increaseIsBad: !0,
1092
- trendRange: o.trendRange.value
1093
- };
1094
- }), s = (m) => `${m}ms`, u = F.useMetricCardBuilder({
1095
- cardType: O.LATENCY,
1096
- title: h(() => {
1097
- const { longCardTitles: m, averageLatencies: C } = t, p = C.value ? "averageLatency" : "p99Latency";
1098
- return m ? n.t(`metricCard.long.${p}`) : l.value === D.Small ? n.t(`metricCard.small.${p}`) : n.t(`metricCard.short.${p}`);
1099
- }),
1100
- hasError: a.hasError,
1101
- record: a.mapped,
1102
- lookupKey: r.lookupKey,
1103
- increaseIsBad: !0,
1104
- formatValueFn: s,
1105
- trendRange: a.trendRange
1106
- }), 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(() => ({
1107
- cards: d.value,
1108
- containerTitle: t.containerTitle.value,
1109
- containerDescription: t.description.value,
1110
- loading: v.value,
1111
- hasTrendAccess: t.hasTrendAccess.value,
1112
- fallbackDisplayText: n.t("general.notAvailable"),
1113
- cardSize: l.value,
1114
- hideTitle: !0
1115
- })), R = h(() => ({
1116
- loading: g.value.loading,
1117
- trafficCard: c.value,
1118
- errorRateCard: i.value,
1119
- latencyCard: u.value,
1120
- errorRateFormatted: f(i.value.currentValue),
1121
- latencyFormatted: s(u.value.currentValue)
1122
- }));
1123
- return (m, C) => Ie(m.$slots, "default", { cardValues: R.value }, () => [
1124
- K(ct, je(He(g.value)), null, 16)
1125
- ]);
1126
- }
1127
- }), j = (e) => new Date(e), Et = (e, r) => {
1128
- const t = e.body;
1129
- e.reply({
1130
- statusCode: 200,
1131
- body: dt(t, r)
1132
- });
1133
- }, Se = (e) => e.reduce((r, t) => (r[t] = { name: t }, r), {}), dt = (e, r) => {
1134
- var g, R;
1135
- 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;
1136
- if ((e.dimensions ?? []).length > 2)
1137
- throw new Error(`Explore only supports 0-2 dimensions; got: ${JSON.stringify(e.dimensions)}`);
1138
- 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 = [];
1139
- for (let m = 0; m < c; m++)
1140
- for (let C = 0; C < s; C++) {
1141
- const p = f ? { [f]: i[C] } : {};
1142
- (g = e.dimensions) != null && g.includes("status_code_grouped") ? $.forEach((y) => {
1143
- 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 });
1144
- d.push({
1145
- version: "v1",
1146
- timestamp: m === 0 ? j(n).toISOString() : j(n + l).toISOString(),
1147
- event: I
1148
- });
1149
- }) : d.push({
1150
- version: "v1",
1151
- timestamp: m === 0 ? j(n).toISOString() : j(n + l).toISOString(),
1152
- 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 })
1153
- });
1154
- }
1155
- const v = {
1156
- start_ms: n,
1157
- end_ms: a,
1158
- start: new Date(n).toISOString(),
1159
- end: new Date(a).toISOString(),
1160
- granularity_ms: l,
1161
- display: f ? {
1162
- [f]: Se(i),
1163
- ...(R = e.dimensions) != null && R.includes("status_code_grouped") ? { status_code_grouped: Se($) } : {}
1164
- } : {},
1165
- metric_names: e.metrics,
1166
- query_id: "test"
1167
- };
1168
- return {
1169
- data: d,
1170
- meta: v
1171
- };
1172
- };
1173
- export {
1174
- $ as ALL_STATUS_CODE_GROUPS,
1175
- hr as DEFAULT_REFRESH_INTERVAL,
1176
- gr as INJECT_QUERY_PROVIDER,
1177
- yr as MAX_ANALYTICS_REQUEST_RETRIES,
1178
- D as MetricCardSize,
1179
- O as MetricCardType,
1180
- Tt as MetricsConsumer,
1181
- Rt as MetricsProvider,
1182
- ge as STATUS_CODES_FAILED,
1183
- pt as STATUS_CODES_SUCCESS,
1184
- dt as mockExploreResponse,
1185
- Et as mockExploreResponseFromCypress
1186
- };