From ec34acd6bcda1d04827bb4874c65464e5b84a401 Mon Sep 17 00:00:00 2001 From: Martin Disibio Date: Thu, 7 Sep 2023 13:45:30 -0400 Subject: [PATCH 1/3] Return an error from metrics summary api if the time range exceeds the available data --- modules/generator/processor/localblocks/processor.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/generator/processor/localblocks/processor.go b/modules/generator/processor/localblocks/processor.go index 0b39b605761..c7a5c6e3e48 100644 --- a/modules/generator/processor/localblocks/processor.go +++ b/modules/generator/processor/localblocks/processor.go @@ -25,6 +25,8 @@ import ( "github.com/pkg/errors" ) +const timeBuffer = 5 * time.Minute + type Processor struct { tenant string Cfg Config @@ -267,6 +269,13 @@ func (p *Processor) GetMetrics(ctx context.Context, req *tempopb.SpanMetricsRequ endNano = uint64(time.Unix(int64(req.End), 0).UnixNano()) ) + if startNano > 0 && endNano > 0 { + cutoff := time.Now().Add(-p.Cfg.CompleteBlockTimeout).Add(-timeBuffer) + if startNano < uint64(cutoff.UnixNano()) { + return nil, fmt.Errorf("time range exceeds the limit of last %v", p.Cfg.CompleteBlockTimeout) + } + } + // Blocks to check blocks := make([]common.BackendBlock, 0, 1+len(p.walBlocks)+len(p.completeBlocks)) if p.headBlock != nil { From 2f4b9c33036503eea971ee0cd134d649fa6d88de Mon Sep 17 00:00:00 2001 From: Martin Disibio Date: Thu, 7 Sep 2023 14:16:25 -0400 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b07fbbe4c9..8f1946a98b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * [CHANGE] Update Go to 1.21 [#2486](https://github.com/grafana/tempo/pull/2829) (@zalegrala) * [CHANGE] Make metrics-generator ingestion slack per tenant [#2589](https://github.com/grafana/tempo/pull/2589) (@ie-pham) * [CHANGE] Moved the tempo_ingester_traces_created_total metric to be incremented when a trace is cut to the wal [#2884](https://github.com/grafana/tempo/pull/2884) (@joe-elliott) +* [CHANGE] Metrics summary API validate the requested time range [#2902](https://github.com/grafana/tempo/pull/2902) (@mdisibio) * [ENHANCEMENT] Add block indexes to vParquet2 and vParquet3 to improve trace by ID lookup [#2697](https://github.com/grafana/tempo/pull/2697) (@mdisibio) * [ENHANCEMENT] Assert ingestion rate limits as early as possible [#2640](https://github.com/grafana/tempo/pull/2703) (@mghildiy) * [ENHANCEMENT] Add several metrics-generator fields to user-configurable overrides [#2711](https://github.com/grafana/tempo/pull/2711) (@kvrhdn) From 427fd3f19895a86171b6a8652340c9e51c42a99d Mon Sep 17 00:00:00 2001 From: Martin Disibio Date: Mon, 11 Sep 2023 14:15:14 -0400 Subject: [PATCH 3/3] Small tweak to error text --- modules/generator/processor/localblocks/processor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/generator/processor/localblocks/processor.go b/modules/generator/processor/localblocks/processor.go index c7a5c6e3e48..aa12262a2d3 100644 --- a/modules/generator/processor/localblocks/processor.go +++ b/modules/generator/processor/localblocks/processor.go @@ -272,7 +272,7 @@ func (p *Processor) GetMetrics(ctx context.Context, req *tempopb.SpanMetricsRequ if startNano > 0 && endNano > 0 { cutoff := time.Now().Add(-p.Cfg.CompleteBlockTimeout).Add(-timeBuffer) if startNano < uint64(cutoff.UnixNano()) { - return nil, fmt.Errorf("time range exceeds the limit of last %v", p.Cfg.CompleteBlockTimeout) + return nil, fmt.Errorf("time range must be within last %v", p.Cfg.CompleteBlockTimeout) } }