From dead06c454d6c86cb269cd6e98c9a7599fc71315 Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Mon, 11 Dec 2023 21:16:54 +0900 Subject: [PATCH] Map metric aggregation setting from Yabeda to Prometheus-mmap --- lib/yabeda/prometheus/mmap/adapter.rb | 17 ++++++++++++++++- spec/yabeda/prometheus/mmap_spec.rb | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/yabeda/prometheus/mmap/adapter.rb b/lib/yabeda/prometheus/mmap/adapter.rb index 7e66a7a..ea15db7 100644 --- a/lib/yabeda/prometheus/mmap/adapter.rb +++ b/lib/yabeda/prometheus/mmap/adapter.rb @@ -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 @@ -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 diff --git a/spec/yabeda/prometheus/mmap_spec.rb b/spec/yabeda/prometheus/mmap_spec.rb index e6d3758..2ded663 100644 --- a/spec/yabeda/prometheus/mmap_spec.rb +++ b/spec/yabeda/prometheus/mmap_spec.rb @@ -14,7 +14,7 @@ gauge :gauge, comment: 'Gauge', tags: [:gtag], - aggregation: :max + aggregation: :sum histogram :histogram, comment: 'Histogram', @@ -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