-
Notifications
You must be signed in to change notification settings - Fork 250
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
Metrics: Add Value, Point and Summary #337
Conversation
opencensus/metrics/export/summary.py
Outdated
|
||
|
||
class Summary(object): | ||
"""Implementation of the Distribution as a summary of observations. |
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.
s/Distribution/Summary
opencensus/metrics/export/summary.py
Outdated
:param sum_data: the sum of the population values. | ||
|
||
:type snapshot: Snapshot | ||
:param snapshot: the bucket boundaries of a histogram. |
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.
snapshot
is not histogram buckets.
opencensus/metrics/export/summary.py
Outdated
|
||
@property | ||
def snapshot(self): | ||
"""Returns the bucket boundaries of a histogram.""" |
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.
ditto
opencensus/metrics/export/summary.py
Outdated
def __init__(self, percentile, value): | ||
|
||
if not 0 < percentile <= 100.0: | ||
raise ValueError("percentile must be in the interval (0.0, 100.0)") |
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.
nit: s/(0.0, 100.0)/(0.0, 100.0]
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.
I took a first pass and left some superficial comments, let me compare to the java client and take another look.
opencensus/metrics/export/summary.py
Outdated
def __init__(self, percentile, value): | ||
|
||
if not 0 < percentile <= 100.0: | ||
raise ValueError("percentile must be in the interval (0.0, 100.0)") |
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.
Might want this to be (0.0, 100.0]
to match the check (and the spec).
opencensus/metrics/export/summary.py
Outdated
|
||
self._percentile = percentile | ||
|
||
if value <= 0: |
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.
0 seems ok here, s/<=/<
.
opencensus/metrics/export/summary.py
Outdated
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): |
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.
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.
opencensus/metrics/export/summary.py
Outdated
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') |
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.
But it's ok to have a null count
and non-null sum_data
?
opencensus/metrics/export/summary.py
Outdated
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: |
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.
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' |
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.
Might want to freeze this to avoid flaky tests if something does go wrong parsing a particular time.
opencensus/metrics/export/value.py
Outdated
return ValueSummary(value) | ||
|
||
@property | ||
def get_value(self): |
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.
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): |
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.
Why the caps here?
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.
LGTM
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.
LGTM!
This PR is based on #335