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: query key is updated (#2894)

Palash Gupta148889e19839
diff --git a/frontend/src/container/FormAlertRules/QuerySection.tsx b/frontend/src/container/FormAlertRules/QuerySection.tsx
index 07f5be4f3a..b8c88ab683 100644
--- a/frontend/src/container/FormAlertRules/QuerySection.tsx
+++ b/frontend/src/container/FormAlertRules/QuerySection.tsx
@@ -38,10 +38,6 @@ function QuerySection({
/>
);
- const handleRunQuery = (): void => {
- runQuery();
- };
-
const tabs = [
{
label: t('tab_qb'),
@@ -76,7 +72,7 @@ function QuerySection({
onChange={handleQueryCategoryChange}
tabBarExtraContent={
<span style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}>
- <Button type="primary" onClick={handleRunQuery}>
+ <Button type="primary" onClick={runQuery}>
Run Query
</Button>
</span>
@@ -95,7 +91,7 @@ function QuerySection({
onChange={handleQueryCategoryChange}
tabBarExtraContent={
<span style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}>
- <Button type="primary" onClick={handleRunQuery}>
+ <Button type="primary" onClick={runQuery}>
Run Query
</Button>
</span>
@@ -132,7 +128,7 @@ interface QuerySectionProps {
queryCategory: EQueryType;
setQueryCategory: (n: EQueryType) => void;
alertType: AlertTypes;
- runQuery: () => void;
+ runQuery: VoidFunction;
}
export default QuerySection;
diff --git a/frontend/src/hooks/queryBuilder/useGetQueryRange.ts b/frontend/src/hooks/queryBuilder/useGetQueryRange.ts
index dbd35d5ede..7091ffb15b 100644
--- a/frontend/src/hooks/queryBuilder/useGetQueryRange.ts
+++ b/frontend/src/hooks/queryBuilder/useGetQueryRange.ts
@@ -1,5 +1,7 @@
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
+import { useMemo } from 'react';
import { useQuery, UseQueryOptions, UseQueryResult } from 'react-query';
+import { useLocation } from 'react-router-dom';
import {
GetMetricQueryRange,
GetQueryResultsProps,
@@ -10,9 +12,19 @@ import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange';
export const useGetQueryRange = (
requestData: GetQueryResultsProps,
options?: UseQueryOptions<SuccessResponse<MetricRangePayloadProps>, Error>,
-): UseQueryResult<SuccessResponse<MetricRangePayloadProps>, Error> =>
- useQuery<SuccessResponse<MetricRangePayloadProps>, Error>({
- queryKey: [REACT_QUERY_KEY.GET_QUERY_RANGE, requestData],
+): UseQueryResult<SuccessResponse<MetricRangePayloadProps>, Error> => {
+ const { key } = useLocation();
+
+ const queryKey = useMemo(() => {
+ if (options?.queryKey) {
+ return [...options.queryKey, key];
+ }
+ return [REACT_QUERY_KEY.GET_QUERY_RANGE, key, requestData];
+ }, [key, options?.queryKey, requestData]);
+
+ return useQuery<SuccessResponse<MetricRangePayloadProps>, Error>({
queryFn: async () => GetMetricQueryRange(requestData),
...options,
+ queryKey,
});
+};