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
fix(meter): custom step intervals for meter aggregations (#10255)
Vikrant Guptae699ad812218
diff --git a/frontend/src/container/MeterExplorer/Breakdown/graphs.ts b/frontend/src/container/MeterExplorer/Breakdown/graphs.tsindex 2f027a8922..e00df49fb0 100644--- a/frontend/src/container/MeterExplorer/Breakdown/graphs.ts+++ b/frontend/src/container/MeterExplorer/Breakdown/graphs.ts@@ -103,7 +103,7 @@ export const getTotalLogSizeWidgetData = (): Widgets =>queryName: 'A',reduceTo: ReduceOperators.SUM,spaceAggregation: 'sum',- stepInterval: 60,+ stepInterval: null,timeAggregation: 'increase',},],@@ -140,7 +140,7 @@ export const getTotalTraceSizeWidgetData = (): Widgets =>queryName: 'A',reduceTo: ReduceOperators.SUM,spaceAggregation: 'sum',- stepInterval: 60,+ stepInterval: null,timeAggregation: 'increase',},],@@ -177,7 +177,7 @@ export const getTotalMetricDatapointCountWidgetData = (): Widgets =>queryName: 'A',reduceTo: ReduceOperators.SUM,spaceAggregation: 'sum',- stepInterval: 60,+ stepInterval: null,timeAggregation: 'increase',},],@@ -214,7 +214,7 @@ export const getLogCountWidgetData = (): Widgets =>queryName: 'A',reduceTo: ReduceOperators.AVG,spaceAggregation: 'sum',- stepInterval: 60,+ stepInterval: null,timeAggregation: 'increase',},],@@ -251,7 +251,7 @@ export const getLogSizeWidgetData = (): Widgets =>queryName: 'A',reduceTo: ReduceOperators.AVG,spaceAggregation: 'sum',- stepInterval: 60,+ stepInterval: null,timeAggregation: 'increase',},],@@ -288,7 +288,7 @@ export const getSpanCountWidgetData = (): Widgets =>queryName: 'A',reduceTo: ReduceOperators.AVG,spaceAggregation: 'sum',- stepInterval: 60,+ stepInterval: null,timeAggregation: 'increase',},],@@ -325,7 +325,7 @@ export const getSpanSizeWidgetData = (): Widgets =>queryName: 'A',reduceTo: ReduceOperators.AVG,spaceAggregation: 'sum',- stepInterval: 60,+ stepInterval: null,timeAggregation: 'increase',},],@@ -362,7 +362,7 @@ export const getMetricCountWidgetData = (): Widgets =>queryName: 'A',reduceTo: ReduceOperators.AVG,spaceAggregation: 'sum',- stepInterval: 60,+ stepInterval: null,timeAggregation: 'increase',},],diff --git a/pkg/querier/querier.go b/pkg/querier/querier.goindex b4eb4a229a..59db225442 100644--- a/pkg/querier/querier.go+++ b/pkg/querier/querier.go@@ -208,7 +208,16 @@ func (q *querier) QueryRange(ctx context.Context, orgID valuer.UUID, req *qbtypeevent.GroupByApplied = len(spec.GroupBy) > 0if spec.Source == telemetrytypes.SourceMeter {- spec.StepInterval = qbtypes.Step{Duration: time.Second * time.Duration(querybuilder.RecommendedStepIntervalForMeter(req.Start, req.End))}+ if spec.StepInterval.Seconds() == 0 {+ spec.StepInterval = qbtypes.Step{Duration: time.Second * time.Duration(querybuilder.RecommendedStepIntervalForMeter(req.Start, req.End))}+ }++ if spec.StepInterval.Seconds() < float64(querybuilder.MinAllowedStepIntervalForMeter(req.Start, req.End)) {+ newStep := qbtypes.Step{+ Duration: time.Second * time.Duration(querybuilder.MinAllowedStepIntervalForMeter(req.Start, req.End)),+ }+ spec.StepInterval = newStep+ }} else {if spec.StepInterval.Seconds() == 0 {spec.StepInterval = qbtypes.Step{diff --git a/pkg/querybuilder/time.go b/pkg/querybuilder/time.goindex afb0d8f598..1073b8e6a9 100644--- a/pkg/querybuilder/time.go+++ b/pkg/querybuilder/time.go@@ -89,6 +89,23 @@ func RecommendedStepIntervalForMeter(start, end uint64) uint64 {return recommended}+func MinAllowedStepIntervalForMeter(start, end uint64) uint64 {+ start = ToNanoSecs(start)+ end = ToNanoSecs(end)++ step := (end - start) / RecommendedNumberOfPoints / 1e9++ // for meter queries the minimum step interval allowed is 1 hour as this is our granularity+ if step < 3600 {+ return 3600+ }++ // return the nearest lower multiple of 3600 ( 1 hour )+ minAllowed := step - step%3600++ return minAllowed+}+func RecommendedStepIntervalForMetric(start, end uint64) uint64 {start = ToNanoSecs(start)end = ToNanoSecs(end)