Skip to content

Commit

Permalink
Avoid queueing job if Splunk-related functionality disabled
Browse files Browse the repository at this point in the history
Trello: https://trello.com/c/q1B1HKBy

Currently the Splunk-related functionality is effectively disabled,
because neither of the relevant env vars are defined in any environment.
See this Trello card [1] for more details.

Prior to this commit, we were always queueing up a Sidekiq job whenever
EventLog.record_event was called even though, as soon as that
SplunkLogStreamingJob was executed, the first thing we did was give up
if both the relevant env vars were not set.

Now we only queue up the job in the first place if the relevant env vars
are defined. I've left the original check in EventLog#send_to_splunk in
place, because there's a small chance the state of the env vars could
change between the job being queued and the job being executed.

[1]: https://trello.com/c/Zp23Kd6c
  • Loading branch information
floehopper committed Aug 30, 2023
1 parent 034c46d commit c5af367
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/event_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ def self.record_event(user, event, options = {})

event_log_entry = EventLog.create!(attributes)

SplunkLogStreamingJob.perform_later(event_log_entry.id)
if splunk_endpoint_enabled?
SplunkLogStreamingJob.perform_later(event_log_entry.id)
end

event_log_entry
end
Expand Down
22 changes: 22 additions & 0 deletions test/models/event_log_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,28 @@ class EventLogTest < ActiveSupport::TestCase
assert_equal EventLog::ACCOUNT_INVITED, event_log.entry
end

context "when Splunk endpoint enabled" do
setup do
EventLog.stubs(:splunk_endpoint_enabled?).returns(true)
end

should "queue job to send event to Splunk endpoint" do
SplunkLogStreamingJob.expects(:perform_later)
EventLog.record_event(build(:user), EventLog::SUCCESSFUL_LOGIN)
end
end

context "when Splunk endpoint disabled" do
setup do
EventLog.stubs(:splunk_endpoint_enabled?).returns(false)
end

should "not queue job to send event to Splunk endpoint" do
SplunkLogStreamingJob.expects(:perform_later).never
EventLog.record_event(build(:user), EventLog::SUCCESSFUL_LOGIN)
end
end

context "when Splunk endpoint enabled" do
setup do
EventLog.stubs(:splunk_endpoint_enabled?).returns(true)
Expand Down

0 comments on commit c5af367

Please sign in to comment.