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

Skeleton for Azure Metrics Exporter#678

Merged
reyang merged 24 commits intocensus-instrumentation:masterfrom
lzchen:metrics
Jun 14, 2019
Merged

Skeleton for Azure Metrics Exporter#678
reyang merged 24 commits intocensus-instrumentation:masterfrom
lzchen:metrics

Conversation

@lzchen
Copy link
Copy Markdown
Contributor

@lzchen lzchen commented Jun 6, 2019

Initial structure of the Azure Metrics Exporter.

Follows the StackDriver Stats Exporter logic. We use a poll-based mechanism instead of push-based as seen in the Prometheus Stats Exporter.

Currently, the exporter simply prints the meta data related to the metric.

@c24t @reyang

@lzchen lzchen requested review from a team, c24t, reyang and songy23 as code owners June 6, 2019 21:35
.. code:: python

from opencensus.ext.azure import metric_exporter
from opencensus.stats import stats as stats_module
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.

  1. Remove partial example code.
  2. Move from stats to metrics, opencensus.stats is being replaced by opencensus.metrics. If we have dependency in stats, we need to refactor it and move to metrics.


__all__ = ['MetricsExporter']

class MetricsExporter(object):
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.

Regarding the name, I wish to discuss about (we might want to do a better job in OpenTelemetry):

  1. Do we want to drive for some level of consistency or not at all (and leave this for individual vendor's choice of flavor)?
  2. When to use plural form versus not?
  3. Should the class name be specific or generic? (e.g. do we want AzureExporter, AzureMonitorExporter, AzureMetricExporter or AzureMetricsExporter, my personal preference would be something we did for Azure trace exporter and stackdriver trace exporter)
  4. Should the class name be self contained or we should leverage package name? (e.g. ext.azure.trace_exporter.AzureExporter, ext.azure.TraceExporter or ext.azure.AzureTraceExporter).

https://github.com/census-instrumentation/opencensus-python/blob/master/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py#L34

https://github.com/census-instrumentation/opencensus-python/blob/master/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/trace_exporter/__init__.py#L164

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes I was thinking about this as well. I think it is good to be consistent across the entire project and set some standards.

In my opinion:

  1. We should use singular form when referring to the "task-doer" such as MetricExporter, TraceExporter, etc. We should use the plural when we are referring to the category in a collective context (this will export metrics..., the traces are sent through..., etc) because the logic involves one or possibly more of these.

  2. In regards to the class name, I think we should be as specific as possible. When going through the codebase, it is easier to identify what module I am looking at without having to look at the package I am under (problem that I am having with init.py). Also, if we ever take code snippets, readers can identify what class is being looked at without having to see the file path.

  3. In regards to leveraging the package name, separating the files based off levels is my preference. So ext.azure.trace_exporter.AzureTraceExporter would be ideal.

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.

@c24t what's your opinion?

Seems in OpenTelemetry Java we've already started to diverge (metrics and tags are plural form, while trace is not):

https://github.com/open-telemetry/opentelemetry-java/tree/master/api/src/main/java/io/opentelemetry

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.

We have just discussed the exact same issue recently, in open-telemetry/opentelemetry-java#259 (comment). The conclusion is:

Let's stick with what we have, but pluralize resources.
trace
metrics
tags
resources

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.

What about log? Using logs seems to be against language convention.

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.

We haven't talked about it but personally I'd suggest to go with log for now. Agree logs doesn't seem to be a great name here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will make the changes based off these decisions for metrics.

@lzchen
Copy link
Copy Markdown
Contributor Author

lzchen commented Jun 7, 2019

Going to refactor the PR to use metrics instead of stats.

@lzchen
Copy link
Copy Markdown
Contributor Author

lzchen commented Jun 10, 2019

The MetricsExporter uses copies of the metrics and view/recorder apis in stats (copied to metrics package). I know @c24t has been working on some refactor work from stats to metrics. Any thoughts on this?

#476

README.rst Outdated
.. _threading: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-threading
.. _Zipkin: https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-zipkin

Metrics Exporter
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.

Probably need to put this under "Stats Exporter".

Copy link
Copy Markdown
Contributor Author

@lzchen lzchen Jun 12, 2019

Choose a reason for hiding this comment

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

Yes I will do that. I will change it back to Metrics next time when we truly have a metrics exporter.

import logging

from opencensus.ext.azure.log_exporter import AzureLogHandler
from opencensus.ext.azure.logs_exporter import AzureLogHandler
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.

This is a breaking change, we need to:

  1. Update the changelog to mention it, so users would know.
  2. Bump the version when we do a release.

I would suggest that we don't touch this for now (since we haven't yet finalized whether to take plural form or not).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right. I did not realize this. I will revert this for now.

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.

This PR is becoming too big.
Let's revert the log->logs change. Other parts looks good once we cleaned up CI error.

Metrics
~~~~~~~

The **OpenCensus Azure Monitor Metrics Exporter** allows you to export metrics to `Azure Monitor`_.
Copy link
Copy Markdown
Contributor

@reyang reyang Jun 13, 2019

Choose a reason for hiding this comment

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

Minor: I feel that we don't need to mention "OpenCensus" here given the context we have in the doc, otherwise it is too long?
Up to you, if you decide to keep it, need to update trace/logs to make them consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right. We should be consistent with the other two and it seems a bit redundant given the package we are in. I shall remove it.

def main():
# Enable metrics
# Set the interval in seconds in which you want to send metrics
exporter = metrics_exporter.new_metrics_exporter(export_interval=2)
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.

Minor suggestion, it is not clear if the interval should be an integer or it can be a float/decimal, consider either update the comment or put something like 2.0 (if we do support float).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We allow floats so I will put 2.0 in the sample to let users know implicitly this is possible.

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.

Great, this is something that we've been practicing, e.g. ProbabilitySampler(1.0) and

aggregation_module.DistributionAggregation(
        [100.0, 200.0, 400.0, 1000.0, 2000.0, 4000.0]))



def new_metrics_exporter(**options):
options = Options(**options)
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'm curious why would we want to validate options here versus in the MetricsExporter.__init__.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I feel like validation logic should be handled in the service layer, outside of the constructor. IMO init should only serve to instantiate variables.

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.

Would you explain a bit more?
In general people do validate inside constructors, which prevent them from creating a wrong object.

https://github.com/googleapis/google-cloud-python/blob/master/monitoring/google/cloud/monitoring_v3/gapic/metric_service_client.py#L115

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, it does seem like we do validation everywhere inside the constructor for a lot of classes. I can make the change to be consistent.

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, I've left some minor suggestions.

@reyang reyang merged commit 0ec23a6 into census-instrumentation:master Jun 14, 2019
lzchen added a commit to lzchen/opencensus-python that referenced this pull request Jul 15, 2019
lzchen added a commit to lzchen/opencensus-python that referenced this pull request Jul 18, 2019
lzchen added a commit to lzchen/opencensus-python that referenced this pull request Jul 19, 2019
lzchen added a commit to lzchen/opencensus-python that referenced this pull request Jul 22, 2019
Add skeleton metrics exporter to azure

add bracket (census-instrumentation#690)

Implement Azure Metrics Exporter (census-instrumentation#693)

fix rst doc for Azure exporter

bump version
lzchen added a commit to lzchen/opencensus-python that referenced this pull request Jul 22, 2019
Add skeleton metrics exporter to azure

add bracket (census-instrumentation#690)

Implement Azure Metrics Exporter (census-instrumentation#693)

fix rst doc for Azure exporter

bump version

fix comment
c24t pushed a commit that referenced this pull request Jul 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants