Skip to content
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

Fix gauge aggregation #6

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/yabeda/prometheus/mmap/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def register_gauge!(metric)
registry.gauge(
build_name(metric),
metric.comment,
build_tags(metric.tags)
build_tags(metric.tags),
gauge_aggregation_mode(metric.aggregation)
)
end

Expand Down Expand Up @@ -86,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
22 changes: 21 additions & 1 deletion spec/yabeda/prometheus/mmap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

gauge :gauge,
comment: 'Gauge',
tags: [:gtag]
tags: [:gtag],
aggregation: :sum

histogram :histogram,
comment: 'Histogram',
Expand All @@ -32,9 +33,28 @@
expect(Yabeda.test_counter.values).to eq(
{ { ctag: :'ctag-value' } => 1 }
)
end
end

context 'gauge' do
it do
expect(Yabeda.test_gauge.values).to eq(
{ { gtag: :'gtag-value' } => 123 }
)
end

it 'passes aggregation to multiprocess_mode' do
expect(
Yabeda
.adapters[:prometheus].registry
.instance_variable_get(:@metrics)[:test_gauge]
.instance_variable_get(:@multiprocess_mode)
).to eq(:livesum)
end
end

context 'histogram' do
it do
expect(Yabeda.test_histogram.values).to eq(
{ { htag: :'htag-value' } => 7 }
)
Expand Down