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

SendSumOfHistograms should support native histograms #6489

Open
yeya24 opened this issue Jan 7, 2025 · 4 comments
Open

SendSumOfHistograms should support native histograms #6489

yeya24 opened this issue Jan 7, 2025 · 4 comments

Comments

@yeya24
Copy link
Contributor

yeya24 commented Jan 7, 2025

Is your feature request related to a problem? Please describe.
SendSumOfHistograms is a helper function Cortex uses to aggregate histograms from metrics registries. For example, we have certain metrics emitted from Thanos library and we aggregate them in Cortex.

data.SendSumOfHistograms(out, m.indexHeaderLoadDuration, "thanos_bucket_store_indexheader_load_duration_seconds")

With the introduction of some metrics being native histograms in Thanos, SendSumOfHistograms is not working properly as the current implementation only support legacy histograms.

See

histoBuckets := histo.GetBucket()

It ignores native histogram buckets now

	histoBuckets := histo.GetBucket()
	if len(histoBuckets) > 0 && d.buckets == nil {
		d.buckets = map[float64]uint64{}
	}

Describe the solution you'd like
Implement the sum aggregation with native histograms also

Additional context
It is unclear how would we merge legacy histograms with native histograms. Might not be a concern as we can assume in the single process it would be consistent to be either legacy or native histogram not both the same time.

@cswpy
Copy link

cswpy commented Jan 9, 2025

I'd love to take this issue but not sure whether I could take on this as a new contributor. If possible, I can spend some time familarizing myself with Cortex architecture and take a stab at this. Any tips would be appreciated :)

@yeya24
Copy link
Contributor Author

yeya24 commented Jan 9, 2025

Hi @cswpy, this specific PR doesn't need knowledge of Cortex architecture. It is more of aggregating histogram data types and handle native histograms. Some relevant knowledge are the usage of https://github.com/prometheus/client_golang and the implementation of native histogram type

@cswpy
Copy link

cswpy commented Jan 10, 2025

Thanks for the tips! I spent some time reading the Native Histogram Specs. From what I understood, since the native histograms have adaptive bucket boundaries, determined by schema, we need to calculate the upper boundaries and corresponding cumulative count, and add them to Cortex's *HistogramData (essentially convert the native histogram into conventional representation and merge into Cortex's data model). Feel free to correct me if I am wrong here.

@yeya24
Copy link
Contributor Author

yeya24 commented Jan 12, 2025

No, I think it is the opposite. HistogramData today has sample count, sum and histogram buckets and we aggregate classic histograms this way and at the end we expose HistogramData to the same format of classic histogram.

Native histogram uses a different format and our goal here is to aggregate native histograms and expose native histograms during scraping. We should extend HistogramData struct with native histogram related fields and at the end we aggregate using the new fields and expose native histogram.

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

No branches or pull requests

2 participants