Skip to content

Commit f6e2fc1

Browse files
committed
Adding interval information to Metrics Eexplorer API
1 parent ac480d4 commit f6e2fc1

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

x-pack/plugins/infra/common/http_api/metrics_explorer.ts

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ export const metricsExplorerSeriesRT = rt.type({
9090
id: rt.string,
9191
columns: rt.array(metricsExplorerColumnRT),
9292
rows: rt.array(metricsExplorerRowRT),
93+
intervals: rt.partial({
94+
current: rt.number,
95+
recommended: rt.number,
96+
}),
9397
});
9498

9599
export const metricsExplorerResponseRT = rt.type({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export const calculateIntervalFromRows = (rows: Array<{ timestamp: number }>) => {
8+
if (rows.length > 1) {
9+
return (rows[1].timestamp - rows[0].timestamp) / 1000;
10+
}
11+
};

x-pack/plugins/infra/server/routes/metrics_explorer/lib/populate_series_with_tsvb_data.ts

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { createMetricModel } from './create_metrics_model';
1717
import { JsonObject } from '../../../../common/typed_json';
1818
import { calculateMetricInterval } from '../../../utils/calculate_metric_interval';
1919
import { getDatasetForField } from './get_dataset_for_field';
20+
import { calculateIntervalFromRows } from './caclculate_interval_from_rows';
2021

2122
export const populateSeriesWithTSVBData = (
2223
request: KibanaRequest,
@@ -130,9 +131,14 @@ export const populateSeriesWithTSVBData = (
130131
{ timestamp, ...rowAttributes } as MetricsExplorerRow
131132
);
132133
});
134+
133135
return {
134136
...series,
135137
rows,
138+
intervals: {
139+
current: calculateIntervalFromRows(rows),
140+
recommended: calculatedInterval,
141+
},
136142
columns: [
137143
{ name: 'timestamp', type: 'date' } as MetricsExplorerColumn,
138144
...metricColumns,

0 commit comments

Comments
 (0)