Skip to content

Commit d4aec07

Browse files
committed
Implement timestamp() for native histograms
Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
1 parent 4e2b57a commit d4aec07

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

engine/engine_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,16 @@ or
23302330
end: time.UnixMilli(160000),
23312331
step: time.Minute + 16*time.Second,
23322332
},
2333+
{
2334+
name: "native histogram timestamp",
2335+
load: `load 2m
2336+
http_request_duration_seconds{pod="nginx-1"} {{schema:0 count:3 sum:14.00 buckets:[1 2]}}+{{schema:0 count:4 buckets:[1 2 1]}}x20
2337+
http_request_duration_seconds{pod="nginx-2"} 1x10 {{schema:0 count:2 sum:14.00 buckets:[2]}}+{{schema:0 count:6 buckets:[2 2 2]}}x10`,
2338+
query: `--timestamp(-{__name__="http_request_duration_seconds"} offset 8s)`,
2339+
start: time.UnixMilli(0),
2340+
end: time.UnixMilli(300000),
2341+
step: 15 * time.Second,
2342+
},
23332343
}
23342344

23352345
disableOptimizerOpts := []bool{true, false}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
go test fuzz v1
2+
int64(111)
3+
uint32(0)
4+
uint32(151)
5+
uint32(3)
6+
int8(0)
7+
int8(0)
8+
uint64(15)
9+
uint64(0)
10+
uint64(106)

execution/function/operator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewFunctionOperator(funcExpr *logicalplan.FunctionCall, nextOps []model.Vec
2727
case "scalar":
2828
return newScalarOperator(model.NewVectorPoolWithSize(stepsBatch, 1), nextOps[0], opts), nil
2929
case "timestamp":
30-
return newTimestampOperator(nextOps[0], opts), nil
30+
return newTimestampOperator(model.NewVectorPool(stepsBatch), nextOps[0], opts), nil
3131
case "label_join", "label_replace":
3232
return newRelabelOperator(nextOps[0], funcExpr, opts), nil
3333
case "absent":

execution/function/timestamp.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ import (
1616
)
1717

1818
type timestampOperator struct {
19+
pool *model.VectorPool
1920
next model.VectorOperator
2021

2122
series []labels.Labels
2223
once sync.Once
2324
}
2425

25-
func newTimestampOperator(next model.VectorOperator, opts *query.Options) model.VectorOperator {
26+
func newTimestampOperator(pool *model.VectorPool, next model.VectorOperator, opts *query.Options) model.VectorOperator {
2627
oper := &timestampOperator{
28+
pool: pool,
2729
next: next,
2830
}
2931
return telemetry.NewOperator(telemetry.NewTelemetry(oper, opts), oper)
@@ -65,7 +67,7 @@ func (o *timestampOperator) loadSeries(ctx context.Context) error {
6567
}
6668

6769
func (o *timestampOperator) GetPool() *model.VectorPool {
68-
return o.next.GetPool()
70+
return o.pool
6971
}
7072

7173
func (o *timestampOperator) Next(ctx context.Context) ([]model.StepVector, error) {
@@ -76,13 +78,29 @@ func (o *timestampOperator) Next(ctx context.Context) ([]model.StepVector, error
7678
}
7779

7880
in, err := o.next.Next(ctx)
81+
7982
if err != nil {
8083
return nil, err
8184
}
85+
if len(in) == 0 {
86+
return nil, nil
87+
}
88+
result := o.pool.GetVectorBatch()
8289
for _, vector := range in {
90+
out := o.pool.GetStepVector(vector.T)
91+
value := float64(vector.T / 1000)
92+
8393
for i := range vector.Samples {
84-
vector.Samples[i] = float64(vector.T / 1000)
94+
out.AppendSample(o.pool, vector.SampleIDs[i], value)
8595
}
96+
for i := range vector.Histograms {
97+
out.AppendSample(o.pool, vector.HistogramIDs[i], value)
98+
}
99+
100+
result = append(result, out)
101+
o.next.GetPool().PutStepVector(vector)
86102
}
87-
return in, nil
103+
104+
o.next.GetPool().PutVectors(in)
105+
return result, nil
88106
}

0 commit comments

Comments
 (0)