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

Metrics: Add Value, Point and Summary #337

Merged

Conversation

mayurkale22
Copy link
Member

@mayurkale22 mayurkale22 commented Oct 5, 2018

This PR is based on #335



class Summary(object):
"""Implementation of the Distribution as a summary of observations.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/Distribution/Summary

:param sum_data: the sum of the population values.

:type snapshot: Snapshot
:param snapshot: the bucket boundaries of a histogram.
Copy link
Contributor

Choose a reason for hiding this comment

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

snapshot is not histogram buckets.


@property
def snapshot(self):
"""Returns the bucket boundaries of a histogram."""
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

def __init__(self, percentile, value):

if not 0 < percentile <= 100.0:
raise ValueError("percentile must be in the interval (0.0, 100.0)")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: s/(0.0, 100.0)/(0.0, 100.0]

Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

I took a first pass and left some superficial comments, let me compare to the java client and take another look.

def __init__(self, percentile, value):

if not 0 < percentile <= 100.0:
raise ValueError("percentile must be in the interval (0.0, 100.0)")
Copy link
Member

Choose a reason for hiding this comment

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

Might want this to be (0.0, 100.0] to match the check (and the spec).


self._percentile = percentile

if value <= 0:
Copy link
Member

Choose a reason for hiding this comment

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

0 seems ok here, s/<=/<.

def check_count_and_sum(count, sum_data):
if not (count is None or count >= 0):
raise ValueError('count must be non-negative')
elif not (sum_data is None or sum_data >= 0):
Copy link
Member

Choose a reason for hiding this comment

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

Nit, but you might just want if here so if the caller does handle the first error (unlikely, I know) you still check the other cases.

raise ValueError('sum_data must be non-negative')
elif count is not None and count == 0:
if not (sum_data is None or sum_data == 0):
raise ValueError('sum_data must be 0 if count is 0')
Copy link
Member

Choose a reason for hiding this comment

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

But it's ok to have a null count and non-null sum_data?

raise ValueError('count must be non-negative')
elif not (sum_data is None or sum_data >= 0):
raise ValueError('sum_data must be non-negative')
elif count is not None and count == 0:
Copy link
Member

Choose a reason for hiding this comment

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

Could just be count == 0.

def setUp(self):
self.double_value = value_module.Value.double_value(55.5)
self.long_value = value_module.Value.long_value(9876543210)
self.timestamp = datetime.utcnow().isoformat() + 'Z'
Copy link
Member

Choose a reason for hiding this comment

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

Might want to freeze this to avoid flaky tests if something does go wrong parsing a particular time.

return ValueSummary(value)

@property
def get_value(self):
Copy link
Member

Choose a reason for hiding this comment

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

Not value? I'd expect get_x to be a method, x to be a property.

self.assertIsNotNone(summary.snapshot)
self.assertIsInstance(summary.snapshot, summary_module.Snapshot)

def test_constructor_with_Negative_count(self):
Copy link
Member

Choose a reason for hiding this comment

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

Why the caps here?

Copy link
Contributor

@songy23 songy23 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

LGTM!

@mayurkale22
Copy link
Member Author

Thanks @songy23 and @c24t for reviews

@mayurkale22 mayurkale22 merged commit 1147173 into census-instrumentation:master Oct 8, 2018
@mayurkale22 mayurkale22 deleted the metrics_value_point branch October 8, 2018 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants