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

Conversation

nishchay-veer
Copy link
Contributor

According to my understanding of the codebase, promql.Point is not defined in the Prometheus Go client library. Here's the definition of promql.Point that needs to be added in value.go file:
type Point struct {
T int64
V float64
}
also we can add a list of all the Points. It then loops over all the filtered samples and appends a promql.Point struct to its Points field with its timestamp and value (converted to seconds).
Resolve #206

@nishchay-veer
Copy link
Contributor Author

for adding Points slice we can update the Sample struct by adding a new Points field to it
type Sample struct { T int64 F float64 H *histogram.FloatHistogram Points []Point Metric labels.Labels}

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})
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

@@ -165,35 +187,38 @@ func (o *vectorSelector) loadSeries(ctx context.Context) error {
}

// TODO(fpetkovski): Add max samples limit.
func selectPoint(it *storage.MemoizedSeriesIterator, ts, lookbackDelta, offset int64) (int64, float64, *histogram.FloatHistogram, bool, error) {
// To push down the timestamp function into this file and store the timestamp in the value for each series, you can modify the selectPoint function.
func selectPoint(it *storage.MemoizedSeriesIterator, ts, lookbackDelta, offset int64) (point, bool, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

My suggestion would be to roll back the changes and use a bool flag here to indicate whether to return the timestamp as the point value. Then for the case chunkenc.ValFloat case in the switch statement we can return t as the point value instead of v.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it possible to return the timestamp as the point value incase chunkenc.ValFloatwithout the need to set a boolean flag for it? This would allow us to handle non-histogram data directly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, the return types would remain as they are. The idea is to use a bool as an argument to the function in order to decide whether the chunkenc.ValFloat case would return t or v.

I guess we would need to do the same for histograms, based on this boolean we would either return the histogram itself or t as the float64 return value. If I'm not mistaken, the rest of the operator code would remain unchanged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I got the idea behind it !

@@ -49,6 +49,12 @@ type vectorSelector struct {
numShards int
}

type point struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we still need this new struct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well I made this just to have a good relation between timestamp and values in our data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what changes do we need now ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for timestamp function
3 participants