Skip to content

Commit

Permalink
Copy in quantile functions instead of exporting them from Prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
jhesketh committed Nov 18, 2024
1 parent b471cea commit 78fc811
Show file tree
Hide file tree
Showing 4 changed files with 472 additions and 43 deletions.
16 changes: 8 additions & 8 deletions pkg/streamingpromql/operators/functions/histograms.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type groupWithLabels struct {

type bucketGroup struct {
groupedMetricName string // The metric name of the group. May be duplicate between groups.
pointBuckets []promql.Buckets // Buckets for the grouped series at each step
pointBuckets []buckets // Buckets for the grouped series at each step
nativeHistograms *[]promql.HPoint // Histograms should only ever exist once per group
remainingSeriesCount uint // The number of series remaining before this group is fully collated.
}
Expand Down Expand Up @@ -131,7 +131,7 @@ func (h *HistogramFunctionOverInstantVector) SeriesMetadata(ctx context.Context)
g.labels = lb.Labels()
g.group = bucketGroupPool.Get()
g.group.groupedMetricName = series.Labels.Get(labels.MetricName)
g.group.pointBuckets = make([]promql.Buckets, h.timeRange.StepCount)
g.group.pointBuckets = make([]buckets, h.timeRange.StepCount)
groups[string(b)] = g
}
g.group.remainingSeriesCount++
Expand All @@ -150,7 +150,7 @@ func (h *HistogramFunctionOverInstantVector) SeriesMetadata(ctx context.Context)
g.labels = lb.Labels()
g.group = bucketGroupPool.Get()
g.group.groupedMetricName = series.Labels.Get(labels.MetricName)
g.group.pointBuckets = make([]promql.Buckets, h.timeRange.StepCount)
g.group.pointBuckets = make([]buckets, h.timeRange.StepCount)
groups[string(b)] = g
}
g.group.remainingSeriesCount++
Expand Down Expand Up @@ -242,9 +242,9 @@ func (h *HistogramFunctionOverInstantVector) saveFloatsToGroup(fPoints []promql.
pointIdx := h.timeRange.PointIndex(f.T)
g.pointBuckets[pointIdx] = append(
g.pointBuckets[pointIdx],
promql.Bucket{
UpperBound: upperBound,
Count: f.F,
bucket{
upperBound: upperBound,
count: f.F,
},
)
}
Expand Down Expand Up @@ -307,7 +307,7 @@ func (h *HistogramFunctionOverInstantVector) computeOutputSeriesForGroup(_ conte
}

if len(g.pointBuckets[pointIdx]) > 0 {
res, forcedMonotonicity, _ := promql.BucketQuantile(ph, g.pointBuckets[pointIdx])
res, forcedMonotonicity, _ := bucketQuantile(ph, g.pointBuckets[pointIdx])
floatPoints = append(floatPoints, promql.FPoint{
T: h.timeRange.IndexTime(int64(pointIdx)),
F: res,
Expand All @@ -323,7 +323,7 @@ func (h *HistogramFunctionOverInstantVector) computeOutputSeriesForGroup(_ conte
}

if currentHPoint != nil && h.timeRange.PointIndex(currentHPoint.T) == int64(pointIdx) {
res := promql.HistogramQuantile(ph, currentHPoint.H)
res := histogramQuantile(ph, currentHPoint.H)

floatPoints = append(floatPoints, promql.FPoint{
T: h.timeRange.IndexTime(int64(pointIdx)),
Expand Down
Loading

0 comments on commit 78fc811

Please sign in to comment.