Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Metrics point conversion#467

Merged
c24t merged 21 commits intocensus-instrumentation:masterfrom
c24t:metrics-point-conversion
Jan 25, 2019
Merged

Metrics point conversion#467
c24t merged 21 commits intocensus-instrumentation:masterfrom
c24t:metrics-point-conversion

Conversation

@c24t
Copy link
Copy Markdown
Member

@c24t c24t commented Jan 24, 2019

This PR adds to_point functions to each stats aggregation data class and fixes an unrelated bug in DistributionAggregationData exemplars. This lays the groundwork for MetricProducers, which will let us convert stats data into metrics data models for export.

Addresses #335.


# If there is no histogram, do not record an exemplar
self._exemplars = \
{bucket: exemplars} if len(self._bounds) > 0 else None
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm assuming this is a typo and this line should have been indented. Score one for semantic whitespace detractors.

self.assertEqual(sum_of_sqd_deviations,
dist_agg_data.sum_of_sqd_deviations)
self.assertEqual([1, 1, 1], dist_agg_data.counts_per_bucket)
self.assertEqual([exemplar_1, exemplar_2], dist_agg_data.exemplars[2])
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was asserting the wrong behavior: attaching all exemplars to the last bucket.

cls.CUMULATIVE_DOUBLE: float,
cls.CUMULATIVE_DISTRIBUTION: ValueDistribution,
cls.SUMMARY: ValueSummary
cls.GAUGE_INT64: value.ValueLong,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have a general question, would this hurt the performance as we need to build the dictionary each time the function gets called (and optimization doesn't work since cls is parameterized)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's a good point. I assumed it was cheap enough to do that I didn't bother trying to optimize it, but this will get called on every stat conversion and there's no reason not to move this up into the class. Changed in 7a43a50.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It'd be interesting to profile the library on an example app to see what other easy improvements we could make.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good point. We should have some level of performance test in the CI.

:param timestamp: The time to report the point as having been recorded.

:rtype: :class: `opencensus.metrics.export.point.Point`
:return: a :class: `opencensus.metrics.export.value.ValueLong`-valued
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor nit -> s/ValueLong/ValueDouble

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, fixed in 9bbc9f4.

self.assertEqual(converted_point.value.sum, 4950)
self.assertEqual(converted_point.value.sum_of_squared_deviation,
80850.0)
self.assertEqual([bb.count for bb in converted_point.value.buckets],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please add check for bucket_options?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good call, f9d64fb.

Copy link
Copy Markdown
Member

@mayurkale22 mayurkale22 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 2 minor nits.

Copy link
Copy Markdown
Contributor

@reyang reyang left a comment

Choose a reason for hiding this comment

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

LGTM.

@c24t c24t merged commit 99346e5 into census-instrumentation:master Jan 25, 2019
@c24t c24t deleted the metrics-point-conversion branch January 25, 2019 17:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants