This repository was archived by the owner on Sep 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 247
Metrics view data conversion #469
Merged
c24t
merged 3 commits into
census-instrumentation:master
from
c24t:metrics-viewdata-conversion
Jan 29, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,13 @@ | |
| # limitations under the License. | ||
|
|
||
|
|
||
| import threading | ||
|
|
||
| from opencensus.metrics import label_key | ||
| from opencensus.metrics.export import metric_descriptor | ||
| from opencensus.stats import metric_utils | ||
|
|
||
|
|
||
| class View(object): | ||
| """A view defines a specific aggregation and a set of tag keys | ||
|
|
||
|
|
@@ -33,13 +40,19 @@ class View(object): | |
| :param aggregation: the aggregation the view will support | ||
|
|
||
| """ | ||
|
|
||
| def __init__(self, name, description, columns, measure, aggregation): | ||
| self._name = name | ||
| self._description = description | ||
| self._columns = columns | ||
| self._measure = measure | ||
| self._aggregation = aggregation | ||
|
|
||
| # Cache the converted MetricDescriptor here to avoid creating it each | ||
| # time we convert a ViewData that realizes this View into a Metric. | ||
| self._md_cache_lock = threading.Lock() | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other stats classes are generally not threadsafe. I don't know that it's worth opening this can of worms in this PR. |
||
| self._metric_descriptor = None | ||
|
|
||
| @property | ||
| def name(self): | ||
| """the name of the current view""" | ||
|
|
@@ -64,3 +77,24 @@ def measure(self): | |
| def aggregation(self): | ||
| """the aggregation of the current view""" | ||
| return self._aggregation | ||
|
|
||
| def get_metric_descriptor(self): | ||
| """Get a MetricDescriptor for this view. | ||
|
|
||
| Lazily creates a MetricDescriptor for metrics conversion. | ||
|
|
||
| :rtype: :class: | ||
| `opencensus.metrics.export.metric_descriptor.MetricDescriptor` | ||
| :return: A converted Metric. | ||
| """ # noqa | ||
| with self._md_cache_lock: | ||
| if self._metric_descriptor is None: | ||
| self._metric_descriptor = metric_descriptor.MetricDescriptor( | ||
| self.name, | ||
| self.description, | ||
| self.measure.unit, | ||
| metric_utils.get_metric_type(self.measure, | ||
| self.aggregation), | ||
| # TODO: add label key description | ||
| [label_key.LabelKey(tk, "") for tk in self.columns]) | ||
| return self._metric_descriptor | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rewrote this for clarity, the only behavior change is the copy below. Note that we're not using
timestamphere, there are likely other bugs hiding in this class.