Skip to content

Conversation

@harry671003
Copy link
Contributor

@harry671003 harry671003 commented Jun 20, 2025

Notes

  • Implementing timestamp() for native histograms
  • Timestamp function should return a float sample with t=T, v=T/1000 for both native histograms and floats

From the docs: https://prometheus.io/docs/prometheus/latest/querying/functions/#timestamp

timestamp()
timestamp(v instant-vector) returns the timestamp of each of the samples of the given vector as the number of seconds since January 1, 1970 UTC. It acts on float and histogram samples in the same way.

@harry671003 harry671003 requested a review from fpetkovski June 20, 2025 15:45
@harry671003 harry671003 force-pushed the native_histogram_timestamp branch 2 times, most recently from 894d1c4 to 4a960b9 Compare June 20, 2025 21:59
@harry671003 harry671003 force-pushed the native_histogram_timestamp branch from 4a960b9 to 577abd2 Compare July 11, 2025 16:12
for _, vector := range in {
for i := range vector.Samples {
vector.Samples[i] = float64(vector.T / 1000)
out := o.pool.GetStepVector(vector.T)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need these changes? Can't apply the same pattern to histograms as we do for floats?

Copy link
Contributor Author

@harry671003 harry671003 Jul 11, 2025

Choose a reason for hiding this comment

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

When we have both samples and histograms in the input StepVector, we need to return a StepVector with only Samples populated.

Eg:

load 30s
  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
  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`

I'm not sure if we should do this in place.

for _, vector := range in {
		for i := range vector.Samples {
			vector.Samples[i] = float64(vector.T / 1000)
		}
		for i := range vector.Histograms {
			vector.Samples = append(vector.Samples, float64(vector.T)/1000)
			vector.SampleIDs = append(vector.SampleIDs, vector.HistogramIDs[i])
		}
		vector.Histograms = nil
		vector.HistogramIDs = nil
	}
}

@harry671003 harry671003 force-pushed the native_histogram_timestamp branch from 577abd2 to d2e54d7 Compare July 11, 2025 18:53
@harry671003 harry671003 requested a review from fpetkovski July 21, 2025 20:12
@harry671003
Copy link
Contributor Author

Could you take another look @fpetkovski?

@fpetkovski
Copy link
Collaborator

@harry671003 would you mind rebasing this so we can merge it?

Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
@harry671003 harry671003 force-pushed the native_histogram_timestamp branch from d2e54d7 to d4aec07 Compare October 24, 2025 16:29
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.

2 participants