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: added fix for issue-3226, where the query was getting malformed (#9603)

Abhi kumar6a378ed7b455
diff --git a/frontend/src/components/QueryBuilderV2/utils.ts b/frontend/src/components/QueryBuilderV2/utils.ts
index be0cbfcd9c..26be437a48 100644
--- a/frontend/src/components/QueryBuilderV2/utils.ts
+++ b/frontend/src/components/QueryBuilderV2/utils.ts
@@ -224,7 +224,7 @@ export const convertFiltersToExpressionWithExistingQuery = (
const visitedPairs: Set<string> = new Set(); // Set to track visited query pairs
// Map extracted query pairs to key-specific pair information for faster access
- let queryPairsMap = getQueryPairsMap(existingQuery.trim());
+ let queryPairsMap = getQueryPairsMap(existingQuery);
filters?.items?.forEach((filter) => {
const { key, op, value } = filter;
@@ -309,7 +309,7 @@ export const convertFiltersToExpressionWithExistingQuery = (
)}${OPERATORS.IN} ${formattedValue} ${modifiedQuery.slice(
notInPair.position.valueEnd + 1,
)}`;
- queryPairsMap = getQueryPairsMap(modifiedQuery.trim());
+ queryPairsMap = getQueryPairsMap(modifiedQuery);
}
shouldAddToNonExisting = false; // Don't add this to non-existing filters
} else if (
diff --git a/frontend/src/utils/__tests__/queryContextUtils.test.ts b/frontend/src/utils/__tests__/queryContextUtils.test.ts
index 81ddc8f211..2cea3edcb1 100644
--- a/frontend/src/utils/__tests__/queryContextUtils.test.ts
+++ b/frontend/src/utils/__tests__/queryContextUtils.test.ts
@@ -26,7 +26,16 @@ describe('extractQueryPairs', () => {
valuesPosition: [],
hasNegation: true,
isMultiValue: false,
- position: expect.any(Object),
+ position: {
+ keyStart: 0,
+ keyEnd: 5,
+ negationEnd: 9,
+ negationStart: 7,
+ operatorEnd: 16,
+ operatorStart: 11,
+ valueEnd: undefined,
+ valueStart: undefined,
+ },
isComplete: false,
},
{
@@ -37,7 +46,16 @@ describe('extractQueryPairs', () => {
valuesPosition: [],
hasNegation: true,
isMultiValue: false,
- position: expect.any(Object),
+ position: {
+ keyEnd: 25,
+ keyStart: 22,
+ negationEnd: 29,
+ negationStart: 27,
+ operatorEnd: 34,
+ operatorStart: 31,
+ valueEnd: 42,
+ valueStart: 36,
+ },
isComplete: true,
},
]);
@@ -54,12 +72,11 @@ describe('extractQueryPairs', () => {
isComplete: true,
value: expect.stringMatching(/^\(.*\)$/),
valueList: ['1', '2', '3'],
- valuesPosition: expect.arrayContaining([
- expect.objectContaining({
- start: expect.any(Number),
- end: expect.any(Number),
- }),
- ]),
+ valuesPosition: [
+ { start: 7, end: 7 },
+ { start: 10, end: 10 },
+ { start: 13, end: 13 },
+ ],
}),
]);
});
@@ -75,6 +92,31 @@ describe('extractQueryPairs', () => {
isComplete: true,
value: expect.stringMatching(/^\[.*\]$/),
valueList: ["'a'", "'b'", "'c'"],
+ valuesPosition: [
+ { start: 11, end: 13 },
+ { start: 18, end: 20 },
+ { start: 25, end: 27 },
+ ],
+ }),
+ ]);
+ });
+
+ test('should extract correct query pairs when the query has space at the start of the value', () => {
+ const input = " label IN [ 'a' , 'b' , 'c' ]";
+ const result = extractQueryPairs(input);
+ expect(result).toEqual([
+ expect.objectContaining({
+ key: 'label',
+ operator: 'IN',
+ isMultiValue: true,
+ isComplete: true,
+ value: expect.stringMatching(/^\[.*\]$/),
+ valueList: ["'a'", "'b'", "'c'"],
+ valuesPosition: [
+ { start: 13, end: 15 },
+ { start: 20, end: 22 },
+ { start: 27, end: 29 },
+ ],
}),
]);
});