beam-telemetry / telemetry_metrics_prometheus_core

Core Prometheus Telemetry.Metrics Reporter package for telemetry_metrics_prometheus
Apache License 2.0
35 stars 30 forks source link

Add reporter option to allow gauges for summed metrics #36

Closed c-brenn closed 3 years ago

c-brenn commented 3 years ago

👋 Hopefully the commit message below gives a decent explanation behind the motivations for making a change like this.

I've opened this PR to get your feedback and see if it's something that might be considered - feel free to close this out if not 😄 Likewise if there's an alternative idea as to how to implement this I'd be more than happy to rework this PR.

Thanks for your work on this package, using it has been a breeze!

Commit Message

Some summed metrics can decrease as well as increase, in which case a Prometheus counter isn't suitable as they are monotonic. A Prometheus gauge fits nicely as it allows for arbitrary increases and decreases value.

At the moment, it's only possible to get a gauge from last_value, meaning if you want to report a sum goes up and down, you currently need to sum the value yourself and make it available to last_value via something like telemetry_metrics_poller.

This commit allows users to pass the :prometheus_type reporter option when declaring a sum, which determines whether the metric exported to prometheus is a counter or a gauge.

codecov-io commented 3 years ago

Codecov Report

Merging #36 (53b0d2f) into master (cd8bea3) will increase coverage by 0.04%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #36      +/-   ##
==========================================
+ Coverage   98.31%   98.35%   +0.04%     
==========================================
  Files           9        9              
  Lines         237      243       +6     
==========================================
+ Hits          233      239       +6     
  Misses          4        4              
Flag Coverage Δ
1_10_otp21 98.35% <100.00%> (+0.04%) :arrow_up:
1_10_otp22 98.35% <100.00%> (+0.04%) :arrow_up:
1_6_otp20 98.35% <100.00%> (+0.04%) :arrow_up:
1_6_otp21 98.35% <100.00%> (+0.04%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/core.ex 100.00% <ø> (ø)
lib/core/exporter.ex 100.00% <100.00%> (ø)
lib/core/registry.ex 93.93% <100.00%> (+0.28%) :arrow_up:
lib/core/sum.ex 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update cd8bea3...53b0d2f. Read the comment docs.

c-brenn commented 3 years ago

@bryannaegele I updated the documentation a little while ago so folks can find the new option 😄 Let me know if there are any further improvements we'd like to get this change in a fit state to merge.

c-brenn commented 3 years ago

Yikes, I need to be a bit more careful with my editor's tab-complete 😅

Thanks for the review!