mirror of
https://github.com/prometheus/prometheus
synced 2024-12-26 08:33:06 +00:00
promql: export Sample
This commit is contained in:
parent
65581a3d46
commit
c5f225b920
@ -108,20 +108,20 @@ func (s Point) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// sample is a single sample belonging to a COWMetric.
|
||||
type sample struct {
|
||||
// Sample is a single sample belonging to a metric.
|
||||
type Sample struct {
|
||||
Point
|
||||
|
||||
Metric labels.Labels
|
||||
}
|
||||
|
||||
func (s sample) String() string {
|
||||
func (s Sample) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Vector is basically only an alias for model.Samples, but the
|
||||
// contract is that in a Vector, all Samples have the same timestamp.
|
||||
type Vector []sample
|
||||
type Vector []Sample
|
||||
|
||||
func (vec Vector) String() string {
|
||||
entries := make([]string, len(vec))
|
||||
@ -804,7 +804,7 @@ func (ev *evaluator) VectorSelector(node *VectorSelector) Vector {
|
||||
}
|
||||
}
|
||||
|
||||
vec = append(vec, sample{
|
||||
vec = append(vec, Sample{
|
||||
Metric: node.series[i].Labels(),
|
||||
Point: Point{V: v, T: ev.Timestamp},
|
||||
})
|
||||
@ -936,7 +936,7 @@ func (ev *evaluator) VectorBinop(op itemType, lhs, rhs Vector, matching *VectorM
|
||||
}
|
||||
|
||||
// All samples from the rhs hashed by the matching label/values.
|
||||
rightSigs := map[uint64]sample{}
|
||||
rightSigs := map[uint64]Sample{}
|
||||
|
||||
// Add all rhs samples to a map so we can easily find matches later.
|
||||
for _, rs := range rhs {
|
||||
@ -1002,7 +1002,7 @@ func (ev *evaluator) VectorBinop(op itemType, lhs, rhs Vector, matching *VectorM
|
||||
insertedSigs[insertSig] = struct{}{}
|
||||
}
|
||||
|
||||
result = append(result, sample{
|
||||
result = append(result, Sample{
|
||||
Metric: metric,
|
||||
Point: Point{V: value, T: ev.Timestamp},
|
||||
})
|
||||
@ -1310,13 +1310,13 @@ func (ev *evaluator) aggregation(op itemType, grouping []string, without bool, k
|
||||
}
|
||||
if op == itemTopK || op == itemQuantile {
|
||||
result[groupingKey].heap = make(VectorByValueHeap, 0, k)
|
||||
heap.Push(&result[groupingKey].heap, &sample{
|
||||
heap.Push(&result[groupingKey].heap, &Sample{
|
||||
Point: Point{V: s.V},
|
||||
Metric: s.Metric,
|
||||
})
|
||||
} else if op == itemBottomK {
|
||||
result[groupingKey].reverseHeap = make(VectorByReverseValueHeap, 0, k)
|
||||
heap.Push(&result[groupingKey].reverseHeap, &sample{
|
||||
heap.Push(&result[groupingKey].reverseHeap, &Sample{
|
||||
Point: Point{V: s.V},
|
||||
Metric: s.Metric,
|
||||
})
|
||||
@ -1359,7 +1359,7 @@ func (ev *evaluator) aggregation(op itemType, grouping []string, without bool, k
|
||||
if int64(len(group.heap)) == k {
|
||||
heap.Pop(&group.heap)
|
||||
}
|
||||
heap.Push(&group.heap, &sample{
|
||||
heap.Push(&group.heap, &Sample{
|
||||
Point: Point{V: s.V},
|
||||
Metric: s.Metric,
|
||||
})
|
||||
@ -1370,7 +1370,7 @@ func (ev *evaluator) aggregation(op itemType, grouping []string, without bool, k
|
||||
if int64(len(group.reverseHeap)) == k {
|
||||
heap.Pop(&group.reverseHeap)
|
||||
}
|
||||
heap.Push(&group.reverseHeap, &sample{
|
||||
heap.Push(&group.reverseHeap, &Sample{
|
||||
Point: Point{V: s.V},
|
||||
Metric: s.Metric,
|
||||
})
|
||||
@ -1407,7 +1407,7 @@ func (ev *evaluator) aggregation(op itemType, grouping []string, without bool, k
|
||||
// The heap keeps the lowest value on top, so reverse it.
|
||||
sort.Sort(sort.Reverse(aggr.heap))
|
||||
for _, v := range aggr.heap {
|
||||
resultVector = append(resultVector, sample{
|
||||
resultVector = append(resultVector, Sample{
|
||||
Metric: v.Metric,
|
||||
Point: Point{V: v.V, T: ev.Timestamp},
|
||||
})
|
||||
@ -1418,7 +1418,7 @@ func (ev *evaluator) aggregation(op itemType, grouping []string, without bool, k
|
||||
// The heap keeps the lowest value on top, so reverse it.
|
||||
sort.Sort(sort.Reverse(aggr.reverseHeap))
|
||||
for _, v := range aggr.reverseHeap {
|
||||
resultVector = append(resultVector, sample{
|
||||
resultVector = append(resultVector, Sample{
|
||||
Metric: v.Metric,
|
||||
Point: Point{V: v.V, T: ev.Timestamp},
|
||||
})
|
||||
@ -1432,7 +1432,7 @@ func (ev *evaluator) aggregation(op itemType, grouping []string, without bool, k
|
||||
// For other aggregations, we already have the right value.
|
||||
}
|
||||
|
||||
resultVector = append(resultVector, sample{
|
||||
resultVector = append(resultVector, Sample{
|
||||
Metric: aggr.labels,
|
||||
Point: Point{V: aggr.value, T: ev.Timestamp},
|
||||
})
|
||||
|
@ -116,7 +116,7 @@ func extrapolatedRate(ev *evaluator, arg Expr, isCounter bool, isRate bool) Valu
|
||||
resultValue = resultValue / 1000 / ms.Range.Seconds()
|
||||
}
|
||||
|
||||
resultVector = append(resultVector, sample{
|
||||
resultVector = append(resultVector, Sample{
|
||||
Metric: copyLabels(samples.Metric, false),
|
||||
Point: Point{V: resultValue, T: ev.Timestamp},
|
||||
})
|
||||
@ -179,7 +179,7 @@ func instantValue(ev *evaluator, arg Expr, isRate bool) Value {
|
||||
resultValue /= float64(sampledInterval) / 1000
|
||||
}
|
||||
|
||||
resultVector = append(resultVector, sample{
|
||||
resultVector = append(resultVector, Sample{
|
||||
Metric: copyLabels(samples.Metric, false),
|
||||
Point: Point{V: resultValue, T: ev.Timestamp},
|
||||
})
|
||||
@ -272,7 +272,7 @@ func funcHoltWinters(ev *evaluator, args Expressions) Value {
|
||||
s[i] = x + y
|
||||
}
|
||||
|
||||
resultVector = append(resultVector, sample{
|
||||
resultVector = append(resultVector, Sample{
|
||||
Metric: copyLabels(samples.Metric, false),
|
||||
Point: Point{V: s[len(s)-1], T: ev.Timestamp}, // The last value in the Vector is the smoothed result.
|
||||
})
|
||||
@ -413,7 +413,7 @@ func aggrOverTime(ev *evaluator, args Expressions, aggrFn func([]Point) float64)
|
||||
continue
|
||||
}
|
||||
|
||||
resultVector = append(resultVector, sample{
|
||||
resultVector = append(resultVector, Sample{
|
||||
Metric: copyLabels(el.Metric, false),
|
||||
Point: Point{V: aggrFn(el.Points), T: ev.Timestamp},
|
||||
})
|
||||
@ -496,9 +496,9 @@ func funcQuantileOverTime(ev *evaluator, args Expressions) Value {
|
||||
el.Metric = copyLabels(el.Metric, false)
|
||||
values := make(VectorByValueHeap, 0, len(el.Points))
|
||||
for _, v := range el.Points {
|
||||
values = append(values, sample{Point: Point{V: v.V}})
|
||||
values = append(values, Sample{Point: Point{V: v.V}})
|
||||
}
|
||||
resultVector = append(resultVector, sample{
|
||||
resultVector = append(resultVector, Sample{
|
||||
Metric: el.Metric,
|
||||
Point: Point{V: quantile(q, values), T: ev.Timestamp},
|
||||
})
|
||||
@ -559,7 +559,7 @@ func funcAbsent(ev *evaluator, args Expressions) Value {
|
||||
}
|
||||
}
|
||||
return Vector{
|
||||
sample{
|
||||
Sample{
|
||||
Metric: labels.New(m...),
|
||||
Point: Point{V: 1, T: ev.Timestamp},
|
||||
},
|
||||
@ -663,7 +663,7 @@ func funcDeriv(ev *evaluator, args Expressions) Value {
|
||||
continue
|
||||
}
|
||||
slope, _ := linearRegression(samples.Points, 0)
|
||||
resultSample := sample{
|
||||
resultSample := Sample{
|
||||
Metric: copyLabels(samples.Metric, false),
|
||||
Point: Point{V: slope, T: ev.Timestamp},
|
||||
}
|
||||
@ -687,7 +687,7 @@ func funcPredictLinear(ev *evaluator, args Expressions) Value {
|
||||
}
|
||||
slope, intercept := linearRegression(samples.Points, ev.Timestamp)
|
||||
|
||||
resultVector = append(resultVector, sample{
|
||||
resultVector = append(resultVector, Sample{
|
||||
Metric: copyLabels(samples.Metric, false),
|
||||
Point: Point{V: slope*duration + intercept, T: ev.Timestamp},
|
||||
})
|
||||
@ -727,7 +727,7 @@ func funcHistogramQuantile(ev *evaluator, args Expressions) Value {
|
||||
}
|
||||
|
||||
for _, mb := range signatureToMetricWithBuckets {
|
||||
outVec = append(outVec, sample{
|
||||
outVec = append(outVec, Sample{
|
||||
Metric: mb.metric,
|
||||
Point: Point{V: bucketQuantile(q, mb.buckets), T: ev.Timestamp},
|
||||
})
|
||||
@ -752,7 +752,7 @@ func funcResets(ev *evaluator, args Expressions) Value {
|
||||
prev = current
|
||||
}
|
||||
|
||||
out = append(out, sample{
|
||||
out = append(out, Sample{
|
||||
Metric: copyLabels(samples.Metric, false),
|
||||
Point: Point{V: float64(resets), T: ev.Timestamp},
|
||||
})
|
||||
@ -776,7 +776,7 @@ func funcChanges(ev *evaluator, args Expressions) Value {
|
||||
prev = current
|
||||
}
|
||||
|
||||
out = append(out, sample{
|
||||
out = append(out, Sample{
|
||||
Metric: copyLabels(samples.Metric, false),
|
||||
Point: Point{V: float64(changes), T: ev.Timestamp},
|
||||
})
|
||||
@ -832,7 +832,7 @@ func funcLabelReplace(ev *evaluator, args Expressions) Value {
|
||||
// === Vector(s Scalar) Vector ===
|
||||
func funcVector(ev *evaluator, args Expressions) Value {
|
||||
return Vector{
|
||||
sample{
|
||||
Sample{
|
||||
Metric: labels.Labels{},
|
||||
Point: Point{V: ev.evalFloat(args[0]), T: ev.Timestamp},
|
||||
},
|
||||
@ -844,7 +844,7 @@ func dateWrapper(ev *evaluator, args Expressions, f func(time.Time) float64) Val
|
||||
var v Vector
|
||||
if len(args) == 0 {
|
||||
v = Vector{
|
||||
sample{
|
||||
Sample{
|
||||
Metric: labels.Labels{},
|
||||
Point: Point{V: float64(ev.Timestamp) / 1000},
|
||||
},
|
||||
@ -1220,7 +1220,7 @@ func (s VectorByValueHeap) Swap(i, j int) {
|
||||
}
|
||||
|
||||
func (s *VectorByValueHeap) Push(x interface{}) {
|
||||
*s = append(*s, x.(sample))
|
||||
*s = append(*s, x.(Sample))
|
||||
}
|
||||
|
||||
func (s *VectorByValueHeap) Pop() interface{} {
|
||||
@ -1249,7 +1249,7 @@ func (s VectorByReverseValueHeap) Swap(i, j int) {
|
||||
}
|
||||
|
||||
func (s *VectorByReverseValueHeap) Push(x interface{}) {
|
||||
*s = append(*s, x.(sample))
|
||||
*s = append(*s, x.(Sample))
|
||||
}
|
||||
|
||||
func (s *VectorByReverseValueHeap) Pop() interface{} {
|
||||
|
Loading…
Reference in New Issue
Block a user