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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
chore: add query step intervals in response meta (#9954)
Srikanth Chekuri0f62a04f9235
diff --git a/docs/api/openapi.yml b/docs/api/openapi.ymlindex eade525528..f99519ce37 100644--- a/docs/api/openapi.yml+++ b/docs/api/openapi.yml@@ -3267,6 +3267,11 @@ components:rowsScanned:minimum: 0type: integer+ stepIntervals:+ additionalProperties:+ minimum: 0+ type: integer+ type: objecttype: objectQuerybuildertypesv5Filter:properties:@@ -3282,8 +3287,6 @@ components:type: objectQuerybuildertypesv5OrderByKey:properties:- '-':- $ref: '#/components/schemas/TelemetrytypesJSONDataType'description:type: stringfieldContext:@@ -3338,8 +3341,6 @@ components:status:type: stringtype: object- TelemetrytypesJSONDataType:- type: objectTypesChangePasswordRequest:properties:newPassword:diff --git a/ee/query-service/app/api/queryrange.go b/ee/query-service/app/api/queryrange.goindex 698ac2d91c..3357692cd3 100644--- a/ee/query-service/app/api/queryrange.go+++ b/ee/query-service/app/api/queryrange.go@@ -257,18 +257,20 @@ func (aH *APIHandler) queryRangeV5(rw http.ResponseWriter, req *http.Request) {results = append(results, item)}+ // Build step intervals from the anomaly query+ stepIntervals := make(map[string]uint64)+ if anomalyQuery.StepInterval.Duration > 0 {+ stepIntervals[anomalyQuery.Name] = uint64(anomalyQuery.StepInterval.Duration.Seconds())+ }+finalResp := &qbtypes.QueryRangeResponse{Type: queryRangeRequest.RequestType,- Data: struct {- Results []any `json:"results"`- }{+ Data: qbtypes.QueryData{Results: results,},- Meta: struct {- RowsScanned uint64 `json:"rowsScanned"`- BytesScanned uint64 `json:"bytesScanned"`- DurationMS uint64 `json:"durationMs"`- }{},+ Meta: qbtypes.ExecStats{+ StepIntervals: stepIntervals,+ },}render.Success(rw, http.StatusOK, finalResp)diff --git a/pkg/querier/querier.go b/pkg/querier/querier.goindex 66b2f279c5..b4eb4a229a 100644--- a/pkg/querier/querier.go+++ b/pkg/querier/querier.go@@ -593,19 +593,31 @@ func (q *querier) run(return nil, err}+ // attach step interval to metadata so client can make informed decisions, ex: width of the bar+ // or go to related logs/traces from a point in line/bar chart with correct time range+ stepIntervals := make(map[string]uint64, len(steps))+ for name, step := range steps {+ stepIntervals[name] = uint64(step.Duration.Seconds())+ }+ for _, query := range req.CompositeQuery.Queries {+ if query.Type == qbtypes.QueryTypeFormula {+ if formula, ok := query.Spec.(qbtypes.QueryBuilderFormula); ok {+ formulaStepMs := q.calculateFormulaStep(formula.Expression, req)+ stepIntervals[formula.Name] = uint64(formulaStepMs / 1000) // convert ms to seconds+ }+ }+ }+resp := &qbtypes.QueryRangeResponse{Type: req.RequestType,Data: qbtypes.QueryData{Results: maps.Values(processedResults),},- Meta: struct {- RowsScanned uint64 `json:"rowsScanned"`- BytesScanned uint64 `json:"bytesScanned"`- DurationMS uint64 `json:"durationMs"`- }{- RowsScanned: stats.RowsScanned,- BytesScanned: stats.BytesScanned,- DurationMS: stats.DurationMS,+ Meta: qbtypes.ExecStats{+ RowsScanned: stats.RowsScanned,+ BytesScanned: stats.BytesScanned,+ DurationMS: stats.DurationMS,+ StepIntervals: stepIntervals,},}diff --git a/pkg/types/querybuildertypes/querybuildertypesv5/query.go b/pkg/types/querybuildertypes/querybuildertypesv5/query.goindex 0fe2f15143..ba0434ca49 100644--- a/pkg/types/querybuildertypes/querybuildertypesv5/query.go+++ b/pkg/types/querybuildertypes/querybuildertypesv5/query.go@@ -23,9 +23,10 @@ type Result struct {}type ExecStats struct {- RowsScanned uint64 `json:"rowsScanned"`- BytesScanned uint64 `json:"bytesScanned"`- DurationMS uint64 `json:"durationMs"`+ RowsScanned uint64 `json:"rowsScanned"`+ BytesScanned uint64 `json:"bytesScanned"`+ DurationMS uint64 `json:"durationMs"`+ StepIntervals map[string]uint64 `json:"stepIntervals,omitempty"`}type TimeRange struct{ From, To uint64 } // ms since epoch