Skip to content

Commit

Permalink
Short circuit on valid step size
Browse files Browse the repository at this point in the history
  • Loading branch information
benclive committed Apr 19, 2024
1 parent 20180b3 commit a0b6949
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/pattern/drain/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ func (c Chunk) ForRange(start, end, step model.Time) []logproto.PatternSample {
return c.Samples[i].Timestamp >= end
})
}
if step == timeResolution {
return c.Samples[lo:hi]
}

// Re-scale samples into step-sized buckets
currentStep := truncateTimestamp(c.Samples[lo].Timestamp, step)
outputSamples := []logproto.PatternSample{
aggregatedSamples := []logproto.PatternSample{
{
Timestamp: currentStep,
Value: 0,
Expand All @@ -79,17 +82,17 @@ func (c Chunk) ForRange(start, end, step model.Time) []logproto.PatternSample {
if sample.Timestamp >= currentStep+step {
stepForSample := truncateTimestamp(sample.Timestamp, step)
for i := currentStep + step; i <= stepForSample; i += step {
outputSamples = append(outputSamples, logproto.PatternSample{
aggregatedSamples = append(aggregatedSamples, logproto.PatternSample{
Timestamp: i,
Value: 0,
})
}
currentStep = stepForSample
}
outputSamples[len(outputSamples)-1].Value += sample.Value
aggregatedSamples[len(aggregatedSamples)-1].Value += sample.Value
}

return outputSamples
return aggregatedSamples
}

func (c *Chunks) Add(ts model.Time) {
Expand Down

0 comments on commit a0b6949

Please sign in to comment.