Skip to content

Commit

Permalink
Map metric aggregation setting from Yabeda to Prometheus-mmap
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Dec 11, 2023
1 parent 174e6c8 commit dead06c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion lib/yabeda/prometheus/mmap/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def register_gauge!(metric)
build_name(metric),
metric.comment,
build_tags(metric.tags),
metric.aggregation || :all
gauge_aggregation_mode(metric.aggregation)
)
end

Expand Down Expand Up @@ -87,6 +87,21 @@ def debug!
end
end

private

def gauge_aggregation_mode(yabeda_mode)
case yabeda_mode
when nil, :most_recent # TODO: Switch to most_recent when supported: https://gitlab.com/gitlab-org/ruby/gems/prometheus-client-mmap/-/issues/36
:all
when :min, :max, :all, :liveall
yabeda_mode
when :sum
:livesum
else
raise ArgumentError, "Unsupported gauge aggregation mode #{yabeda_mode.inspect}"
end
end

Yabeda.register_adapter(:prometheus, new)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/yabeda/prometheus/mmap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
gauge :gauge,
comment: 'Gauge',
tags: [:gtag],
aggregation: :max
aggregation: :sum

histogram :histogram,
comment: 'Histogram',
Expand Down Expand Up @@ -49,7 +49,7 @@
.adapters[:prometheus].registry
.instance_variable_get(:@metrics)[:test_gauge]
.instance_variable_get(:@multiprocess_mode)
).to eq(:max)
).to eq(:livesum)
end
end

Expand Down

0 comments on commit dead06c

Please sign in to comment.