-
Notifications
You must be signed in to change notification settings - Fork 818
Let clients of DropwizardExports handle validation errors #1354
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
Conversation
I like the idea of making this customizable. Instead of subclassing, I'd prefer to use a callback and builder - would that work? |
Yes - that is a much cleaner solution. I have updated the PR to allow the callback to decide if an exception is to be suppressed. |
56cb38c
to
292a1bc
Compare
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.
great
@@ -179,7 +202,7 @@ MetricSnapshot fromTimer(String dropwizardName, Timer timer) { | |||
} | |||
|
|||
/** Export a Meter as a prometheus COUNTER. */ | |||
MetricSnapshot fromMeter(String dropwizardName, Meter meter) { | |||
protected MetricSnapshot fromMeter(String dropwizardName, Meter meter) { |
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.
should not have to be protected
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.
Fixed.
* @param metricFilter a custom metric filter. | ||
* @param labelMapper a labelMapper to use to map labels. | ||
*/ | ||
public DropwizardExports( |
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.
this ctor should be private - i.e. you have to use the builder for that
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.
Fixed.
In the current form, if e.g. a Counter contains invalid data the entire `collect` calls fails with InvalidArgumentException. In large applications, it may be preferable to gracefully degrade the available metrics and report the failure via e.g. logging. This change allows that by letting the user add a exception handler. This allows the user to inspect the exception, and the metric name it was associated with, and decide if the exception should be suppressed or not. Metrics for which exceptions were suppressed will be absent from the collection. Signed-off-by: Anders Månsson <[email protected]>
A possible solution for #1353.
In the current form, if e.g. a Counter contains invalid data the entire
collect
calls fails with InvalidArgumentException.In large applications, it may be preferable to gracefully degrade the available metrics and report the failure via e.g. logging. This change allows just that - by changing the access modifiers to the
fromXYZ
methods subclasses can now handle the errors.Finally, to allow for skipping of invalid metrics, we follow the example in
fromGauge
to interpret the meaning of a returned null to be that the metric should be skipped.