Adding interval information to Metrics Eexplorer API

This commit is contained in:
Chris Cowan 2020-04-29 12:15:33 -07:00
parent ac480d4afa
commit f6e2fc11be
3 changed files with 21 additions and 0 deletions

View file

@ -90,6 +90,10 @@ export const metricsExplorerSeriesRT = rt.type({
id: rt.string,
columns: rt.array(metricsExplorerColumnRT),
rows: rt.array(metricsExplorerRowRT),
intervals: rt.partial({
current: rt.number,
recommended: rt.number,
}),
});
export const metricsExplorerResponseRT = rt.type({

View file

@ -0,0 +1,11 @@
/*
* 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.
*/
export const calculateIntervalFromRows = (rows: Array<{ timestamp: number }>) => {
if (rows.length > 1) {
return (rows[1].timestamp - rows[0].timestamp) / 1000;
}
};

View file

@ -17,6 +17,7 @@ import { createMetricModel } from './create_metrics_model';
import { JsonObject } from '../../../../common/typed_json';
import { calculateMetricInterval } from '../../../utils/calculate_metric_interval';
import { getDatasetForField } from './get_dataset_for_field';
import { calculateIntervalFromRows } from './caclculate_interval_from_rows';
export const populateSeriesWithTSVBData = (
request: KibanaRequest,
@ -130,9 +131,14 @@ export const populateSeriesWithTSVBData = (
{ timestamp, ...rowAttributes } as MetricsExplorerRow
);
});
return {
...series,
rows,
intervals: {
current: calculateIntervalFromRows(rows),
recommended: calculatedInterval,
},
columns: [
{ name: 'timestamp', type: 'date' } as MetricsExplorerColumn,
...metricColumns,