You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No input validation on MetricFamily classes resulting in confusing errors #362
I am not too familiar with the code but I wonder if it would somehow be possible to merge the metrics_core.py code with metrics.py. Or is there a reason that, for example, a Gauge does not use the GaugeMetricFamily internally (or vice versa)?
I understand the stack trace is correct, but why would there be no input validation on the add_metric? Is there a situation where other value types would be correct?
In my case the value came from a mongo database which had an incomplete record resulting in None. Tracking it down required me to monkeypatch the code, because this error only occurs on runtime with no useful information about the cause.
I would propose either some validation on the add_metric or additional output when raising errors from sample_line so these runtime only errors can be tracked down without firing up a debugger.
Is there a situation where other value types would be correct?
You might have a object that looks like a float.
But if you're going to cast to a float in the end anyhow, would it be a good solution to do the casting sooner? That would immediately solve the issue and wouldn't require any double work.
additional output when raising errors from sample_line
Do you want to send a PR?
That depends on the amount of work required, but if it's not too invasive, sure :)
I've noticed you're not using the logging module anywhere, I think that could be a good solution for adding additional debug information. I expect that there are several other similar error cases that could benefit from this debug information as well (for example, with recursive imports it can be hard to track down the cause of duplicate measurement names).
Adding some logging and documentation on how to enable/disable the logging within your application? Generally I do something along these lines to make it easy to enable/disable logging within a module:
Activity
brian-brazil commentedon Jan 4, 2019
If you're using the MetricFamilys it's presumed you know what you're doing, and the stack trace is correct as those can't be converted to floats.
wolph commentedon Jan 4, 2019
I understand the stack trace is correct, but why would there be no input validation on the
add_metric? Is there a situation where other value types would be correct?In my case the value came from a mongo database which had an incomplete record resulting in
None. Tracking it down required me to monkeypatch the code, because this error only occurs on runtime with no useful information about the cause.I would propose either some validation on the
add_metricor additional output when raising errors fromsample_lineso these runtime only errors can be tracked down without firing up a debugger.brian-brazil commentedon Jan 4, 2019
You might have a object that looks like a float.
That'd be doing double the validation.
Do you want to send a PR?
wolph commentedon Jan 4, 2019
But if you're going to cast to a float in the end anyhow, would it be a good solution to do the casting sooner? That would immediately solve the issue and wouldn't require any double work.
That depends on the amount of work required, but if it's not too invasive, sure :)
I've noticed you're not using the
loggingmodule anywhere, I think that could be a good solution for adding additional debug information. I expect that there are several other similar error cases that could benefit from this debug information as well (for example, with recursive imports it can be hard to track down the cause of duplicate measurement names).brian-brazil commentedon Jan 4, 2019
That may be a bit of a layering violation, different exposition formats use different types.
wolph commentedon Jan 4, 2019
Ok, so should I go for the logging solution?
Adding some logging and documentation on how to enable/disable the logging within your application? Generally I do something along these lines to make it easy to enable/disable logging within a module:
Would that be acceptable?
brian-brazil commentedon Jan 7, 2019
I was thinking more having a better exception in cases like this