From d616d5b2e043d33cf7b22a05d0bc7aca235bf6c0 Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Tue, 7 Jan 2020 15:40:02 +0800 Subject: [PATCH] Add `job_stats` to the config It works exactly the same as `query_stats`. Users who don't need the feature can disable it. --- CHANGELOG.md | 4 ++++ README.md | 21 ++++++++++++++++++++- lib/airbrake-ruby/config.rb | 9 +++++++++ spec/config_spec.rb | 16 ++++++++++++++++ spec/performance_notifier_spec.rb | 1 + 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 016710d8..e2fbd54c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ Airbrake Ruby Changelog ### master +* Added a new option called `job_stats`, which controls whether the library + should send jobs (aka tasks/workers/queues) + ([#534](https://github.com/airbrake/airbrake-ruby/pull/534)) + ### [v4.11.1][v4.11.1] (December 20, 2019) * `PerformanceNotifier`: started rejecting resources with zero timing diff --git a/README.md b/README.md index d6a9f647..1892fddc 100644 --- a/README.md +++ b/README.md @@ -388,6 +388,24 @@ Airbrake.configure do |c| end ``` +#### job_stats + +Configures Airbrake Performance Monitoring job (aka queue/task/worker) +statistics collection. It is displayed on the Performance tab of your +project. If `performance_stats` is `false`, setting this to `true` won't have +effect because `performance_stats` has higher precedence. By default, it's +enabled. + +The statistics is sent via: + +* [`Airbrake.notify_queue`](#airbrakenotify_queue) + +``` +Airbrake.configure do |c| + c.job_stats = false +end +``` + ### Asynchronous Airbrake options The options listed below apply to [`Airbrake.notify`](#airbrakenotify), they do @@ -895,7 +913,8 @@ Sends queue (worker) statistics to Airbrake. Supports groups (similar to Airbrake.notify_queue( queue: "emails", error_count: 1, - groups: { redis: 24.0, sql: 0.4 } # ms + groups: { redis: 24.0, sql: 0.4 }, # ms + timing: 0.05221 # ms ) ``` diff --git a/lib/airbrake-ruby/config.rb b/lib/airbrake-ruby/config.rb index 244b63d1..01577d1c 100644 --- a/lib/airbrake-ruby/config.rb +++ b/lib/airbrake-ruby/config.rb @@ -101,6 +101,12 @@ class Config # @since v4.6.0 attr_accessor :query_stats + # @return [Boolean] true if the library should send job/queue/worker stats + # to Airbrake, false otherwise + # @api public + # @since v4.12.0 + attr_accessor :job_stats + class << self # @return [Config] attr_writer :instance @@ -139,6 +145,7 @@ def initialize(user_config = {}) self.performance_stats = true self.performance_stats_flush_period = 15 self.query_stats = true + self.job_stats = true merge(user_config) end @@ -213,6 +220,8 @@ def check_performance_options(resource) promise.reject("The Performance Stats feature is disabled") elsif resource.is_a?(Airbrake::Query) && !query_stats promise.reject("The Query Stats feature is disabled") + elsif resource.is_a?(Airbrake::Queue) && !job_stats + promise.reject("The Job Stats feature is disabled") else promise end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 99cc7c3d..b5d1eecc 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -22,6 +22,7 @@ its(:performance_stats) { is_expected.to eq(true) } its(:performance_stats_flush_period) { is_expected.to eq(15) } its(:query_stats) { is_expected.to eq(true) } + its(:job_stats) { is_expected.to eq(true) } describe "#new" do context "when user config is passed" do @@ -146,5 +147,20 @@ ) end end + + context "when job stats are disabled" do + before { subject.job_stats = false } + + let(:resource) do + Airbrake::Queue.new(queue: 'foo_queue', error_count: 0, timing: 1) + end + + it "returns a rejected promise" do + promise = subject.check_performance_options(resource) + expect(promise.value).to eq( + 'error' => "The Job Stats feature is disabled", + ) + end + end end end diff --git a/spec/performance_notifier_spec.rb b/spec/performance_notifier_spec.rb index 14c2d9c4..947d5ef7 100644 --- a/spec/performance_notifier_spec.rb +++ b/spec/performance_notifier_spec.rb @@ -16,6 +16,7 @@ performance_stats: true, performance_stats_flush_period: 0, query_stats: true, + job_stats: true, ) end