Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for derivative() CQ's with empty buckets #3383

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions services/continuous_querier/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,14 @@ func (s *Service) ExecuteContinuousQuery(dbi *meta.DatabaseInfo, cqi *meta.Conti
}

// Calculate and set the time range for the query.
startTime := now.Round(interval)
if startTime.UnixNano() > now.UnixNano() {
startTime = startTime.Add(-interval)
startTime := now.Add(-interval * time.Duration(s.Config.RecomputePreviousN))

recomputeNoOlderThan := time.Duration(s.Config.RecomputeNoOlderThan)
if now.Sub(startTime) > recomputeNoOlderThan {
startTime = now.Add(-recomputeNoOlderThan)
}

if err := cq.q.SetTimeRange(startTime, startTime.Add(interval)); err != nil {
if err := cq.q.SetTimeRange(startTime, now); err != nil {
s.Logger.Printf("error setting time range: %s\n", err)
}

Expand All @@ -240,27 +242,6 @@ func (s *Service) ExecuteContinuousQuery(dbi *meta.DatabaseInfo, cqi *meta.Conti
return err
}

recomputeNoOlderThan := time.Duration(s.Config.RecomputeNoOlderThan)

for i := 0; i < s.Config.RecomputePreviousN; i++ {
// if we're already more time past the previous window than we're going to look back, stop
if now.Sub(startTime) > recomputeNoOlderThan {
return nil
}
newStartTime := startTime.Add(-interval)

if err := cq.q.SetTimeRange(newStartTime, startTime); err != nil {
s.Logger.Printf("error setting time range: %s\n", err)
return err
}

if err := s.runContinuousQueryAndWriteResult(cq); err != nil {
s.Logger.Printf("error during recompute previous: %s. running: %s\n", err, cq.q.String())
return err
}

startTime = newStartTime
}
return nil
}

Expand Down