-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mimir query engine: add support for
count_over_time
, `present_over_…
…time` and `last_over_time` (#8925) * Add `count_over_time` function * Add feature toggle for functions * Add `present_over_time` function * Add `last_over_time` function * Add changelog entry * Update CLI flag description and enable by default
- Loading branch information
1 parent
37ce120
commit b5098c5
Showing
17 changed files
with
266 additions
and
102 deletions.
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
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
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,59 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
package functions | ||
|
||
import ( | ||
"github.com/prometheus/prometheus/model/histogram" | ||
|
||
"github.com/grafana/mimir/pkg/streamingpromql/types" | ||
) | ||
|
||
var CountOverTime = FunctionOverRangeVector{ | ||
SeriesMetadataFunc: DropSeriesName, | ||
StepFunc: countOverTime, | ||
} | ||
|
||
func countOverTime(step types.RangeVectorStepData, _ float64, fPoints *types.FPointRingBuffer, hPoints *types.HPointRingBuffer, _ EmitAnnotationFunc) (f float64, hasFloat bool, h *histogram.FloatHistogram, err error) { | ||
fPointCount := fPoints.CountAtOrBefore(step.RangeEnd) | ||
hPointCount := hPoints.CountAtOrBefore(step.RangeEnd) | ||
|
||
if fPointCount == 0 && hPointCount == 0 { | ||
return 0, false, nil, nil | ||
} | ||
|
||
return float64(fPointCount + hPointCount), true, nil, nil | ||
} | ||
|
||
var LastOverTime = FunctionOverRangeVector{ | ||
SeriesMetadataFunc: PassthroughSeriesMetadata, | ||
StepFunc: lastOverTime, | ||
} | ||
|
||
func lastOverTime(step types.RangeVectorStepData, _ float64, fPoints *types.FPointRingBuffer, hPoints *types.HPointRingBuffer, _ EmitAnnotationFunc) (f float64, hasFloat bool, h *histogram.FloatHistogram, err error) { | ||
lastFloat, floatAvailable := fPoints.LastAtOrBefore(step.RangeEnd) | ||
lastHistogram, histogramAvailable := hPoints.LastAtOrBefore(step.RangeEnd) | ||
|
||
if !floatAvailable && !histogramAvailable { | ||
return 0, false, nil, nil | ||
} | ||
|
||
if floatAvailable && (!histogramAvailable || lastFloat.T > lastHistogram.T) { | ||
return lastFloat.F, true, nil, nil | ||
} | ||
|
||
// We must make a copy of the histogram before returning it, as the ring buffer may reuse the FloatHistogram instance on subsequent steps. | ||
return 0, false, lastHistogram.H.Copy(), nil | ||
} | ||
|
||
var PresentOverTime = FunctionOverRangeVector{ | ||
SeriesMetadataFunc: DropSeriesName, | ||
StepFunc: presentOverTime, | ||
} | ||
|
||
func presentOverTime(step types.RangeVectorStepData, _ float64, fPoints *types.FPointRingBuffer, hPoints *types.HPointRingBuffer, _ EmitAnnotationFunc) (f float64, hasFloat bool, h *histogram.FloatHistogram, err error) { | ||
if fPoints.AnyAtOrBefore(step.RangeEnd) || hPoints.AnyAtOrBefore(step.RangeEnd) { | ||
return 1, true, nil, nil | ||
} | ||
|
||
return 0, false, nil, 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
Oops, something went wrong.