Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comprehensive test and support for timestamp function #257

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@ func TestQueriesAgainstOldEngine(t *testing.T) {
http_requests_total{pod="nginx-2"} 1`,
query: "atanh(http_requests_total)",
},
{
name: "timestamp",
load: `load 30s
http_requests_total{pod="nginx-1"} 0
http_requests_total{pod="nginx-2"} 1`,
query: "timestamp(http_requests_total)",
},
{
name: "rad",
load: `load 30s
Expand Down
12 changes: 12 additions & 0 deletions execution/function/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@
F: math.Pi,
}
},
"timestamp": func(f FunctionArgs) promql.Sample {
if len(f.Samples) == 0 {
return InvalidSample
}
result := promql.Sample{}
for _, sample := range f.Samples {
if sample.H == nil { // only consider float samples
result.Points = append(result.Points, promql.Point{T: sample.T, V: float64(sample.T) / 1000})

Check failure on line 130 in execution/function/functions.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

result.Points undefined (type promql.Sample has no field or method Points)

Check failure on line 130 in execution/function/functions.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

Point not declared by package promql

Check failure on line 130 in execution/function/functions.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

result.Points undefined (type promql.Sample has no field or method Points)

Check failure on line 130 in execution/function/functions.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

result.Points undefined (type promql.Sample has no field or method Points)

Check failure on line 130 in execution/function/functions.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

Point not declared by package promql

Check failure on line 130 in execution/function/functions.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

result.Points undefined (type promql.Sample has no field or method Points)

Check failure on line 130 in execution/function/functions.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

result.Points undefined (type promql.Sample has no field or method Points) (typecheck)

Check failure on line 130 in execution/function/functions.go

View workflow job for this annotation

GitHub Actions / Run tests

result.Points undefined (type promql.Sample has no field or method Points)

Check failure on line 130 in execution/function/functions.go

View workflow job for this annotation

GitHub Actions / Run tests

result.Points undefined (type promql.Sample has no field or method Points)

Check failure on line 130 in execution/function/functions.go

View workflow job for this annotation

GitHub Actions / Run tests

undefined: promql.Point

Check failure on line 130 in execution/function/functions.go

View workflow job for this annotation

GitHub Actions / Run tests --tags=stringlabels

result.Points undefined (type promql.Sample has no field or method Points)

Check failure on line 130 in execution/function/functions.go

View workflow job for this annotation

GitHub Actions / Run tests --tags=stringlabels

result.Points undefined (type promql.Sample has no field or method Points)

Check failure on line 130 in execution/function/functions.go

View workflow job for this annotation

GitHub Actions / Run tests --tags=stringlabels

undefined: promql.Point
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, this cannot be implemented as a function i think, it will return the step timestamp for nested functions for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes you are right . I tried to push down the timestamp function into execution/scan/vector_selector.go as mentioned

}
}
return result
},
"sum_over_time": func(f FunctionArgs) promql.Sample {
if len(f.Samples) == 0 {
return InvalidSample
Expand Down