🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(dashboards): patch invalid tags filter (#8445)
Steffen Schmitzab2669291371
diff --git a/web/src/__tests__/async/metrics-api.servertest.ts b/web/src/__tests__/async/metrics-api.servertest.tsindex a13a78e234..829ad3f6a9 100644--- a/web/src/__tests__/async/metrics-api.servertest.ts+++ b/web/src/__tests__/async/metrics-api.servertest.ts@@ -497,4 +497,137 @@ describe("/api/public/metrics API Endpoint", () => {expect(height).toBeGreaterThanOrEqual(0);});});++ describe("LFE-6148: Comprehensive filter validation", () => {+ it("should return 400 error for invalid array field filters", async () => {+ // Test using string type on array field (tags) - should return validation error+ const invalidStringTypeQuery = {+ view: "traces",+ dimensions: [{ field: "name" }],+ metrics: [{ measure: "count", aggregation: "count" }],+ filters: [+ {+ column: "tags",+ operator: "contains",+ value: "test-tag",+ type: "string", // Invalid: array fields require arrayOptions type+ },+ ],+ timeDimension: {+ granularity: "day",+ },+ fromTimestamp: yesterday.toISOString(),+ toTimestamp: tomorrow.toISOString(),+ orderBy: null,+ };++ // Make API call and expect 400 error+ const response = await makeAPICall(+ "GET",+ `/api/public/metrics?query=${encodeURIComponent(JSON.stringify(invalidStringTypeQuery))}`,+ );++ expect(response.status).toBe(400);+ expect(response.body).toMatchObject({+ error: "InvalidRequestError",+ message: expect.stringContaining(+ "Array fields require type 'arrayOptions', not 'string'",+ ),+ });+ });++ it("should return 400 error for invalid metadata filters", async () => {+ // Test using wrong type for metadata field+ const invalidMetadataTypeQuery = {+ view: "traces",+ dimensions: [{ field: "name" }],+ metrics: [{ measure: "count", aggregation: "count" }],+ filters: [+ {+ column: "metadata",+ operator: "contains",+ value: "test-value",+ type: "string", // Invalid: metadata requires stringObject type+ },+ ],+ timeDimension: null,+ fromTimestamp: yesterday.toISOString(),+ toTimestamp: tomorrow.toISOString(),+ orderBy: null,+ };++ const response = await makeAPICall(+ "GET",+ `/api/public/metrics?query=${encodeURIComponent(JSON.stringify(invalidMetadataTypeQuery))}`,+ );++ expect(response.status).toBe(400);+ expect(response.body).toMatchObject({+ error: "InvalidRequestError",+ message: expect.stringContaining(+ "Metadata filters require type 'stringObject'",+ ),+ });+ });++ it("should work correctly with proper array field filter configuration", async () => {+ // Setup test data with tags+ const taggedTraceId = randomUUID();+ await createTracesCh([+ createTrace({+ id: taggedTraceId,+ name: "tagged-trace",+ project_id: projectId,+ timestamp: now.getTime(),+ tags: ["test-tag", "another-tag"],+ metadata: { test: testMetadataValue },+ }),+ ]);++ // Test with correct arrayOptions filter+ const validQuery = {+ view: "traces",+ dimensions: [{ field: "name" }],+ metrics: [{ measure: "count", aggregation: "count" }],+ filters: [+ {+ column: "tags",+ operator: "any of", // Correct operator for array fields+ value: ["test-tag"],+ type: "arrayOptions", // Correct type for array fields+ },+ {+ column: "metadata",+ operator: "contains",+ key: "test",+ value: testMetadataValue,+ type: "stringObject",+ },+ ],+ timeDimension: null,+ fromTimestamp: yesterday.toISOString(),+ toTimestamp: tomorrow.toISOString(),+ orderBy: null,+ };++ // Make the API call+ const response = await makeZodVerifiedAPICall(+ GetMetricsV1Response,+ "GET",+ `/api/public/metrics?query=${encodeURIComponent(JSON.stringify(validQuery))}`,+ );++ // Should succeed and return data+ expect(response.status).toBe(200);+ expect(Array.isArray(response.body.data)).toBe(true);+ expect(response.body.data.length).toBeGreaterThan(0);++ // Verify we got the tagged trace+ const taggedTraceResult = response.body.data.find(+ (row: any) => row.name === "tagged-trace",+ );+ expect(taggedTraceResult).toBeDefined();+ expect(taggedTraceResult.count_count).toBe("1");+ });+ });});diff --git a/web/src/features/query/server/queryBuilder.ts b/web/src/features/query/server/queryBuilder.tsindex baccd2927b..f0737e5ec8 100644--- a/web/src/features/query/server/queryBuilder.ts+++ b/web/src/features/query/server/queryBuilder.ts@@ -117,10 +117,71 @@ export class QueryBuilder {});}+ private validateFilters(+ filters: z.infer<typeof queryModel>["filters"],+ view: ViewDeclarationType,+ ) {+ for (const filter of filters) {+ // Validate filters on dimension fields+ if (filter.column in view.dimensions) {+ const dimension = view.dimensions[filter.column];++ // Array fields (like tags) validation+ if (dimension.type === "string[]") {+ if (filter.type === "string") {+ throw new InvalidRequestError(+ `Invalid filter for field '${filter.column}': Array fields require type 'arrayOptions', not 'string'. ` ++ `Use operators like 'any of', 'all of', or 'none of' with an array of values.`,+ );+ }++ // Additional validation: ensure value is array for arrayOptions+ if (filter.type === "arrayOptions" && !Array.isArray(filter.value)) {+ throw new InvalidRequestError(+ `Invalid filter for field '${filter.column}': arrayOptions type requires an array of values, not '${typeof filter.value}'.`,+ );+ }+ }+ }++ // Special validation for metadata filters+ else if (filter.column === "metadata") {+ if (filter.type !== "stringObject") {+ throw new InvalidRequestError(+ `Invalid filter for field 'metadata': Metadata filters require type 'stringObject' with a 'key' property, not '${filter.type}'. ` ++ `Example: {"column": "metadata", "type": "stringObject", "key": "environment", "operator": "=", "value": "production"}`,+ );+ }++ // Validate stringObject has required key+ if (filter.type === "stringObject" && !("key" in filter)) {+ throw new InvalidRequestError(+ `Invalid filter for field 'metadata': stringObject type requires a 'key' property to specify which metadata field to filter on. ` ++ `Example: {"column": "metadata", "type": "stringObject", "key": "environment", "operator": "=", "value": "production"}`,+ );+ }++ // Validate stringObject value type+ if (+ filter.type === "stringObject" &&+ typeof filter.value !== "string"+ ) {+ throw new InvalidRequestError(+ // @ts-ignore+ `Invalid filter for field 'metadata': stringObject type requires a string value, not '${typeof filter.value}'.`,+ );+ }+ }+ }+ }+private mapFilters(filters: z.infer<typeof queryModel>["filters"],view: ViewDeclarationType,) {+ // Validate all filters before processing+ this.validateFilters(filters, view);+// Transform our filters to match the column mapping format expected by createFilterFromFilterStateconst columnMappings = filters.map((filter) => {let clickhouseSelect: string;