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

Use metrics instead of stats in SD exporter#560

Merged
c24t merged 16 commits intocensus-instrumentation:stackdriver-metricsfrom
c24t:stackdriver-metrics
Mar 21, 2019
Merged

Use metrics instead of stats in SD exporter#560
c24t merged 16 commits intocensus-instrumentation:stackdriver-metricsfrom
c24t:stackdriver-metrics

Conversation

@c24t
Copy link
Copy Markdown
Member

@c24t c24t commented Mar 18, 2019

This is the first of several breaking changes to replace the stats data model (ViewData, AggregationData, etc.) with metrics in stats/metrics exporters.

This PR changes StackdriverStatsExporter to:

  • use Metric instead of ViewData internally
  • remove on_register_view hook, lazily register metric descriptors with stackdriver at export time instead of on view creation
  • prepare to move from push to poll model by removing transports, emit, etc.

The meat of this PR is in create_time_series_list, which now takes a list of Metrics.

cc @colincadams

Addresses #454.



class StackdriverStatsExporter(base_exporter.StatsExporter):
class StackdriverStatsExporter(object):
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.

We'll update StatsExporter after making the same changes to the prometheus exporter. This is an API change.

except KeyError:
raise ValueError("Unknown MetricDescriptorType value")

@classmethod
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.

Consider replacing this one-off enum class with enum34.

def create_time_series_list(self, metric):
tsl = []
for ts in metric.time_series:
tsl.append(self._convert_series(metric, ts))
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.

Curious, would this [self._convert_series(metric, ts) for ts in metric.time_series] give better readability and perf? And would tuple work 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.

Changed in bce0b86. No strong opinion on lists vs tuples, but it's fine for the caller to modify this one and we generally use lists internally like this.

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.

Got it. Thanks!

"""Get a SD descriptor type for an OC metric descriptor."""
return namespaced_view_name(oc_md.name, self.options.metric_prefix)

def get_metric_descriptor(self, oc_md):
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, probably we can use a predefined dict to do the lookup?

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.

agreed. In fact one already exists for gauge: metric_utils.is_gauge. I think it would make sense to create one for cumulative and for the value types as well.

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.

Done in bce0b86, good call.

Copy link
Copy Markdown
Contributor

@colincadams colincadams left a comment

Choose a reason for hiding this comment

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

few minor comments

safe_key = sanitize_label(key.key)
series.metric.labels[safe_key] = val.value

set_monitored_resource(series, self.options.resource)
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.

Outside the scope of this pr, but I'm curious what the motivation is to do the monitored resource detection every time we export every series. Instead would it make sense to detect and convert the labels once when the exporter is created? Then we can just set it on each series each time.

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.

nvm, #427 addresses this

"""Get a SD descriptor type for an OC metric descriptor."""
return namespaced_view_name(oc_md.name, self.options.metric_prefix)

def get_metric_descriptor(self, oc_md):
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.

agreed. In fact one already exists for gauge: metric_utils.is_gauge. I think it would make sense to create one for cumulative and for the value types as well.

@c24t c24t changed the title [WIP] Use metrics instead of stats in SD exporter Use metrics instead of stats in SD exporter Mar 19, 2019
@c24t
Copy link
Copy Markdown
Member Author

c24t commented Mar 19, 2019

e89c84e is a mostly mechanical change to the existing tests to convert ViewDatas to metrics before converting to timeseries. These should be replaced with Metrics or mocks before merging into master, and we need new tests to cover the exporter's new polling behavior.

Note that this is being merged into the stackdriver-metrics branch. I'm separating the changes to the stackdriver client here to make the diffs easier to digest, and will open a PR from this branch once all the metrics changes in the client are done.

GLOBAL_RESOURCE_TYPE = 'global'

# OC metric descriptor type to SD metric kind and value type
OC_MD_TO_SD_TYPE = {
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.

There should be one more mapping for Summary type. See Java: census-instrumentation/opencensus-java#1591. You can file an issue to add support for it later.

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.

Opened #567.

elif (metric.descriptor.type ==
metric_descriptor.MetricDescriptorType.GAUGE_DOUBLE):
sd_point.value.double_value = float(point.value.value)

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.

elif (metric.descriptor.type == 
       metric_descriptor.MetricDescriptorType.SUMMARY):
# TODO...

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 a98553e.

@c24t
Copy link
Copy Markdown
Member Author

c24t commented Mar 20, 2019

Screen Shot 2019-03-20 at 4 12 17 PM

ResourceExhausted: 429 Your metric descriptor quota has been exhausted.

Our stackdriver system tests create (and then don't delete) metric descriptors in GCP.

@c24t c24t merged commit a0f8c2b into census-instrumentation:stackdriver-metrics Mar 21, 2019
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.

5 participants