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

Metrics: add MetricsProducer and convert stats#476

Merged
c24t merged 8 commits intocensus-instrumentation:masterfrom
c24t:metrics-wrap-stats
Feb 5, 2019
Merged

Metrics: add MetricsProducer and convert stats#476
c24t merged 8 commits intocensus-instrumentation:masterfrom
c24t:metrics-wrap-stats

Conversation

@c24t
Copy link
Copy Markdown
Member

@c24t c24t commented Jan 31, 2019

This PR adds a MetricProducer class and adds the plumbing to allow Stats to produce metrics, building on #469. It also fixes a bug converting DistributionAggregationDatas without bucket bounds into metrics Points.

Closes #335.



class Stats(object):
class Stats(MetricProducer):
Copy link
Copy Markdown
Member Author

@c24t c24t Jan 31, 2019

Choose a reason for hiding this comment

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

Stats here is effectively both the java library's StatsManager and MetricProducerImpl classes.

MetricProducer doesn't provide anything here other than to signify that Stats is in fact a metrics producer. It's not clear to me that this is the best approach. Our other options are (1) duck typing: remove MetricProducer and rely on get_metrics to signify that this is a metrics producer, and (2) composition: add a separate StatsMetricProducer that wraps Stats.

See PEP 3119 for a justification for using abstract base classes like these in python.

self._view_manager = ViewManager()

@property
def stats_recorder(self):
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'd understand making an attribute protected and then exposing it as a property if we were returning a copy, but we don't seem to be doing that here.

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.

c24t added 2 commits January 31, 2019 09:18
Point conversions previously failed for DistributionAggregationDatas
with histograms.
@c24t c24t force-pushed the metrics-wrap-stats branch from 9ed23b5 to 4e3b562 Compare January 31, 2019 17:18

from datetime import datetime

from opencensus.metrics.export.metric_producer import MetricProducer
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 kept this consistent with other imports, but we should decide on class- or module-level imports across the library.

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.

@c24t c24t mentioned this pull request Jan 31, 2019
with self.mp_lock:
self.metric_producers.remove(metric_producer)
except KeyError:
pass
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.

getAllMetricProducer is missing?

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.

Because the set of MPs is available as manager.metric_producers.

That said, you might want a method that gives you a copy of the set so another thread can't add/remove a MP as you're iterating through it. I don't know how much consideration to give threadsafety since most stats classes ignore it completely.

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.

I see, ok.

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.

Added in fdd002f, if we go to the trouble of adding a lock to the class we might as well use it here.

:type metric_producer: :class: 'MetricProducer'
:param metric_producer: The metric producer to remove.
"""
if metric_producer is None:
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.

I am not sure If we want to do None check here...

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.

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

@c24t c24t merged commit f669aa9 into census-instrumentation:master Feb 5, 2019
@c24t c24t deleted the metrics-wrap-stats branch February 5, 2019 17:59
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.

Add Metrics APIs as per "metrics.proto"

3 participants