From c591ec811d917ec321ea4a4c93152db92ca0b5cd Mon Sep 17 00:00:00 2001 From: Jamie Gaskins Date: Fri, 9 Jul 2021 15:19:37 -0400 Subject: [PATCH] Arrange Datadog Redis integrations more usefully (#14185) This commit solves two problems: 1. Redis cache usage is tracked under `redis-rpush` because they use the same Redis URL and `redis-rpush` overrides `redis`. 2. Sidekiq jobs can enqueue an unbounded number of other Sidekiq jobs. The instrumentation cost alone of enqueuing hundreds of thousands of other Sidekiq jobs can be prohibitive, similar to DEBUG-level logging. This commit wraps it in a conditional so it must be enabled explicitly and can be turned on and off at will without a code change. --- app/lib/forem_stats_drivers/datadog_driver.rb | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/lib/forem_stats_drivers/datadog_driver.rb b/app/lib/forem_stats_drivers/datadog_driver.rb index cb4f7e727..ccde97e34 100644 --- a/app/lib/forem_stats_drivers/datadog_driver.rb +++ b/app/lib/forem_stats_drivers/datadog_driver.rb @@ -19,12 +19,26 @@ module ForemStatsDrivers c.use :httpclient, split_by_domain: false c.use :httprb, split_by_domain: true c.use :rails - c.use :redis, service_name: "redis", describes: { url: ENV["REDIS_URL"] } - c.use :redis, service_name: "redis-rpush", describes: { url: ENV["REDIS_RPUSH_URL"] } - c.use :redis, service_name: "redis-sessions", describes: { url: ENV["REDIS_SESSIONS_URL"] } - c.use :redis, service_name: "redis-sidekiq", describes: { url: ENV["REDIS_SIDEKIQ_URL"] } + c.use :rest_client c.use :sidekiq + + # Multiple Redis integrations to split Redis usage per-instance to + # accommodate having a different Redis instance for each use case. + + c.use :redis, service_name: "redis-rpush", describes: { url: ENV["REDIS_RPUSH_URL"] } + c.use :redis, service_name: "redis-sessions", describes: { url: ENV["REDIS_SESSIONS_URL"] } + + # Sidekiq jobs that spin up thousands of other jobs end up consuming a + # *lot* of memory on instrumentation alone. This env var allows us to + # enable it only when needed. + if ENV["DD_ENABLE_REDIS_SIDEKIQ"] == "true" + c.use :redis, service_name: "redis-sidekiq", describes: { url: ENV["REDIS_SIDEKIQ_URL"] } + end + + # Generic REDIS_URL comes last, allowing it to overwrite any of the + # above when multiple Redis use cases are backed by the same Redis URL. + c.use :redis, service_name: "redis", describes: { url: ENV["REDIS_URL"] } end Datadog::Statsd.new