diff --git a/README.md b/README.md index 44c606d..91fc60a 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,14 @@ Follow the [yabeda-external-http-requests](http://localhost:3000/d/OGd-oEXWz/yab Finally, after a couple of minutes when data collected you will see the following: ![Monitor external HTTP calls with Grafana](docs/dashboard.png) +## Configuration + +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. + +| Config key | Type | Default | Description | +| -----------| ----- | ------- | ------------------------------------------- | +| `buckets` | array | [] | Set buckets to be used by histogram metrics | + ## Development with Docker Get local development environment working and tests running is very easy with docker-compose: diff --git a/lib/yabeda/http_requests.rb b/lib/yabeda/http_requests.rb index c090caa..6550b44 100644 --- a/lib/yabeda/http_requests.rb +++ b/lib/yabeda/http_requests.rb @@ -2,6 +2,7 @@ require 'yabeda/http_requests/version' require 'yabeda/http_requests/sniffer' +require 'yabeda/http_requests/config' require 'yabeda' require 'sniffer' @@ -16,22 +17,22 @@ module HttpRequests ].freeze Yabeda.configure do + config = ::Yabeda::HttpRequests::Config.new + buckets = config.buckets || LONG_RUNNING_REQUEST_BUCKETS + group :http counter :request_total, - comment: 'A counter of the total number of external HTTP \ - requests.', + comment: 'A counter of the total number of external HTTP requests.', tags: %i[host port method] counter :response_total, - comment: 'A counter of the total number of external HTTP \ - responses.', + comment: 'A counter of the total number of external HTTP responses.', tags: %i[host port method status] histogram :response_duration, tags: %i[host port method status], unit: :milliseconds, - buckets: LONG_RUNNING_REQUEST_BUCKETS, - comment: "A histogram of the response \ - duration (milliseconds)." + buckets: buckets, + comment: 'A histogram of the response duration (milliseconds).' ::Sniffer.config do |c| c.enabled = true diff --git a/lib/yabeda/http_requests/config.rb b/lib/yabeda/http_requests/config.rb new file mode 100644 index 0000000..5fe41f7 --- /dev/null +++ b/lib/yabeda/http_requests/config.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'anyway' + +module Yabeda + module HttpRequests + # yabeda-http-requests configuration + class Config < ::Anyway::Config + config_name :yabeda_http_requests + + attr_config :buckets + end + end +end diff --git a/yabeda-http_requests.gemspec b/yabeda-http_requests.gemspec index 4c0813a..e781819 100644 --- a/yabeda-http_requests.gemspec +++ b/yabeda-http_requests.gemspec @@ -26,6 +26,8 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] + spec.add_dependency 'anyway_config', '>= 1.3', '< 3.0' + spec.add_runtime_dependency 'sniffer' spec.add_runtime_dependency 'yabeda' end