Skip to content

Commit 3f2e086

Browse files
committed
Remove the per-app override
1 parent 01fb512 commit 3f2e086

7 files changed

Lines changed: 18 additions & 32 deletions

File tree

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Besides `base_controller_class`, you can also set the following for `MissionCont
114114
- `scheduled_job_delay_threshold`: the time duration before a scheduled job is considered delayed. Defaults to `1.minute` (a job is considered delayed if it hasn't transitioned from the `scheduled` status 1 minute after the scheduled time).
115115
- `show_console_help`: whether to show the console help. If you don't want the console help message, set this to `false`—defaults to `true`.
116116
- `backtrace_cleaner`: a backtrace cleaner used for optionally filtering backtraces on the Failed Jobs detail page. Defaults to `Rails::BacktraceCleaner.new`. See the [Advanced configuration](#advanced-configuration) section for how to configure/override this setting on a per application/server basis.
117-
- `filter_arguments`: an array of job argument keys that you want to filter out in the UI. This is useful for hiding sensitive user data. You can also override this option for each application. Currently, only root-level hash keys are supported. See the [Advanced configuration](#advanced-configuration) section for an example.
117+
- `filter_arguments`: an array of job argument keys that you want to filter out in the UI. This is useful for hiding sensitive user data. Currently, only root-level hash keys are supported.
118118

119119
This library extends Active Job with a querying interface and the following setting:
120120
- `config.active_job.default_page_size`: the internal batch size that Active Job will use when sending queries to the underlying adapter and the batch size for the bulk operations defined above—defaults to `1000`.
@@ -185,9 +185,7 @@ SERVERS_BY_APP.each do |app, servers|
185185
# [ server, [ queue_adapter, BacktraceCleaner.new ]] # with optional backtrace cleaner
186186
end.to_h
187187

188-
filter_arguments = %i[ author ]
189-
190-
MissionControl::Jobs.applications.add(app, queue_adapters_by_name, filter_arguments)
188+
MissionControl::Jobs.applications.add(app, queue_adapters_by_name)
191189
end
192190
```
193191

lib/active_job/job_argument_filter.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@ def filter_arguments(arguments)
1111
end
1212

1313
def filter_argument_hash(argument)
14-
return argument if filters.blank?
14+
return argument if MissionControl::Jobs.filter_arguments.blank?
1515

1616
argument.each do |key, value|
17-
if filters.include?(key.to_s)
17+
if MissionControl::Jobs.filter_arguments.include?(key.to_s)
1818
argument[key] = FILTERED
1919
end
2020
end
2121
end
22-
23-
private
24-
def filters
25-
MissionControl::Jobs::Current.application&.filter_arguments
26-
end
2722
end
2823
end

lib/mission_control/jobs/application.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
class MissionControl::Jobs::Application
33
include MissionControl::Jobs::IdentifiedByName
44

5-
attr_reader :servers, :filter_arguments
5+
attr_reader :servers
66

77
def initialize(name:)
88
super
99
@servers = MissionControl::Jobs::IdentifiedElements.new
10-
@filter_arguments = []
1110
end
1211

1312
def add_servers(queue_adapters_by_name)
@@ -18,8 +17,4 @@ def add_servers(queue_adapters_by_name)
1817
backtrace_cleaner: cleaner, application: self)
1918
end
2019
end
21-
22-
def filter_arguments=(arguments)
23-
@filter_arguments = Array(arguments).map(&:to_s)
24-
end
2520
end
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# A container to register applications
22
class MissionControl::Jobs::Applications < MissionControl::Jobs::IdentifiedElements
3-
def add(name, queue_adapters_by_name = {}, filter_arguments = [])
3+
def add(name, queue_adapters_by_name = {})
44
self << MissionControl::Jobs::Application.new(name: name).tap do |application|
55
application.add_servers(queue_adapters_by_name)
6-
application.filter_arguments = filter_arguments.presence || MissionControl::Jobs.filter_arguments
76
end
87
end
98
end
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
require "test_helper"
22

33
class ActiveJob::JobArgumentFilterTest < ActiveSupport::TestCase
4-
setup do
5-
@application = MissionControl::Jobs::Application.new(name: "BC4")
6-
MissionControl::Jobs::Current.application = @application
7-
end
8-
94
test "filter_arguments" do
105
arguments = [
116
"deliver",
@@ -15,24 +10,27 @@ class ActiveJob::JobArgumentFilterTest < ActiveSupport::TestCase
1510
message: "Hello!"
1611
}
1712
]
18-
@application.filter_arguments = %i[ email_address message ]
13+
@previous_filter_arguments, MissionControl::Jobs.filter_arguments = MissionControl::Jobs.filter_arguments, %w[ email_address message ]
1914

2015
filtered = ActiveJob::JobArgumentFilter.filter_arguments(arguments)
2116

2217
assert_equal "deliver", filtered[0]
2318
assert_equal({ email_address: "[FILTERED]", profile: { name: "Jorge Manrubia" }, message: "[FILTERED]" }, filtered[1])
19+
ensure
20+
MissionControl::Jobs.filter_arguments = @previous_filter_arguments
2421
end
2522

2623
test "filter_argument_hash" do
2724
argument = {
2825
email_address: "jorge@37signals.com",
2926
message: "Hello!"
3027
}
31-
filtered = ActiveJob::JobArgumentFilter.filter_argument_hash(argument)
32-
assert_equal({ email_address: "jorge@37signals.com", message: "Hello!" }, filtered)
28+
@previous_filter_arguments, MissionControl::Jobs.filter_arguments = MissionControl::Jobs.filter_arguments, %w[ message ]
3329

34-
@application.filter_arguments = %i[ message ]
3530
filtered = ActiveJob::JobArgumentFilter.filter_argument_hash(argument)
31+
3632
assert_equal({ email_address: "jorge@37signals.com", message: "[FILTERED]" }, filtered)
33+
ensure
34+
MissionControl::Jobs.filter_arguments = @previous_filter_arguments
3735
end
3836
end

test/dummy/config/initializers/mission_control_jobs.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ def redis_connection_for(app, server)
1515
Resque::DataStore.new redis_namespace
1616
end
1717

18+
# Filter sensitive arguments from the UI.
19+
MissionControl::Jobs.filter_arguments = %w[ author ]
20+
1821
SERVERS_BY_APP.each do |app, servers|
1922
queue_adapters_by_name = servers.collect do |server|
2023
queue_adapter = if server.start_with?("resque")
@@ -26,7 +29,5 @@ def redis_connection_for(app, server)
2629
[ server, queue_adapter ]
2730
end.to_h
2831

29-
filter_arguments = %i[ author ]
30-
31-
MissionControl::Jobs.applications.add(app, queue_adapters_by_name, filter_arguments)
32+
MissionControl::Jobs.applications.add(app, queue_adapters_by_name)
3233
end

test/system/show_failed_job_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ShowFailedJobsTest < ApplicationSystemTestCase
2020
ActiveJob.jobs.failed.discard_all
2121
FailingPostJob.perform_later(Post.create(title: "hello_world"), 1.year.ago, author: "Jorge")
2222
perform_enqueued_jobs
23-
@previous_filter_arguments, MissionControl::Jobs.filter_arguments = MissionControl::Jobs.filter_arguments, %i[ author ]
23+
@previous_filter_arguments, MissionControl::Jobs.filter_arguments = MissionControl::Jobs.filter_arguments, %w[ author ]
2424

2525
visit jobs_path(:failed)
2626
click_on "FailingPostJob"

0 commit comments

Comments
 (0)