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

on_failure callbacks not working as expected #144

Open
adrys-lab opened this issue Mar 7, 2024 · 1 comment
Open

on_failure callbacks not working as expected #144

adrys-lab opened this issue Mar 7, 2024 · 1 comment

Comments

@adrys-lab
Copy link

adrys-lab commented Mar 7, 2024

Hello,

we would like to have better knowledge in datadog logs, about when a Healthcheck fails and understanding what is the reason of such failure.

For that, we have added a new on_failure callback that logs as error the failures, but we don´t see that in our logs.

Additionally, we only see logs for health_check failed configured in config.failure 🤔
And even though we have configured the failures as :error we still see health_check failed as info level 🤔
image

Would you mind to help us find the root cause ??

gems:

health_check (3.1.0)
ruby (3.1.4)
puma (6.3.1)
rails (7.1.3)

healh_check initializer:

# frozen_string_literal: true

require File.expand_path('../../app/lib/redis_client_factory', __dir__)

HealthCheck.setup do |config|
  config.redis_url = RedisClientFactory::REDIS_URL

  config.success = 'Site checked'
  config.failure = 'health_check failed'

  config.include_error_in_response_body = true
  config.log_level = :error

  config.http_status_for_error_text = 503	# Service Unavailable
  config.http_status_for_error_object = 503	# Service Unavailable

  config.standard_checks = %w(
    database
    migrations
    cache
    sidekiq-redis
    shutting-down
    elasticsearch
    site
  )

  config.full_checks = %w(
    database
    migrations
    cache
    sidekiq-redis
    shutting-down
    elasticsearch
    site
  )

  config.add_custom_check('shutting-down') do
    PumaClusterOverride::WorkerStatus.shutting_down? ? 'Shutting down' : ''
  end

  config.on_success do
    trace = Datadog::Tracing.active_trace
    trace.reject!
  end

  config.on_failure do |checks, msg|
    Rails.logger.error do
      {
        event: "healthcheck",
        message: "Healthcheck Failure",
        code: 503,
        args: {
          message: "Failed to perform health checks",
          healthcheck_message: msg,
          checks: checks
        },
        domain: 'web_internals'
      }
    end
  end
end
@ArmandoAssuncao
Copy link

I open a PR fixing: #146

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants