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

Eagerly verify Sample values are float-convertible #530

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mhansen
Copy link

@mhansen mhansen commented Mar 19, 2020

Addresses #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. That meant that this test case "([('spam', 0), ('eggs', 0)], None, TypeError)" doesn't throw any more, so I've deleted the test case.

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.

Not sure if removing these assertions is a great idea - would love feedback on this.

@mhansen mhansen force-pushed the factory branch 2 times, most recently from fbe1461 to 39dc454 Compare March 19, 2020 10:55
prometheus_client/samples.py Outdated Show resolved Hide resolved
prometheus_client/samples.py Outdated Show resolved Hide resolved
tests/test_exposition.py Show resolved Hide resolved
@brian-brazil
Copy link
Contributor

I've preserved that behaviour, by not appending and crashing if gsum_value
is None.

That's the right thing to do. gsum is technically optional.

@mhansen
Copy link
Author

mhansen commented Mar 20, 2020

Thanks for the quick review. I pushed a new version, hope you don't mind me marking the comments as resolved, please reopen if any further questions on them.

@@ -32,12 +32,17 @@ def __gt__(self, other):


# Timestamp and exemplar are optional.
# Value can be an int or a float.
# Value must be a float.
Copy link
Contributor

@brian-brazil brian-brazil Mar 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is a problem, we must support ints too for OpenMetrics. If someone passes in an int, it needs to stay as an int.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a go at this, split over two commits, what do you think?

@mhansen
Copy link
Author

mhansen commented Mar 20, 2020 via email

@mhansen
Copy link
Author

mhansen commented Mar 20, 2020 via email

@brian-brazil
Copy link
Contributor

Yes, OpenMetrics has int support for that so we need it.

@mhansen
Copy link
Author

mhansen commented Mar 20, 2020 via email

@brian-brazil
Copy link
Contributor

  • is it to output openmetrics "17" when input "17"?

Yes

is it for avoiding precision issues with floats when you increment a
large float and it rounds down to the same float?

This isn't something this client does currently, for direct instrumentation everything is a float.

mhansen added 2 commits March 21, 2020 15:39
Previously, integers would be formatted the same as floats.

Openmetrics distinguishes floats and integers.

Signed-off-by: Mark Hansen <[email protected]>
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 <[email protected]>
@mhansen
Copy link
Author

mhansen commented Mar 21, 2020

Had a go at preserving integer formatting in the openmetrics exposition.

Copy link
Contributor

@brian-brazil brian-brazil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for us catching this earlier now?
If you rebase that CI failure should also go away.

sample = namedtuple('Sample', ['name', 'labels', 'value', 'timestamp', 'exemplar'])


# Wrap the namedtuple to provide eager type-checking that value is a float.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convertable to a float?

@mhansen
Copy link
Author

mhansen commented Jun 22, 2020 via email

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