[Metrics UI] Fix Metrics Explorer API to return empty results when field is missing from aggregation (#80919)
* [Metrics UI] Fix Metrics Explorer API to return empty results when field is missing from aggregation * Update x-pack/plugins/infra/server/routes/metrics_explorer/lib/convert_request_to_metrics_api_options.ts Co-authored-by: Felix Stürmer <weltenwort@users.noreply.github.com> * Fixing type Co-authored-by: Felix Stürmer <weltenwort@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
96fd83b1a4
commit
43b31e1b2b
|
@ -9,7 +9,7 @@ import { MetricsAPIMetric, MetricsExplorerMetric } from '../../../../common/http
|
|||
export const convertMetricToMetricsAPIMetric = (
|
||||
metric: MetricsExplorerMetric,
|
||||
index: number
|
||||
): MetricsAPIMetric => {
|
||||
): MetricsAPIMetric | undefined => {
|
||||
const id = `metric_${index}`;
|
||||
if (metric.aggregation === 'rate' && metric.field) {
|
||||
return {
|
||||
|
@ -44,6 +44,7 @@ export const convertMetricToMetricsAPIMetric = (
|
|||
};
|
||||
}
|
||||
|
||||
if (metric.aggregation === 'count') {
|
||||
return {
|
||||
id,
|
||||
aggregations: {
|
||||
|
@ -59,4 +60,5 @@ export const convertMetricToMetricsAPIMetric = (
|
|||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -120,4 +120,16 @@ describe('convertRequestToMetricsAPIOptions', () => {
|
|||
metrics: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('should work with empty field', () => {
|
||||
expect(
|
||||
convertRequestToMetricsAPIOptions({
|
||||
...BASE_REQUEST,
|
||||
metrics: [{ aggregation: 'avg' }],
|
||||
})
|
||||
).toEqual({
|
||||
...BASE_METRICS_UI_OPTIONS,
|
||||
metrics: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,7 +15,9 @@ import { convertMetricToMetricsAPIMetric } from './convert_metric_to_metrics_api
|
|||
export const convertRequestToMetricsAPIOptions = (
|
||||
options: MetricsExplorerRequestBody
|
||||
): MetricsAPIRequest => {
|
||||
const metrics = options.metrics.map(convertMetricToMetricsAPIMetric);
|
||||
const metrics = options.metrics
|
||||
.map(convertMetricToMetricsAPIMetric)
|
||||
.filter(<M>(m: M): m is NonNullable<M> => !!m);
|
||||
const { limit, timerange, indexPattern } = options;
|
||||
|
||||
const metricsApiOptions: MetricsAPIRequest = {
|
||||
|
|
Loading…
Reference in a new issue