-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: expose Desc error through public Err() method #1902
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
base: main
Are you sure you want to change the base?
Conversation
Adds a public Err() method to Desc type to allow users to check if an error occurred during descriptor construction. Previously, the error field was private and inaccessible. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Yuri Nikolic <[email protected]>
489f84c to
5ffa5cc
Compare
bboreham
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks!
Hm, I don't see why not, other than opening a potentially bad pattern where users check for error always whenever desc is created, where collector checks it too 🤔 It's not necessarily bad, but perhaps users would think they HAVE to check it now on every NewDesc. At minimum a code comment would be nice that this is not mandatory to check this.
It would be much more practical if the Prometheus API exposed a method such as Desc.Err(), which would return any error that occurred during the creation of the Desc. That's the motivation for the present PR.
Can you elaborate on what "practical" means? Do you have some exact use case you got blocked on, without this PR?
Hi @bwplotka,
This is why we need a way to validate the configuration earlier. |
Signed-off-by: Yuri Nikolic <[email protected]>
A comment has been added in ec2ca21 |
Adds a public
Err()method toDesctype to allow users to check if an error occurred during descriptor construction. Previously, the error field was private and inaccessible.Our use case is as follows:
Desc.Collect()method, we dynamically create aMetricusingNewConstMetric()to report the current value.However, if the
Descwas constructed with an error (for example, due to an invalid label name), that error remains hidden until the collector’sCollect()method is invoked for the first time.It would be much more practical if the Prometheus API exposed a method such as
Desc.Err(), which would return any error that occurred during the creation of theDesc. That's the motivation for the present PR.Signed-off-by: Yuri Nikolic [email protected]