Skip to content

Commit 7cc7676

Browse files
authored
Allow to configure bucket size for histograms (#6)
1 parent 7f64135 commit 7cc7676

File tree

6 files changed

+34
-2
lines changed

6 files changed

+34
-2
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ gem "rspec", "~> 3.0"
3636
gem "rubocop", "~> 1.30"
3737

3838
gem "debug"
39+
40+
gem "anyway_config", ">= 1.3", "< 3.0"

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PATH
33
specs:
44
yabeda-activerecord (0.1.1)
55
activerecord (>= 6.0)
6+
anyway_config (>= 1.3, < 3.0)
67
yabeda (~> 0.6)
78

89
GEM
@@ -83,6 +84,7 @@ PLATFORMS
8384

8485
DEPENDENCIES
8586
activerecord (~> 7.0)
87+
anyway_config (>= 1.3, < 3.0)
8688
debug
8789
rake (~> 13.0)
8890
rspec (~> 3.0)

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ Launch/restart your application and that's it: metrics are being collected.
2222

2323
To expose metrics Don't forget to also add one of [Yabeda adapters](https://github.com/yabeda-rb/yabeda#available-monitoring-system-adapters) to your Gemfile.
2424

25+
## Configuration
26+
27+
Configuration is handled by [anyway_config] gem. With it you can load settings from environment variables (upcased and prefixed with `YABEDA_ACTIVERECORD_`), YAML files, and other sources. See [anyway_config] docs for details.
28+
29+
| Config key | Type | Default | Description |
30+
| -----------| ----- | ------- | ------------------------------------------- |
31+
| `buckets` | array | [] | Set buckets to be used by histogram metrics |
32+
2533
## Metrics
2634

2735
### Query performance

lib/yabeda/active_record.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "yabeda"
44
require "active_record"
5+
require "yabeda/active_record/config"
56

67
require_relative "active_record/version"
78

@@ -14,14 +15,18 @@ class Error < StandardError; end
1415
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, # standard (from Prometheus)
1516
30, 60, 120, 300, 1800, 3600, 21_600, # Well, sometime queries can execute way too long
1617
].freeze
17-
18+
19+
1820
# rubocop: disable Layout/LineLength
1921
Yabeda.configure do
22+
config = ::Yabeda::ActiveRecord::Config.new
23+
buckets = config.buckets || LONG_RUNNING_QUERY_RUNTIME_BUCKETS
24+
2025
group :activerecord do
2126
counter :queries_total, tags: %i[config kind cached async],
2227
comment: "Total number of SQL queries issued by application via ActiveRecord"
2328
histogram :query_duration, tags: %i[config kind cached async],
24-
unit: :seconds, buckets: LONG_RUNNING_QUERY_RUNTIME_BUCKETS,
29+
unit: :seconds, buckets: buckets,
2530
comment: "Duration of SQL queries generated by ActiveRecord"
2631

2732
gauge :connection_pool_size,

lib/yabeda/active_record/config.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
require 'anyway'
4+
5+
module Yabeda
6+
module ActiveRecord
7+
# yabeda-activerecord configuration
8+
class Config < ::Anyway::Config
9+
config_name :yabeda_activerecord
10+
11+
attr_config :buckets
12+
end
13+
end
14+
end

yabeda-activerecord.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ Gem::Specification.new do |spec|
3333

3434
spec.add_dependency "activerecord", ">= 6.0"
3535
spec.add_dependency "yabeda", "~> 0.6"
36+
spec.add_dependency "anyway_config", ">= 1.3", "< 3.0"
3637
end

0 commit comments

Comments
 (0)