Skip to content

Commit

Permalink
Sidekiq args filtering: default source changes
Browse files Browse the repository at this point in the history
Sidekiq args filtering - in `default_source.rb`, use `dynamic_name:
true`, and use heredocs for the descriptions.

By using `dynamic_name: true`, we don't have to have an ignore list for
config scanning.
  • Loading branch information
fallwith committed Aug 29, 2023
1 parent fa500e4 commit ea08703
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
30 changes: 18 additions & 12 deletions lib/new_relic/agent/configuration/default_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1721,25 +1721,31 @@ def self.enforce_fallback(allowed_values: nil, fallback: nil)
default: NewRelic::EMPTY_ARRAY,
public: true,
type: Array,
dynamic_name: true,
allowed_from_server: false,
description: 'An array of strings that will collectively serve as an allowlist for filtering which Sidekiq ' +
'job arguments get reported to New Relic. The capturing of any Sidekiq arguments requires that ' +
"'job.sidekiq.args.*' be added to the separate :'attributes.include' configuration option. Each " +
'string in this array will be turned into a regular expression via `Regexp.new` to permit advanced ' +
'matching. For job argument hashes, if either a key or value matches the pair will be included. All ' +
'matching job argument array elements and job argument scalars will be included.'
description: <<~SIDEKIQ_ARGS_INCLUDE.chomp.tr("\n", ' ')
An array of strings that will collectively serve as an allowlist for filtering which Sidekiq
job arguments get reported to New Relic. The capturing of any Sidekiq arguments requires that
'job.sidekiq.args.*' be added to the separate :'attributes.include' configuration option. Each
string in this array will be turned into a regular expression via `Regexp.new` to permit advanced
matching. For job argument hashes, if either a key or value matches the pair will be included. All
matching job argument array elements and job argument scalars will be included.
SIDEKIQ_ARGS_INCLUDE
},
:'sidekiq.args.exclude' => {
default: NewRelic::EMPTY_ARRAY,
public: true,
type: Array,
dynamic_name: true,
allowed_from_server: false,
description: 'An array of strings that will collectively serve as a denylist for filtering which Sidekiq ' +
'job arguments get reported to New Relic. The capturing of any Sidekiq arguments requires that ' +
"'job.sidekiq.args.*' be added to the separate :'attributes.include' configuration option. Each string " +
'in this array will be turned into a regular expression via `Regexp.new` to permit advanced matching. ' +
'For job argument hashes, if either a key or value matches the pair will be excluded. All matching job ' +
'argument array elements and job argument scalars will be excluded.'
description: <<~SIDEKIQ_ARGS_EXCLUDE.chomp.tr("\n", ' ')
An array of strings that will collectively serve as a denylist for filtering which Sidekiq
job arguments get reported to New Relic. The capturing of any Sidekiq arguments requires that
'job.sidekiq.args.*' be added to the separate :'attributes.include' configuration option. Each string
in this array will be turned into a regular expression via `Regexp.new` to permit advanced matching.
For job argument hashes, if either a key or value matches the pair will be excluded. All matching job
argument array elements and job argument scalars will be excluded.
SIDEKIQ_ARGS_EXCLUDE
},
# Slow SQL
:'slow_sql.enabled' => {
Expand Down
7 changes: 0 additions & 7 deletions test/helpers/config_scanning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ module ConfigScanning
EVENT_BUFFER_MACRO_PATTERN = /(capacity_key|enabled_key)\s+:(['"])?([a-z\._]+)\2?/
ASSIGNED_CONSTANT_PATTERN = /[A-Z]+\s*=\s*:(['"])?([a-z\._]+)\1?\s*/

# These config settings shouldn't be worried about, possibly because they
# are only referenced via Ruby metaprogramming that won't work with this
# module's regex matching
IGNORED = %i[sidekiq.args.include sidekiq.args.exclude]

def scan_and_remove_used_entries(default_keys, non_test_files)
non_test_files.each do |file|
lines_in(file).each do |line|
Expand All @@ -36,8 +31,6 @@ def scan_and_remove_used_entries(default_keys, non_test_files)
default_keys.delete(key.delete("'").to_sym)
end

IGNORED.each { |key| default_keys.delete(key) }

# Remove any config keys that are annotated with the 'dynamic_name' setting
# This indicates that the names of these keys are constructed dynamically at
# runtime, so we don't expect any explicit references to them in code.
Expand Down

0 comments on commit ea08703

Please sign in to comment.