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

Add job_stats to the config #534

Merged
merged 1 commit into from
Jan 7, 2020
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
```

Expand Down
9 changes: 9 additions & 0 deletions lib/airbrake-ruby/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions spec/performance_notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
performance_stats: true,
performance_stats_flush_period: 0,
query_stats: true,
job_stats: true,
)
end

Expand Down