Skip to content

Commit 35dbbce

Browse files
committed
Add configuration for buckets
1 parent 65d7e23 commit 35dbbce

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ Follow the [yabeda-external-http-requests](http://localhost:3000/d/OGd-oEXWz/yab
6767
Finally, after a couple of minutes when data collected you will see the following:
6868
![Monitor external HTTP calls with Grafana](docs/dashboard.png)
6969

70+
## Configuration
71+
72+
Configuration is handled by [anyway_config] gem. With it you can load settings from environment variables (upcased and prefixed with `YABEDA_HTTP_REQUESTS_`), YAML files, and other sources. See [anyway_config] docs for details.
73+
74+
| Config key | Type | Default | Description |
75+
| -----------| ----- | ------- | ------------------------------------------- |
76+
| `buckets` | array | [] | Set buckets to be used by histogram metrics |
77+
7078
## Development with Docker
7179

7280
Get local development environment working and tests running is very easy with docker-compose:

lib/yabeda/http_requests.rb

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

33
require 'yabeda/http_requests/version'
44
require 'yabeda/http_requests/sniffer'
5+
require 'yabeda/http_requests/config'
56
require 'yabeda'
67
require 'sniffer'
78

@@ -16,22 +17,23 @@ module HttpRequests
1617
].freeze
1718

1819
Yabeda.configure do
20+
config = ::Yabeda::HttpRequests::Config.new
21+
buckets = config.buckets || LONG_RUNNING_REQUEST_BUCKETS
22+
1923
group :http
2024

2125
counter :request_total,
22-
comment: 'A counter of the total number of external HTTP \
23-
requests.',
26+
comment: 'A counter of the total number of external HTTP requests.',
2427
tags: %i[host port method]
2528
counter :response_total,
26-
comment: 'A counter of the total number of external HTTP \
27-
responses.',
29+
comment: 'A counter of the total number of external HTTP responses.',
2830
tags: %i[host port method status]
2931

3032
histogram :response_duration, tags: %i[host port method status],
3133
unit: :milliseconds,
32-
buckets: LONG_RUNNING_REQUEST_BUCKETS,
33-
comment: "A histogram of the response \
34-
duration (milliseconds)."
34+
buckets: buckets,
35+
comment: "A histogram of the response duration (milliseconds)."
36+
3537

3638
::Sniffer.config do |c|
3739
c.enabled = true

lib/yabeda/http_requests/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 HttpRequests
7+
# yabeda-http-requests configuration
8+
class Config < ::Anyway::Config
9+
config_name :yabeda_http_requests
10+
11+
attr_config :buckets
12+
end
13+
end
14+
end

yabeda-http_requests.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Gem::Specification.new do |spec|
2626
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2727
spec.require_paths = ['lib']
2828

29+
spec.add_dependency "anyway_config", ">= 1.3", "< 3.0"
30+
2931
spec.add_runtime_dependency 'sniffer'
3032
spec.add_runtime_dependency 'yabeda'
3133
end

0 commit comments

Comments
 (0)