Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add unique identifier to Cloud Monitoring exporter #841

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

Merged
merged 11 commits into from
Jun 23, 2020

Conversation

AndrewAXue
Copy link
Contributor

Cloud Monitoring allows one update every 10 seconds for a unique tuple (metric_name, metric_label_value_1, metric_label_value_2 ...). To respect this, the exporter has an in memory map of when it last exported each tuple. There are two ways this can be broken.

  1. A user restarts the server more then once every 10 seconds. The in memory map will be deleted between restarts.
  2. A user has a multithreaded server or multiple servers.

For both cases, a fix has been suggested in the troubleshooting docs. For the second, the ability to add a unique identifier as a label_value has been added. Thanks to @cnnradams for bringing up this issue :)

@AndrewAXue AndrewAXue requested a review from a team June 18, 2020 19:36
@AndrewAXue AndrewAXue changed the title Cloud monitoring unique Add unique identifier to Cloud Monitoring exporter Jun 18, 2020
@lzchen
Copy link
Contributor

lzchen commented Jun 19, 2020

Correct me if I'm wrong, but it seems like MetricDescriptor is only used as a key to for lookup for this "uniqueness" mechanism. Not only that, but only the type field is used for this. Why go all through trouble of making a descriptor, setting all of its fields (labels, metric_kind, etc) if they aren't being used?

@lzchen
Copy link
Contributor

lzchen commented Jun 19, 2020

It seems kind of strange that metric_descriptor.type (which is derived from the metric name) and record.labels is used, even though when creating the MetricDescriptor, the labels are already stored in it. Is there some way to leverage the "uniqueness" of the MetricDescriptor, maybe override the __equals__ to include a GUID?

@lzchen
Copy link
Contributor

lzchen commented Jun 19, 2020

If the uniqueness depends only on the name and labels, what about instruments with the same name but different other properties (desc, unit, value_type, metric_type)? Would a Counter instrument and Observer instrument with the same name be treated as the same metric? Maybe the uniqueness should depend on all the fields in the descriptor?

@AndrewAXue
Copy link
Contributor Author

It seems kind of strange that metric_descriptor.type (which is derived from the metric name) and record.labels is used, even though when creating the MetricDescriptor, the labels are already stored in it. Is there some way to leverage the "uniqueness" of the MetricDescriptor, maybe override the __equals__ to include a GUID?

Correct me if I'm wrong, but it seems like MetricDescriptor is only used as a key to for lookup for this "uniqueness" mechanism. Not only that, but only the type field is used for this. Why go all through trouble of making a descriptor, setting all of its fields (labels, metric_kind, etc) if they aren't being used?

You Are able to auto create MetricDescriptor https://cloud.google.com/monitoring/custom-metrics/creating-metrics#auto-creation. But theres a lot of information that you lose, e.g. the metric can't have a description, labels can't have descriptions, you can't choose the unit or displayname. That's why I opt to create my own. The other fields (labels, metric_kind) do get used, just not by me. By adding the MetricDescriptor type to my Metric, its telling the backend that the label keys + metric_kind should match, and if they don't it'll complain.

@AndrewAXue
Copy link
Contributor Author

It seems kind of strange that metric_descriptor.type (which is derived from the metric name) and record.labels is used, even though when creating the MetricDescriptor, the labels are already stored in it. Is there some way to leverage the "uniqueness" of the MetricDescriptor, maybe override the __equals__ to include a GUID?

MetricDescriptor stores only label keys, while record.labels has both. When creating the MetricDescriptor you only need to pass it label keys, but when creating Metric (that's associated with a MetricDescriptor) you need to populate all the label keys passed to the associated MetricDescriptor with a valid label value (or None). I'm not sure what you mean with the GUID, we store a UUID with label key opentelemetry_uuid.

Copy link
Contributor

@lzchen lzchen left a comment

Choose a reason for hiding this comment

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

Nice

@AndrewAXue
Copy link
Contributor Author

Nice

Nice.

@AndrewAXue
Copy link
Contributor Author

If the uniqueness depends only on the name and labels, what about instruments with the same name but different other properties (desc, unit, value_type, metric_type)? Would a Counter instrument and Observer instrument with the same name be treated as the same metric? Maybe the uniqueness should depend on all the fields in the descriptor?

Resolved offline. Users can't have multiple metric instruments in the same meter with same name.

@AndrewAXue AndrewAXue force-pushed the cloud_monitoring_unique branch from c62b646 to cca8d63 Compare June 22, 2020 20:51
Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

A few nits, LGTM otherwise. Please check that @aabmass is ok with using these UUID-like labels before merging.

@AndrewAXue AndrewAXue force-pushed the cloud_monitoring_unique branch from cca8d63 to 1f9a247 Compare June 22, 2020 21:01
@aabmass
Copy link
Member

aabmass commented Jun 22, 2020

🚀

@lzchen lzchen merged commit d35e626 into open-telemetry:master Jun 23, 2020
@@ -33,6 +50,11 @@ def __init__(self, project_id=None, client=None):
self.project_name = self.client.project_path(self.project_id)
self._metric_descriptors = {}
self._last_updated = {}
self.unique_identifier = None
if add_unique_identifier:
self.unique_identifier = "{:08x}".format(
Copy link

@xichen2020 xichen2020 Jun 29, 2020

Choose a reason for hiding this comment

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

If the process using the exporter restarts, the ID could change, which means the exported time series will be different from those before the restart for time series that have monitored resource / metric labels that are otherwise the same. Is that a concern?

self.unique_identifier = None
if add_unique_identifier:
self.unique_identifier = "{:08x}".format(
random.randint(0, 16 ** 8)

Choose a reason for hiding this comment

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

Just checking, this will generate different values on different instantiations after process restarts without seeding? (not very familiar with Python random module)

cnnradams pushed a commit to cnnradams/opentelemetry-python that referenced this pull request Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants