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

Stats: Make defensive copy and set end time for ViewData when export. #512

Merged
merged 5 commits into from
Feb 21, 2019

Conversation

songy23
Copy link
Contributor

@songy23 songy23 commented Feb 21, 2019

Updates #509.

@songy23 songy23 requested a review from c24t February 21, 2019 00:54
@songy23 songy23 requested review from reyang and a team as code owners February 21, 2019 00:54
Copy link
Contributor

@colincadams colincadams left a 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):
Copy link
Contributor

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.

Copy link
Contributor Author

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.

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 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):
Copy link
Member

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.

Copy link
Contributor Author

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.

@songy23
Copy link
Contributor Author

songy23 commented Feb 21, 2019

Thanks for the review!

@songy23 songy23 merged commit ed82f64 into census-instrumentation:master Feb 21, 2019
@songy23 songy23 deleted the copy-view-data branch February 21, 2019 23:16
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.

5 participants