-
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
Stats: Make defensive copy and set end time for ViewData when export. #512
Stats: Make defensive copy and set end time for ViewData when export. #512
Conversation
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.
Thanks for doing this!
@@ -145,3 +142,11 @@ def get_metrics(self, timestamp): | |||
metric = metric_utils.view_data_to_metric(vd, timestamp) | |||
if metric is not None: | |||
yield metric | |||
|
|||
# TODO(issue #470): remove this method once we export immutable stats. | |||
def copy_view_data(self, view_data): |
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: Not sure how others feel about naming, but maybe something like finalize_view_data
to make it clear that this also modifies it? Not super important given that this should go away soon.
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.
Actually this method does both - it first makes a copy of the original view_data
and then sets the end_time
of that copy. I renamed it to copy_and_finalize_view_data
to make this clear.
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 with a test. Thanks for moving fast on this @songy23.
@@ -378,3 +378,20 @@ def test_export(self): | |||
measure_to_view_map._registered_measures = {} | |||
measure_to_view_map.export(view_data) | |||
self.assertTrue(True) | |||
|
|||
def test_export_duplicates_viewdata(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.
This test might be too close to just asserting the implementation to be useful, you may want to change it to e.g. check that the end timestamp is getting set correctly. Since this PR is a bugfix I think it ought to include a test to prevent a regression, up to you whether you think this does that.
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.
Thanks for adding the test, I've fixed a failure with mock and made it test if end_time
is properly updated.
f582a14
to
f1ce0af
Compare
f1ce0af
to
13f724b
Compare
Thanks for the review! |
Updates #509.