-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathmetrics_explorer.ts
116 lines (89 loc) · 3.43 KB
/
metrics_explorer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import * as rt from 'io-ts';
export const METRIC_EXPLORER_AGGREGATIONS = [
'avg',
'max',
'min',
'cardinality',
'rate',
'count',
'sum',
] as const;
type MetricExplorerAggregations = typeof METRIC_EXPLORER_AGGREGATIONS[number];
const metricsExplorerAggregationKeys = METRIC_EXPLORER_AGGREGATIONS.reduce<
Record<MetricExplorerAggregations, null>
>((acc, agg) => ({ ...acc, [agg]: null }), {} as Record<MetricExplorerAggregations, null>);
export const metricsExplorerAggregationRT = rt.keyof(metricsExplorerAggregationKeys);
export const metricsExplorerMetricRequiredFieldsRT = rt.type({
aggregation: metricsExplorerAggregationRT,
});
export const metricsExplorerMetricOptionalFieldsRT = rt.partial({
field: rt.union([rt.string, rt.undefined]),
});
export const metricsExplorerMetricRT = rt.intersection([
metricsExplorerMetricRequiredFieldsRT,
metricsExplorerMetricOptionalFieldsRT,
]);
export const timeRangeRT = rt.type({
field: rt.string,
from: rt.number,
to: rt.number,
interval: rt.string,
});
export const metricsExplorerRequestBodyRequiredFieldsRT = rt.type({
timerange: timeRangeRT,
indexPattern: rt.string,
metrics: rt.array(metricsExplorerMetricRT),
});
export const metricsExplorerRequestBodyOptionalFieldsRT = rt.partial({
groupBy: rt.union([rt.string, rt.null, rt.undefined]),
afterKey: rt.union([rt.string, rt.null, rt.undefined]),
limit: rt.union([rt.number, rt.null, rt.undefined]),
filterQuery: rt.union([rt.string, rt.null, rt.undefined]),
forceInterval: rt.boolean,
});
export const metricsExplorerRequestBodyRT = rt.intersection([
metricsExplorerRequestBodyRequiredFieldsRT,
metricsExplorerRequestBodyOptionalFieldsRT,
]);
export const metricsExplorerPageInfoRT = rt.type({
total: rt.number,
afterKey: rt.union([rt.string, rt.null]),
});
export const metricsExplorerColumnTypeRT = rt.keyof({
date: null,
number: null,
string: null,
});
export const metricsExplorerColumnRT = rt.type({
name: rt.string,
type: metricsExplorerColumnTypeRT,
});
export const metricsExplorerRowRT = rt.intersection([
rt.type({
timestamp: rt.number,
}),
rt.record(rt.string, rt.union([rt.string, rt.number, rt.null, rt.undefined])),
]);
export const metricsExplorerSeriesRT = rt.type({
id: rt.string,
columns: rt.array(metricsExplorerColumnRT),
rows: rt.array(metricsExplorerRowRT),
});
export const metricsExplorerResponseRT = rt.type({
series: rt.array(metricsExplorerSeriesRT),
pageInfo: metricsExplorerPageInfoRT,
});
export type MetricsExplorerAggregation = rt.TypeOf<typeof metricsExplorerAggregationRT>;
export type MetricsExplorerColumnType = rt.TypeOf<typeof metricsExplorerColumnTypeRT>;
export type MetricsExplorerMetric = rt.TypeOf<typeof metricsExplorerMetricRT>;
export type MetricsExplorerPageInfo = rt.TypeOf<typeof metricsExplorerPageInfoRT>;
export type MetricsExplorerColumn = rt.TypeOf<typeof metricsExplorerColumnRT>;
export type MetricsExplorerRow = rt.TypeOf<typeof metricsExplorerRowRT>;
export type MetricsExplorerSeries = rt.TypeOf<typeof metricsExplorerSeriesRT>;
export type MetricsExplorerRequestBody = rt.TypeOf<typeof metricsExplorerRequestBodyRT>;
export type MetricsExplorerResponse = rt.TypeOf<typeof metricsExplorerResponseRT>;