From 8ae5836537b055576195414176ef736111a685bb Mon Sep 17 00:00:00 2001 From: Lukasz Mierzwa Date: Wed, 13 Apr 2022 17:49:06 +0100 Subject: [PATCH] Correctly set timestamps in promql/series --- docs/changelog.md | 7 +++++++ internal/checks/promql_series.go | 7 +++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 6e6c6394..15171518 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,12 @@ # Changelog +## v0.17.6 + +### Fixed + +- Fixed false positive reports from `promql/series` check when running + `pint watch`. + ## v0.17.5 ### Added diff --git a/internal/checks/promql_series.go b/internal/checks/promql_series.go index 1372f476..31172798 100644 --- a/internal/checks/promql_series.go +++ b/internal/checks/promql_series.go @@ -216,7 +216,7 @@ func (c SeriesCheck) Check(ctx context.Context, rule parser.Rule, entries []disc // 4. If foo was ALWAYS there but it's NO LONGER there -> BUG if len(trs.ranges) == 1 && - !trs.oldest().After(trs.until.Add(rangeLookback-1).Add(rangeStep)) && + !trs.oldest().After(trs.from.Add(rangeStep)) && trs.newest().Before(trs.until.Add(rangeStep*-1)) { problems = append(problems, Problem{ Fragment: bareSelector.String(), @@ -355,7 +355,6 @@ func (c SeriesCheck) instantSeriesCount(ctx context.Context, query string) (int, } func (c SeriesCheck) serieTimeRanges(ctx context.Context, query string, lookback, step time.Duration) (tr *timeRanges, err error) { - now := time.Now() qr, err := c.prom.RangeQuery(ctx, query, lookback, step) if err != nil { return nil, err @@ -363,8 +362,8 @@ func (c SeriesCheck) serieTimeRanges(ctx context.Context, query string, lookback tr = &timeRanges{ uri: qr.URI, - from: now.Add(lookback * -1), - until: now, + from: qr.Start, + until: qr.End, step: step, } var ts time.Time