-
Notifications
You must be signed in to change notification settings - Fork 532
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
MQE: Add support for count aggregation #9342
Merged
jhesketh
merged 9 commits into
grafana:main
from
jhesketh:jhesketh/mqe-aggregations-count
Sep 20, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aa94b1c
MQE: Add support for count aggregation
jhesketh 692a93c
Extend tests
jhesketh 25b0dc5
Enable upstream count tests
jhesketh fd87451
Update CHANGELOG
jhesketh 27e65af
Fix linting
jhesketh 07a0957
Remove floatPresent
jhesketh fa757ef
Rename floatValues
jhesketh daace0c
Add extra test
jhesketh 2f0c7de
Updated unsupported functions
jhesketh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Provenance-includes-location: https://github.com/prometheus/prometheus/blob/main/promql/engine.go | ||
// Provenance-includes-license: Apache-2.0 | ||
// Provenance-includes-copyright: The Prometheus Authors | ||
|
||
package aggregations | ||
|
||
import ( | ||
"github.com/prometheus/prometheus/promql" | ||
|
||
"github.com/grafana/mimir/pkg/streamingpromql/functions" | ||
"github.com/grafana/mimir/pkg/streamingpromql/limiting" | ||
"github.com/grafana/mimir/pkg/streamingpromql/types" | ||
) | ||
|
||
type CountAggregationGroup struct { | ||
values []float64 | ||
} | ||
|
||
func (g *CountAggregationGroup) AccumulateSeries(data types.InstantVectorSeriesData, timeRange types.QueryTimeRange, memoryConsumptionTracker *limiting.MemoryConsumptionTracker, _ functions.EmitAnnotationFunc) error { | ||
if (len(data.Floats) > 0 || len(data.Histograms) > 0) && g.values == nil { | ||
var err error | ||
// First series with values for this group, populate it. | ||
g.values, err = types.Float64SlicePool.Get(timeRange.StepCount, memoryConsumptionTracker) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
g.values = g.values[:timeRange.StepCount] | ||
} | ||
|
||
for _, p := range data.Floats { | ||
idx := (p.T - timeRange.StartT) / timeRange.IntervalMs | ||
g.values[idx]++ | ||
} | ||
|
||
for _, p := range data.Histograms { | ||
idx := (p.T - timeRange.StartT) / timeRange.IntervalMs | ||
g.values[idx]++ | ||
} | ||
|
||
types.PutInstantVectorSeriesData(data, memoryConsumptionTracker) | ||
return nil | ||
} | ||
|
||
func (g *CountAggregationGroup) ComputeOutputSeries(timeRange types.QueryTimeRange, memoryConsumptionTracker *limiting.MemoryConsumptionTracker) (types.InstantVectorSeriesData, bool, error) { | ||
floatPointCount := 0 | ||
for _, fv := range g.values { | ||
if fv > 0 { | ||
floatPointCount++ | ||
} | ||
} | ||
var floatPoints []promql.FPoint | ||
var err error | ||
if floatPointCount > 0 { | ||
floatPoints, err = types.FPointSlicePool.Get(floatPointCount, memoryConsumptionTracker) | ||
if err != nil { | ||
return types.InstantVectorSeriesData{}, false, err | ||
} | ||
|
||
for i, fv := range g.values { | ||
if fv > 0 { | ||
jhesketh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t := timeRange.StartT + int64(i)*timeRange.IntervalMs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar suggestion to above, similarly could be a separate PR: we could add a method to |
||
floatPoints = append(floatPoints, promql.FPoint{T: t, F: fv}) | ||
} | ||
} | ||
} | ||
|
||
types.Float64SlicePool.Put(g.values, memoryConsumptionTracker) | ||
|
||
return types.InstantVectorSeriesData{Floats: floatPoints}, false, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be something for a follow up PR, but we have expressions like this in lots of places - what do you think about adding this calculation as a helper method on
QueryTimeRange
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, will add it later