-
Notifications
You must be signed in to change notification settings - Fork 6
Don't send healthcheck events to AppSignal to save storage #842
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| class FilteredEventSubscriber | ||
| def initialize(subscriber, filter:) | ||
| @subscriber = subscriber | ||
| @filter = filter | ||
| end | ||
|
|
||
| def emit(event) | ||
| @subscriber.emit(event) if @filter.call(event) | ||
| end | ||
| end | ||
|
|
||
| class HealthCheckFilteredEventSubscriber < FilteredEventSubscriber | ||
| def initialize(subscriber) | ||
| filter = ->(event) { event.dig(:payload, :controller) != "Rails::HealthController" } | ||
|
|
||
| super(subscriber, filter:) | ||
| end | ||
| end | ||
|
|
||
| Rails.application.config.to_prepare do | ||
| next unless defined?(Appsignal::Integrations::ActiveSupportEventReporter::Subscriber) | ||
|
|
||
| subscribers = Rails.event.instance_variable_get(:@subscribers) | ||
| original = subscribers.find { it[:subscriber].is_a? Appsignal::Integrations::ActiveSupportEventReporter::Subscriber } | ||
|
|
||
| next unless original | ||
|
|
||
| subscribers.delete original | ||
|
|
||
| filtered = HealthCheckFilteredEventSubscriber.new(original[:subscriber]) | ||
| Rails.event.subscribe(filtered, &original[:filter]) | ||
|
northeastprince marked this conversation as resolved.
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| require "test_helper" | ||
|
|
||
| class HealthCheckEventFilteringTest < ActionDispatch::IntegrationTest | ||
| test "filters out health check request events" do | ||
| with_filtered_event_reporter do | ||
| assert_no_event_reported("action_controller.request_started") do | ||
| get health_check_path | ||
| assert_response :ok | ||
| end | ||
| end | ||
| end | ||
|
|
||
| test "passes through non-health check request events" do | ||
| assert_event_reported("action_controller.request_completed") do | ||
| get root_path | ||
| end | ||
|
northeastprince marked this conversation as resolved.
|
||
| end | ||
|
|
||
| private | ||
|
|
||
| def with_filtered_event_reporter | ||
| original = ActiveSupport.event_reporter | ||
| ActiveSupport.event_reporter = FilteredEventReporter.new(original) | ||
| yield | ||
| ensure | ||
| ActiveSupport.event_reporter = original | ||
| end | ||
|
Comment on lines
+21
to
+27
|
||
|
|
||
| class FilteredEventReporter < SimpleDelegator | ||
| def subscribe(subscriber, &filter) | ||
| super(HealthCheckFilteredEventSubscriber.new(subscriber), &filter) | ||
| end | ||
|
northeastprince marked this conversation as resolved.
|
||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.