-
Notifications
You must be signed in to change notification settings - Fork 801
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
Eagerly convert value to float in *MetricFamily.add_metric() #527
Comments
That sounds reasonable to me. I don't see how it'd be breaking, you're only changing when we're erroring on bad data. |
It’d only break if someone was creating a metric but never turning it into
a string. Probably unlikely, but maybe someone is holding them in memory
and not outputting them? Seems a bit unlikely.
…On Thu, 12 Mar 2020 at 22:46, Brian Brazil ***@***.***> wrote:
That sounds reasonable to me. I don't see how it'd be breaking, you're
only changing when we're erroring on bad data.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#527 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAZYOLVOHAXZYMRVE6BX2DRHDDPRANCNFSM4LGJ4OGA>
.
|
They're useless without being output at some point, and even if it did break someone I'd be okay with that. |
Having a quick look into this, looks like a common pinchpoint we could add
this check would be the Sample constructor.
But it's a namedtuple. In python3 there's typing.NamedTuple, but that
doesn't verify types at runtime.
Looks like it's not easy to override the constructor of a namedtuple,
except by subclassing or having a factory function wrapper. Subclassing
looks like a better win, preserving the Sample function as a type (which
some folks might depend on), as written here:
https://stackoverflow.com/a/16721002/171898
…On Thu, 12 Mar 2020 at 22:52, Brian Brazil ***@***.***> wrote:
They're useless without being output at some point, and even if it did
break someone I'd be okay with that.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#527 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAZYOO7EABQZQ4NWYNKKDLRHDEH7ANCNFSM4LGJ4OGA>
.
|
Could always write out the entire generated code body of the namedtuple and
then change the constructor too! Not ideal for sure.
…On Thu, 19 Mar 2020 at 20:42, Mark Hansen ***@***.***> wrote:
Having a quick look into this, looks like a common pinchpoint we could add
this check would be the Sample constructor.
But it's a namedtuple. In python3 there's typing.NamedTuple, but that
doesn't verify types at runtime.
Looks like it's not easy to override the constructor of a namedtuple,
except by subclassing or having a factory function wrapper. Subclassing
looks like a better win, preserving the Sample function as a type (which
some folks might depend on), as written here:
https://stackoverflow.com/a/16721002/171898
On Thu, 12 Mar 2020 at 22:52, Brian Brazil ***@***.***>
wrote:
> They're useless without being output at some point, and even if it did
> break someone I'd be okay with that.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#527 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAAZYOO7EABQZQ4NWYNKKDLRHDEH7ANCNFSM4LGJ4OGA>
> .
>
|
The quickest win is probably the add_metric function itself, but wrapping the constructor should also work. |
Yeah add_metric would be quick... but looks like there are 8
implementations of add_metric which makes me feel a bit awkward. Good
fallback option, trying to wrap the constructor now.
…On Thu, 19 Mar 2020 at 20:58, Brian Brazil ***@***.***> wrote:
The quickest win is probably the add_metric function itself, but wrapping
the constructor should also work.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#527 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAZYOJAXY25KKYQYSAHCGLRIHUD3ANCNFSM4LGJ4OGA>
.
|
mhansen
added a commit
to mhansen/client_python
that referenced
this issue
Mar 19, 2020
Addresses prometheus#527. There's a test setting GaugeHistogramMetricFamily.gsum_value = None, so I've preserved that behaviour, by not appending and crashing if gsum_value is None. I was a bit unsure about this bit: assert isinstance(exception.args[-1], core.Metric) I'm not sure what exception.args[-1] is, the python docs for TypeError and ValueError don't explain. I've removed the assertion.
mhansen
added a commit
to mhansen/client_python
that referenced
this issue
Mar 19, 2020
…s#527.There's a test setting GaugeHistogramMetricFamily.gsum_value = None, soI've preserved that behaviour, by not appending and crashing if gsum_valueis None.I was a bit unsure about this bit: assert isinstance(exception.args[-1], core.Metric)I'm not sure what exception.args[-1] is, the python docs for TypeError and ValueErrordon't explain. I've removed the assertion.
mhansen
added a commit
to mhansen/client_python
that referenced
this issue
Mar 19, 2020
Addresses prometheus#527. There's a test setting GaugeHistogramMetricFamily.gsum_value = None, so I've preserved that behaviour, by not appending and crashing if gsum_value is None. I was a bit unsure about this bit: assert isinstance(exception.args[-1], core.Metric) I'm not sure what exception.args[-1] is, the python docs for TypeError and ValueErrordon't explain. I've removed the assertion. Signed-off-by: Mark Hansen <mark@markhansen.co.nz>
mhansen
added a commit
to mhansen/client_python
that referenced
this issue
Mar 20, 2020
Addresses prometheus#527. There's a test setting GaugeHistogramMetricFamily.gsum_value = None, so I've preserved that behaviour, by not appending and crashing if gsum_value is None. I was a bit unsure about this bit: assert isinstance(exception.args[-1], core.Metric) I'm not sure what exception.args[-1] is, the python docs for TypeError and ValueErrordon't explain. I've removed the assertion. Signed-off-by: Mark Hansen <mark@markhansen.co.nz>
mhansen
added a commit
to mhansen/client_python
that referenced
this issue
Mar 21, 2020
Addresses prometheus#527. There's a test setting GaugeHistogramMetricFamily.gsum_value = None, so I've preserved that behaviour, by not appending and crashing if gsum_value is None. I was a bit unsure about this bit: assert isinstance(exception.args[-1], core.Metric) I'm not sure what exception.args[-1] is, the python docs for TypeError and ValueErrordon't explain. I've removed the assertion. Signed-off-by: Mark Hansen <mark@markhansen.co.nz>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there, an experience report and improvement suggestion.
I have a pretty simple exporter which queries a backend URL for JSON, grabs the JSON, stuffs it into prometheus metric families, which it then yields.
Sometimes it errors with stacktraces only when the request is finishing, with a stack traces that points at
finish_request
rather than the code that added the bad float:I've hit this kind of bug a few times in different exporters (I guess it's to be expected to get type errors in Python sometimes).
How about eagerly converting the value passed to
add_metric
to a float? Then the stack trace would point at the exact cause.This might be a breaking change - that'd be a reasonable reason to reject this. But any code doing this will likely fail soon after, as soon as an attempt is made to serialize the metric, so maybe it'd be worth the change for better debuggability? What do you think?
The text was updated successfully, but these errors were encountered: