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

feat: add metricscardinality to heartbeat #1235

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alexcastilio
Copy link
Contributor

@alexcastilio alexcastilio commented Jan 16, 2025

Description

Add metricscardinality to heartbeat. This will give visibility on the number of time series being exposed by retina.

Related Issue

#1040

Checklist

  • I have read the contributing documentation.
  • I signed and signed-off the commits (git commit -S -s ...). See this documentation on signing commits.
  • I have correctly attributed the author(s) of the code.
  • I have tested the changes locally.
  • I have followed the project's style guidelines.
  • I have updated the documentation, if necessary.
  • I have added tests, if applicable.

Screenshots (if applicable) or Testing Completed

Metrics exported with heartbeat:
image

Additional Notes

Metrics of types histogram and summary expose multiple time series during a scrape. Code is counting according to number of time series exposed at /metrics endpoint.

Ref:
https://prometheus.io/docs/concepts/metric_types/#histogram
https://prometheus.io/docs/concepts/metric_types/#summary


Please refer to the CONTRIBUTING.md file for more information on how to contribute to this project.

@alexcastilio alexcastilio force-pushed the alexcastilio/metrics-cardinality-prometheus branch 2 times, most recently from 4efa73e to b0beff5 Compare January 17, 2025 13:55
@alexcastilio alexcastilio marked this pull request as ready for review January 17, 2025 14:04
@alexcastilio alexcastilio requested a review from a team as a code owner January 17, 2025 14:04
Signed-off-by: Alex Castilio dos Santos <[email protected]>
@alexcastilio alexcastilio force-pushed the alexcastilio/metrics-cardinality-prometheus branch from b0beff5 to 7af0632 Compare January 17, 2025 18:48
@matmerr
Copy link
Member

matmerr commented Jan 17, 2025

I think a simpler solution may just be to enumerate over the metrics and take the length of the metrics slice

https://gist.github.com/matmerr/f2e31d9be0b5af0eec750fa944edc617#file-counter_test-go-L58


// count all metrics and combination of labels currently exposed on
// prometheus endpoint
metrics, err := registry.Gather()
if err != nil {
	fmt.Println("Error gathering metrics: ", err)
}

// count all metrics exposed for each metric
var metriccounter int
for _, metric := range metrics {
	metriccounter += len(metric.Metric)
}

where the metrics endpoint looks like this:

image

and in stdout we see the same, total metrics is 4
image

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