Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: fixed metric aggregation and value retention inconsistency in edit mode (#8718)

SagarRajput-741ee4176ad15
diff --git a/frontend/src/api/v5/queryRange/convertV5Response.ts b/frontend/src/api/v5/queryRange/convertV5Response.ts
index b58db0727d..f4328dc807 100644
--- a/frontend/src/api/v5/queryRange/convertV5Response.ts
+++ b/frontend/src/api/v5/queryRange/convertV5Response.ts
@@ -385,7 +385,7 @@ export function convertV5ResponseToLegacy(
data: {
resultType: 'scalar',
result: webTables,
- warnings: v5Data?.data?.warnings || [],
+ warnings: v5Data?.data?.warning || [],
},
warning: v5Data?.warning || undefined,
},
diff --git a/frontend/src/container/FormAlertRules/ChartPreview/index.tsx b/frontend/src/container/FormAlertRules/ChartPreview/index.tsx
index acdee708bf..9be72e44e6 100644
--- a/frontend/src/container/FormAlertRules/ChartPreview/index.tsx
+++ b/frontend/src/container/FormAlertRules/ChartPreview/index.tsx
@@ -28,6 +28,7 @@ import getTimeString from 'lib/getTimeString';
import history from 'lib/history';
import { getUPlotChartOptions } from 'lib/uPlotLib/getUplotChartOptions';
import { getUPlotChartData } from 'lib/uPlotLib/utils/getUplotChartData';
+import { isEmpty } from 'lodash-es';
import { useAppContext } from 'providers/App/App';
import { useTimezone } from 'providers/Timezone';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
@@ -313,7 +314,7 @@ function ChartPreview({
featureFlags?.find((flag) => flag.name === FeatureKeys.ANOMALY_DETECTION)
?.active || false;
- const isWarning = !!queryResponse.data?.warning?.message;
+ const isWarning = !isEmpty(queryResponse.data?.warning);
return (
<div className="alert-chart-container" ref={graphRef}>
<ChartContainer>
diff --git a/frontend/src/container/FormAlertRules/index.tsx b/frontend/src/container/FormAlertRules/index.tsx
index a8d7ff3497..c6952c3295 100644
--- a/frontend/src/container/FormAlertRules/index.tsx
+++ b/frontend/src/container/FormAlertRules/index.tsx
@@ -240,8 +240,18 @@ function FormAlertRules({
const queryData = currentQuery.builder.queryData[index];
const updatedFunctions = updateFunctions(queryData);
- queryData.functions = updatedFunctions;
- handleSetQueryData(index, queryData);
+
+ // Only update if functions actually changed to avoid resetting aggregateAttribute
+ const currentFunctions = queryData.functions || [];
+ const functionsChanged = !isEqual(currentFunctions, updatedFunctions);
+
+ if (functionsChanged) {
+ const updatedQueryData = {
+ ...queryData,
+ functions: updatedFunctions,
+ };
+ handleSetQueryData(index, updatedQueryData);
+ }
}
};
diff --git a/frontend/src/container/GridCardLayout/GridCard/index.tsx b/frontend/src/container/GridCardLayout/GridCard/index.tsx
index 35a525b536..56585d13bc 100644
--- a/frontend/src/container/GridCardLayout/GridCard/index.tsx
+++ b/frontend/src/container/GridCardLayout/GridCard/index.tsx
@@ -301,7 +301,7 @@ function GridCardGraph({
widget={widget}
queryResponse={queryResponse}
errorMessage={errorMessage}
- isWarning={!!queryResponse.data?.warning?.message}
+ isWarning={!isEmpty(queryResponse.data?.warning)}
version={version}
threshold={threshold}
headerMenuList={menuList}
diff --git a/frontend/src/container/MetricsExplorer/Explorer/Explorer.tsx b/frontend/src/container/MetricsExplorer/Explorer/Explorer.tsx
index a2dbf01836..33cbf39411 100644
--- a/frontend/src/container/MetricsExplorer/Explorer/Explorer.tsx
+++ b/frontend/src/container/MetricsExplorer/Explorer/Explorer.tsx
@@ -13,6 +13,7 @@ import DateTimeSelector from 'container/TopNav/DateTimeSelectionV2';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { useShareBuilderUrl } from 'hooks/queryBuilder/useShareBuilderUrl';
import { useSafeNavigate } from 'hooks/useSafeNavigate';
+import { isEmpty } from 'lodash-es';
import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useSearchParams } from 'react-router-dom-v5-compat';
@@ -135,7 +136,7 @@ function Explorer(): JSX.Element {
/>
</div>
<div className="explore-header-right-actions">
- {warning?.message && <WarningPopover warningData={warning} />}
+ {!isEmpty(warning) && <WarningPopover warningData={warning} />}
<DateTimeSelector showAutoRefresh />
<RightToolbarActions
onStageRunQuery={(): void => handleRunQuery(true, true)}
diff --git a/frontend/src/container/MetricsExplorer/MetricDetails/utils.tsx b/frontend/src/container/MetricsExplorer/MetricDetails/utils.tsx
index a57d27a6f8..492115baa4 100644
--- a/frontend/src/container/MetricsExplorer/MetricDetails/utils.tsx
+++ b/frontend/src/container/MetricsExplorer/MetricDetails/utils.tsx
@@ -1,5 +1,6 @@
import { Temporality } from 'api/metricsExplorer/getMetricDetails';
import { MetricType } from 'api/metricsExplorer/getMetricsList';
+import { SpaceAggregation, TimeAggregation } from 'api/v5/v5';
import { initialQueriesMap } from 'constants/queryBuilder';
import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';
import { Query } from 'types/api/queryBuilder/queryBuilderData';
@@ -110,6 +111,15 @@ export function getMetricDetailsQuery(
isJSON: false,
dataType: DataTypes.String,
},
+ aggregations: [
+ {
+ metricName,
+ timeAggregation: timeAggregation as TimeAggregation,
+ spaceAggregation: spaceAggregation as SpaceAggregation,
+ reduceTo: 'avg',
+ temporality: '',
+ },
+ ],
aggregateOperator,
timeAggregation,
spaceAggregation,
diff --git a/frontend/src/container/NewWidget/LeftContainer/WidgetGraph/index.tsx b/frontend/src/container/NewWidget/LeftContainer/WidgetGraph/index.tsx
index 622566a247..d279db4d2f 100644
--- a/frontend/src/container/NewWidget/LeftContainer/WidgetGraph/index.tsx
+++ b/frontend/src/container/NewWidget/LeftContainer/WidgetGraph/index.tsx
@@ -6,6 +6,7 @@ import { Card } from 'container/GridCardLayout/styles';
import DateTimeSelectionV2 from 'container/TopNav/DateTimeSelectionV2';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { useIsDarkMode } from 'hooks/useDarkMode';
+import { isEmpty } from 'lodash-es';
import { memo } from 'react';
import { Warning } from 'types/api';
@@ -38,7 +39,7 @@ function WidgetGraph({
<div className="header">
<div className="header-left">
<PlotTag queryType={currentQuery.queryType} panelType={selectedGraph} />
- {queryResponse.data?.warning?.message && (
+ {!isEmpty(queryResponse.data?.warning) && (
<WarningPopover warningData={queryResponse.data?.warning as Warning} />
)}
</div>
diff --git a/frontend/src/container/QueryBuilder/filters/AggregatorFilter/AggregatorFilter.intefaces.ts b/frontend/src/container/QueryBuilder/filters/AggregatorFilter/AggregatorFilter.intefaces.ts
index 4703566230..a94b78946e 100644
--- a/frontend/src/container/QueryBuilder/filters/AggregatorFilter/AggregatorFilter.intefaces.ts
+++ b/frontend/src/container/QueryBuilder/filters/AggregatorFilter/AggregatorFilter.intefaces.ts
@@ -4,7 +4,7 @@ import { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
export type AgregatorFilterProps = Pick<AutoCompleteProps, 'disabled'> & {
query: IBuilderQuery;
- onChange: (value: BaseAutocompleteData) => void;
+ onChange: (value: BaseAutocompleteData, isEditMode?: boolean) => void;
defaultValue?: string;
onSelect?: (value: BaseAutocompleteData) => void;
index?: number;
diff --git a/frontend/src/container/QueryBuilder/filters/AggregatorFilter/AggregatorFilter.tsx b/frontend/src/container/QueryBuilder/filters/AggregatorFilter/AggregatorFilter.tsx
index 52dcb3f8ee..3c30536468 100644
--- a/frontend/src/container/QueryBuilder/filters/AggregatorFilter/AggregatorFilter.tsx
+++ b/frontend/src/container/QueryBuilder/filters/AggregatorFilter/AggregatorFilter.tsx
@@ -135,7 +135,7 @@ export const AggregatorFilter = memo(function AggregatorFilter({
if (metricData) {
// Update the aggregateAttribute with the fetched type information
- onChange(metricData);
+ onChange(metricData, true);
}
}
}, [
@@ -214,11 +214,16 @@ export const AggregatorFilter = memo(function AggregatorFilter({
);
const handleBlur = useCallback(async () => {
- if (searchText) {
+ if (searchText && searchText !== queryAggregation.metricName) {
const aggregateAttributes = await getResponseAttributes();
handleChangeCustomValue(searchText, aggregateAttributes);
}
- }, [getResponseAttributes, handleChangeCustomValue, searchText]);
+ }, [
+ getResponseAttributes,
+ handleChangeCustomValue,
+ searchText,
+ queryAggregation?.metricName,
+ ]);
const handleChange = useCallback(
(
diff --git a/frontend/src/hooks/queryBuilder/useQueryBuilderOperations.ts b/frontend/src/hooks/queryBuilder/useQueryBuilderOperations.ts
index f282ceab68..cc60a9e50f 100644
--- a/frontend/src/hooks/queryBuilder/useQueryBuilderOperations.ts
+++ b/frontend/src/hooks/queryBuilder/useQueryBuilderOperations.ts
@@ -212,7 +212,7 @@ export const useQueryOperations: UseQueryOperations = ({
);
const handleChangeAggregatorAttribute = useCallback(
- (value: BaseAutocompleteData): void => {
+ (value: BaseAutocompleteData, isEditMode?: boolean): void => {
const newQuery: IBuilderQuery = {
...query,
aggregateAttribute: value,
@@ -226,30 +226,32 @@ export const useQueryOperations: UseQueryOperations = ({
handleMetricAggregateAtributeTypes(newQuery.aggregateAttribute);
}
- if (newQuery.aggregateAttribute?.type === ATTRIBUTE_TYPES.SUM) {
- newQuery.aggregateOperator = MetricAggregateOperator.RATE;
- newQuery.timeAggregation = MetricAggregateOperator.RATE;
- } else if (newQuery.aggregateAttribute?.type === ATTRIBUTE_TYPES.GAUGE) {
- newQuery.aggregateOperator = MetricAggregateOperator.AVG;
- newQuery.timeAggregation = MetricAggregateOperator.AVG;
- } else {
- newQuery.timeAggregation = '';
- }
-
- newQuery.spaceAggregation = '';
-
- // Handled query with unknown metric to avoid 400 and 500 errors
- // With metric value typed and not available then - time - 'avg', space - 'avg'
- // If not typed - time - 'rate', space - 'sum', op - 'count'
- if (isEmpty(newQuery.aggregateAttribute?.type)) {
- if (!isEmpty(newQuery.aggregateAttribute?.key)) {
+ if (!isEditMode) {
+ if (newQuery.aggregateAttribute?.type === ATTRIBUTE_TYPES.SUM) {
+ newQuery.aggregateOperator = MetricAggregateOperator.RATE;
+ newQuery.timeAggregation = MetricAggregateOperator.RATE;
+ } else if (newQuery.aggregateAttribute?.type === ATTRIBUTE_TYPES.GAUGE) {
newQuery.aggregateOperator = MetricAggregateOperator.AVG;
newQuery.timeAggregation = MetricAggregateOperator.AVG;
- newQuery.spaceAggregation = MetricAggregateOperator.AVG;
} else {
- newQuery.aggregateOperator = MetricAggregateOperator.COUNT;
- newQuery.timeAggregation = MetricAggregateOperator.RATE;
- newQuery.spaceAggregation = MetricAggregateOperator.SUM;
+ newQuery.timeAggregation = '';
+ }
+
+ newQuery.spaceAggregation = '';
+
+ // Handled query with unknown metric to avoid 400 and 500 errors
+ // With metric value typed and not available then - time - 'avg', space - 'avg'
+ // If not typed - time - 'rate', space - 'sum', op - 'count'
+ if (isEmpty(newQuery.aggregateAttribute?.type)) {
+ if (!isEmpty(newQuery.aggregateAttribute?.key)) {
+ newQuery.aggregateOperator = MetricAggregateOperator.AVG;
+ newQuery.timeAggregation = MetricAggregateOperator.AVG;
+ newQuery.spaceAggregation = MetricAggregateOperator.AVG;
+ } else {
+ newQuery.aggregateOperator = MetricAggregateOperator.COUNT;
+ newQuery.timeAggregation = MetricAggregateOperator.RATE;
+ newQuery.spaceAggregation = MetricAggregateOperator.SUM;
+ }
}
}
}
@@ -262,61 +264,63 @@ export const useQueryOperations: UseQueryOperations = ({
handleMetricAggregateAtributeTypes(newQuery.aggregateAttribute);
}
- if (newQuery.aggregateAttribute?.type === ATTRIBUTE_TYPES.SUM) {
- newQuery.aggregations = [
- {
- timeAggregation: MetricAggregateOperator.RATE,
- metricName: newQuery.aggregateAttribute?.key || '',
- temporality: '',
- spaceAggregation: '',
- },
- ];
- } else if (newQuery.aggregateAttribute?.type === ATTRIBUTE_TYPES.GAUGE) {
- newQuery.aggregations = [
- {
- timeAggregation: MetricAggregateOperator.AVG,
- metricName: newQuery.aggregateAttribute?.key || '',
- temporality: '',
- spaceAggregation: '',
- },
- ];
- } else {
- newQuery.aggregations = [
- {
- timeAggregation: '',
- metricName: newQuery.aggregateAttribute?.key || '',
- temporality: '',
- spaceAggregation: '',
- },
- ];
- }
-
- newQuery.aggregateOperator = '';
- newQuery.spaceAggregation = '';
-
- // Handled query with unknown metric to avoid 400 and 500 errors
- // With metric value typed and not available then - time - 'avg', space - 'avg'
- // If not typed - time - 'rate', space - 'sum', op - 'count'
- if (isEmpty(newQuery.aggregateAttribute?.type)) {
- if (!isEmpty(newQuery.aggregateAttribute?.key)) {
+ if (!isEditMode) {
+ if (newQuery.aggregateAttribute?.type === ATTRIBUTE_TYPES.SUM) {
+ newQuery.aggregations = [
+ {
+ timeAggregation: MetricAggregateOperator.RATE,
+ metricName: newQuery.aggregateAttribute?.key || '',
+ temporality: '',
+ spaceAggregation: '',
+ },
+ ];
+ } else if (newQuery.aggregateAttribute?.type === ATTRIBUTE_TYPES.GAUGE) {
newQuery.aggregations = [
{
timeAggregation: MetricAggregateOperator.AVG,
metricName: newQuery.aggregateAttribute?.key || '',
temporality: '',
- spaceAggregation: MetricAggregateOperator.AVG,
+ spaceAggregation: '',
},
];
} else {
newQuery.aggregations = [
{
- timeAggregation: MetricAggregateOperator.COUNT,
+ timeAggregation: '',
metricName: newQuery.aggregateAttribute?.key || '',
temporality: '',
- spaceAggregation: MetricAggregateOperator.SUM,
+ spaceAggregation: '',
},
];
}
+
+ newQuery.aggregateOperator = '';
+ newQuery.spaceAggregation = '';
+
+ // Handled query with unknown metric to avoid 400 and 500 errors
+ // With metric value typed and not available then - time - 'avg', space - 'avg'
+ // If not typed - time - 'rate', space - 'sum', op - 'count'
+ if (isEmpty(newQuery.aggregateAttribute?.type)) {
+ if (!isEmpty(newQuery.aggregateAttribute?.key)) {
+ newQuery.aggregations = [
+ {
+ timeAggregation: MetricAggregateOperator.AVG,
+ metricName: newQuery.aggregateAttribute?.key || '',
+ temporality: '',
+ spaceAggregation: MetricAggregateOperator.AVG,
+ },
+ ];
+ } else {
+ newQuery.aggregations = [
+ {
+ timeAggregation: MetricAggregateOperator.COUNT,
+ metricName: newQuery.aggregateAttribute?.key || '',
+ temporality: '',
+ spaceAggregation: MetricAggregateOperator.SUM,
+ },
+ ];
+ }
+ }
}
}
diff --git a/frontend/src/pages/LogsExplorer/index.tsx b/frontend/src/pages/LogsExplorer/index.tsx
index 9c6d82e26f..47e6fb90f4 100644
--- a/frontend/src/pages/LogsExplorer/index.tsx
+++ b/frontend/src/pages/LogsExplorer/index.tsx
@@ -28,7 +28,7 @@ import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { useShareBuilderUrl } from 'hooks/queryBuilder/useShareBuilderUrl';
import { useHandleExplorerTabChange } from 'hooks/useHandleExplorerTabChange';
import useUrlQueryData from 'hooks/useUrlQueryData';
-import { isEqual, isNull } from 'lodash-es';
+import { isEmpty, isEqual, isNull } from 'lodash-es';
import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';
import { usePreferenceContext } from 'providers/preferences/context/PreferenceContextProvider';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
@@ -361,7 +361,7 @@ function LogsExplorer(): JSX.Element {
/>
}
warningElement={
- warning?.message ? <WarningPopover warningData={warning} /> : <div />
+ !isEmpty(warning) ? <WarningPopover warningData={warning} /> : <div />
}
rightActions={
<RightToolbarActions
diff --git a/frontend/src/pages/TracesExplorer/index.tsx b/frontend/src/pages/TracesExplorer/index.tsx
index 82d156a3e1..6bde8d4723 100644
--- a/frontend/src/pages/TracesExplorer/index.tsx
+++ b/frontend/src/pages/TracesExplorer/index.tsx
@@ -318,7 +318,7 @@ function TracesExplorer(): JSX.Element {
/>
}
warningElement={
- warning?.message ? <WarningPopover warningData={warning} /> : <div />
+ !isEmpty(warning) ? <WarningPopover warningData={warning} /> : <div />
}
rightActions={
<RightToolbarActions
diff --git a/frontend/src/types/api/v5/queryRange.ts b/frontend/src/types/api/v5/queryRange.ts
index 38d05d00b4..1546d5e0bd 100644
--- a/frontend/src/types/api/v5/queryRange.ts
+++ b/frontend/src/types/api/v5/queryRange.ts
@@ -420,7 +420,7 @@ export type QueryRangeDataV5 =
export interface QueryRangeResponseV5 {
type: RequestType;
- data: QueryRangeDataV5 & { warnings?: string[] };
+ data: QueryRangeDataV5 & { warning?: string[] };
meta: ExecStats;
warning?: Warning;
}