Skip to content

StackdriverMeterRegistry should report Counters as CUMULATIVE not as GAUGE #2773

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

Closed
jayleenli opened this issue Sep 10, 2021 · 5 comments · Fixed by #2232
Closed

StackdriverMeterRegistry should report Counters as CUMULATIVE not as GAUGE #2773

jayleenli opened this issue Sep 10, 2021 · 5 comments · Fixed by #2232
Labels
doc-update A documentation update enhancement A general enhancement registry: stackdriver A StackDriver Registry related issue
Milestone

Comments

@jayleenli
Copy link

Calling .counter() for a StackdriverMeterRegistry creates a GAUGE metric instead of CUMULATIVE metric.

This is basically a repost of a previously reported bug because that one is closed.
#2231

Environment

  • Micrometer latest version (io.micrometer:micrometer-registry-stackdriver:latest.release)
  • Stackdriver Micrometer registry
  • macOS
  • Java version: 15

To Reproduce
How to reproduce the bug:
Example:

    MeterRegistry registry = StackdriverMeterRegistry.builder(stackdriverConfig).build();
    Counter x = registry.counter("example_counter","example_key","20");
    someUserCaseIncrementingCounter(x);

Will create a gauge metric and not a cumulative one in Cloud Monitoring.

Expected behavior
Create a CUMULATIVE Metric instead of a Gauge Metric

Additional context
User @tmarszal has proposed changes to fix this bug.
tmarszal@9e6809f

@jayleenli jayleenli added the bug A general bug label Sep 10, 2021
@jonatan-ivanov
Copy link
Member

We have a PR to fix this: #2232
I linked it to this issue.

@jonatan-ivanov jonatan-ivanov added enhancement A general enhancement registry: stackdriver A StackDriver Registry related issue and removed bug A general bug labels Sep 10, 2021
@jonatan-ivanov jonatan-ivanov added this to the 1.8.0-M3 milestone Sep 10, 2021
@jonatan-ivanov jonatan-ivanov changed the title StackdriverMeterRegistry is reports Counter meter as a GAUGE metric, not CUMULATIVE StackdriverMeterRegistry should report Counters as CUMULATIVE not as GAUGE Sep 10, 2021
@tmarszal
Copy link
Contributor

Thanks a lot for creating this Issue, @jayleenli !

I see one thing to consider, I would like to get your thoughts on. What MetricKind should we use e.g. for Counters? @shakuzen mentioned in the PR that Step* variants of meters that are used for Stackdriver behave more like DELTA than CUMULATIVE - they reset value on every publish and I agree. Does it make sense to you to produce DELTA instead?

@tmarszal
Copy link
Contributor

Ok, I think I answered my own question. It is not super obvious in Google Monitoring docs, but custom metrics are only allowed to have GAUGE and CUMULATIVE MetricKind. So we can't use DELTA.

https://cloud.google.com/monitoring/api/v3/kinds-and-types#kind-type-combos - in the DELTA column all of the allowed combinations have footnote saying it's not actually supported for custom metrics.

@shakuzen shakuzen modified the milestones: 1.8.0-M3, 1.8.0-RC1 Sep 15, 2021
@shakuzen
Copy link
Member

Just sharing that I found this discussion which resulted in this feature request being opened to support DELTA with custom metrics. Also of note is that a Stackdriver product manager suggested the approach with CUMULATIVE and timstamp resets as a workaround.

@shakuzen shakuzen added the doc-update A documentation update label Oct 14, 2021
shakuzen pushed a commit that referenced this issue Oct 14, 2021
This change makes it possible to send counter metrics as CUMULATIVE instead of GAUGE, which enables better functionality in Stackdriver when graphing the metric. Since a different MetricKind cannot be sent for an already existing MetricDescriptor, this feature is controlled by a feature flag in `StackdriverConfig` called `useSemanticMetricTypes`.

Resolves gh-2773

Co-authored-by: Yuliia <[email protected]>
@shakuzen
Copy link
Member

A new config method has been added to StackdriverConfig named useSemanticMetricTypes. This can be used to enable sending Counters as CUMULATIVE to Stackdriver. If you have sent metrics to Stackdriver on a previous version of Micrometer or with this config set to false, you will need to delete the metric descriptor so that it can be recreated with the CUMULATIVE type. This can be done with, for example, the API explorer at https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors/delete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-update A documentation update enhancement A general enhancement registry: stackdriver A StackDriver Registry related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants