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

Metrics: add MetricsProducer and convert stats #476

Merged
merged 8 commits into from
Feb 5, 2019

Conversation

c24t
Copy link
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.

from opencensus.stats.stats_recorder import StatsRecorder
from opencensus.stats.view_manager import ViewManager


class Stats(object):
class Stats(MetricProducer):
Copy link
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
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
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
@@ -12,24 +12,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime

from opencensus.metrics.export.metric_producer import MetricProducer
Copy link
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
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
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
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
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
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
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
Member Author

Choose a reason for hiding this comment

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

Copy link
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 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.

Add Metrics APIs as per "metrics.proto"
3 participants