feat(telemetrymeter): step interval improvements

This commit is contained in:
vikrantgupta25 2025-07-31 19:02:21 +05:30
parent 27305e6cc6
commit 712fa3e041
No known key found for this signature in database
GPG Key ID: F8440BDE36411E79
3 changed files with 20 additions and 5 deletions

View File

@ -173,7 +173,7 @@ func (q *querier) QueryRange(ctx context.Context, orgID valuer.UUID, req *qbtype
event.GroupByApplied = len(spec.GroupBy) > 0
if spec.Signal == telemetrytypes.SignalMeter {
spec.StepInterval = qbtypes.Step{Duration: time.Hour * 24}
spec.StepInterval = qbtypes.Step{Duration: time.Second * time.Duration(querybuilder.RecommendedStepIntervalForMeter(req.Start, req.End))}
} else {
if spec.StepInterval.Seconds() == 0 {
spec.StepInterval = qbtypes.Step{

View File

@ -126,13 +126,11 @@ func newProvider(
)
// Create meter statement builder
meterFieldMapper := telemetrymetrics.NewFieldMapper()
meterConditionBuilder := telemetrymetrics.NewConditionBuilder(metricFieldMapper)
meterStmtBuilder := telemetrymeter.NewMeterQueryStatementBuilder(
settings,
telemetryMetadataStore,
meterFieldMapper,
meterConditionBuilder,
metricFieldMapper,
metricConditionBuilder,
)
// Create bucket cache

View File

@ -61,6 +61,23 @@ func MinAllowedStepInterval(start, end uint64) uint64 {
return step - step%5
}
func RecommendedStepIntervalForMeter(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 day as this is our granularity
if step < 86400 {
return 86400
}
// return the nearest lower multiple of 86400 ( 1 day )
recommended := step - step%86400
return recommended
}
func RecommendedStepIntervalForMetric(start, end uint64) uint64 {
start = ToNanoSecs(start)
end = ToNanoSecs(end)