fix: added default value to time,space aggregation to fix query_range getting 500 for metric (#7414)

* fix: added default value to time,space aggregation to fix query_range getting 500 for metric

* fix: added all available operators as default when no attribute type is present

* fix: changed operator, time and space values to avg when empty attribute type
This commit is contained in:
SagarRajput-7 2025-03-28 12:06:09 +05:30 committed by GitHub
parent d8d8191a32
commit 8c4c357351
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 57 additions and 12 deletions

View File

@ -425,3 +425,45 @@ export const metricsEmptyTimeAggregateOperatorOptions: SelectOption<
string,
string
>[] = [];
export const metricsEmptySpaceAggregateOperatorOptions: SelectOption<
string,
string
>[] = [
{
value: MetricAggregateOperator.SUM,
label: 'Sum',
},
{
value: MetricAggregateOperator.AVG,
label: 'Avg',
},
{
value: MetricAggregateOperator.MIN,
label: 'Min',
},
{
value: MetricAggregateOperator.MAX,
label: 'Max',
},
{
value: MetricAggregateOperator.P50,
label: 'P50',
},
{
value: MetricAggregateOperator.P75,
label: 'P75',
},
{
value: MetricAggregateOperator.P90,
label: 'P90',
},
{
value: MetricAggregateOperator.P95,
label: 'P95',
},
{
value: MetricAggregateOperator.P99,
label: 'P99',
},
];

View File

@ -9,6 +9,8 @@ import {
PANEL_TYPES,
} from 'constants/queryBuilder';
import {
metricAggregateOperatorOptions,
metricsEmptySpaceAggregateOperatorOptions,
metricsGaugeSpaceAggregateOperatorOptions,
metricsHistogramSpaceAggregateOperatorOptions,
metricsSumSpaceAggregateOperatorOptions,
@ -21,6 +23,7 @@ import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { getMetricsOperatorsByAttributeType } from 'lib/newQueryBuilder/getMetricsOperatorsByAttributeType';
import { getOperatorsBySourceAndPanelType } from 'lib/newQueryBuilder/getOperatorsBySourceAndPanelType';
import { findDataTypeOfOperator } from 'lib/query/findDataTypeOfOperator';
import { isEmpty } from 'lodash-es';
import { useCallback, useEffect, useState } from 'react';
import { BaseAutocompleteData } from 'types/api/queryBuilder/queryAutocompleteResponse';
import {
@ -145,12 +148,14 @@ export const useQueryOperations: UseQueryOperations = ({
const handleMetricAggregateAtributeTypes = useCallback(
(aggregateAttribute: BaseAutocompleteData): any => {
const newOperators = getMetricsOperatorsByAttributeType({
dataSource: DataSource.METRICS,
panelType: panelType || PANEL_TYPES.TIME_SERIES,
aggregateAttributeType:
(aggregateAttribute.type as ATTRIBUTE_TYPES) || ATTRIBUTE_TYPES.GAUGE,
});
const newOperators = !isEmpty(aggregateAttribute.type)
? getMetricsOperatorsByAttributeType({
dataSource: DataSource.METRICS,
panelType: panelType || PANEL_TYPES.TIME_SERIES,
aggregateAttributeType:
(aggregateAttribute.type as ATTRIBUTE_TYPES) || ATTRIBUTE_TYPES.GAUGE,
})
: metricAggregateOperatorOptions;
switch (aggregateAttribute.type) {
case ATTRIBUTE_TYPES.SUM:
@ -168,7 +173,7 @@ export const useQueryOperations: UseQueryOperations = ({
setSpaceAggregationOptions(metricsHistogramSpaceAggregateOperatorOptions);
break;
default:
setSpaceAggregationOptions(metricsGaugeSpaceAggregateOperatorOptions);
setSpaceAggregationOptions(metricsEmptySpaceAggregateOperatorOptions);
break;
}
@ -194,14 +199,12 @@ export const useQueryOperations: UseQueryOperations = ({
if (newQuery.aggregateAttribute.type === ATTRIBUTE_TYPES.SUM) {
newQuery.aggregateOperator = MetricAggregateOperator.RATE;
newQuery.timeAggregation = MetricAggregateOperator.RATE;
} else if (newQuery.aggregateAttribute.type === ATTRIBUTE_TYPES.GAUGE) {
newQuery.spaceAggregation = MetricAggregateOperator.SUM;
} else {
newQuery.aggregateOperator = MetricAggregateOperator.AVG;
newQuery.timeAggregation = MetricAggregateOperator.AVG;
} else {
newQuery.timeAggregation = '';
newQuery.spaceAggregation = MetricAggregateOperator.AVG;
}
newQuery.spaceAggregation = '';
}
handleSetQueryData(index, newQuery);