From 0428fa9a032ffb6bbaa120c4d1c4c4d6fbb2d7a6 Mon Sep 17 00:00:00 2001 From: Jon Kartago Lamida Date: Mon, 11 Nov 2024 02:14:17 +0800 Subject: [PATCH] Clear up comment for isCounter and isRate parameter Signed-off-by: Jon Kartago Lamida --- .../operators/functions/rate_increase.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/streamingpromql/operators/functions/rate_increase.go b/pkg/streamingpromql/operators/functions/rate_increase.go index a2a2a8ee2bb..3313930377b 100644 --- a/pkg/streamingpromql/operators/functions/rate_increase.go +++ b/pkg/streamingpromql/operators/functions/rate_increase.go @@ -35,8 +35,11 @@ var Delta = FunctionOverRangeVectorDefinition{ NeedsSeriesNamesForAnnotations: true, } -// isCounter and isRate are used to determine if the rate should be calculated -// as `rate`, `increase` or `delta. +// rate is utility function for rate/increase/delta. +// It calculates the rate (allowing for counter resets if isCounter is true for rate and increase), +// extrapolates if the first/last sample is close to the boundary, and returns +// the result as either per-second (if isRate is true) or overall (this is increase function). +// If isCounter and isRate are both false, this function will calculate the delta. func rate(isCounter, isRate bool) RangeVectorStepFunction { return func(step *types.RangeVectorStepData, rangeSeconds float64, emitAnnotation types.EmitAnnotationFunc) (float64, bool, *histogram.FloatHistogram, error) { fHead, fTail := step.Floats.UnsafePoints() @@ -71,6 +74,11 @@ func rate(isCounter, isRate bool) RangeVectorStepFunction { } } +// histogramRate is utility function for rate/increase/delta. +// It calculates the rate (allowing for counter resets if isCounter is true for rate and increase), +// extrapolates if the first/last sample is close to the boundary, and returns +// the result as either per-second (if isRate is true) or overall (this is increase function). +// If isCounter and isRate are both false, this function will calculate the delta. func histogramRate(isCounter, isRate bool, hCount int, hHead []promql.HPoint, hTail []promql.HPoint, rangeStart int64, rangeEnd int64, rangeSeconds float64, emitAnnotation types.EmitAnnotationFunc) (*histogram.FloatHistogram, error) { firstPoint := hHead[0] hHead = hHead[1:]