From ed74f2f245c3a4f04fa63eafbed9ca1fa466f96a Mon Sep 17 00:00:00 2001 From: Kirk Haines Date: Wed, 27 Jan 2021 09:25:44 -0700 Subject: [PATCH] Abstract DatadogStatsClient to ForemStatsClient (#12304) * This change abstracts the DatadogStatsClient into a ForemStatsClient. The purpose of this abstraction is to set the foundation for a subsequent PR that will allow one to use New Relic for recording Forem stats, instead of Datadog, if there is a New Relic configuration found. This specific change creates an abstraction layer that can be built upon, without changing any actual default behavior. All specs still pass. * Use delegate instead of explicit methods. * Delegate instead of explicit methods. * Fix the error. * Refactor according to the suggestions in the comments. * Ooops. Stats work better when all of the code is committed. * Removing the alias of count to increment since that was done in error. --- app/controllers/follows_controller.rb | 2 +- .../omniauth_callbacks_controller.rb | 2 +- .../stripe_active_cards_controller.rb | 10 ++--- app/lib/acts_as_forem_stats_driver.rb | 15 +++++++ app/lib/forem_stats_driver.rb | 16 ++++++++ app/lib/forem_stats_drivers/datadog_driver.rb | 19 +++++++++ app/services/authentication/authenticator.rb | 4 +- app/services/edge_cache/bust.rb | 4 +- app/services/edge_cache/bust/nginx.rb | 4 +- app/services/fastly_config/snippets.rb | 2 +- app/services/fastly_config/update.rb | 2 +- app/services/feeds/import.rb | 12 +++--- app/services/github/oauth_client.rb | 2 +- .../loggers/log_worker_queue_stats.rb | 2 +- .../welcome_notification/send.rb | 2 +- app/services/payments/customer.rb | 6 +-- app/services/rate_limit_checker.rb | 2 +- app/services/search/client.rb | 2 +- app/services/twitter_client/client.rb | 2 +- app/workers/data_update_worker.rb | 2 +- .../check_data_update_script_statuses.rb | 2 +- .../record_daily_notifications_worker.rb | 2 +- .../metrics/record_daily_usage_worker.rb | 16 ++++---- .../metrics/record_data_counts_worker.rb | 6 +-- app/workers/moderator/banish_user_worker.rb | 2 +- app/workers/moderator/sink_articles_worker.rb | 2 +- app/workers/users/delete_worker.rb | 2 +- config/initializers/datadog_apm.rb | 13 ------ config/initializers/stats.rb | 1 + ...t_articles_with_duplicate_canonical_url.rb | 4 +- .../worker_retries_exhausted_reporter.rb | 2 +- .../worker_retries_exhausted_reporter_spec.rb | 4 +- spec/requests/stripe_active_cards_spec.rb | 16 ++++---- .../authentication/authenticator_spec.rb | 40 +++++++++---------- spec/services/fastly_config/snippets_spec.rb | 4 +- spec/services/fastly_config/update_spec.rb | 4 +- .../welcome_notification/send_spec.rb | 4 +- spec/services/payments/customer_spec.rb | 20 +++++----- spec/services/rate_limit_checker_spec.rb | 4 +- .../user_logs_in_with_apple_spec.rb | 8 ++-- .../user_logs_in_with_facebook_spec.rb | 8 ++-- .../user_logs_in_with_github_spec.rb | 8 ++-- .../user_logs_in_with_twitter_spec.rb | 8 ++-- spec/workers/data_update_worker_spec.rb | 4 +- .../check_data_update_script_statuses_spec.rb | 6 +-- .../record_daily_notifications_worker_spec.rb | 6 +-- .../metrics/record_daily_usage_worker_spec.rb | 14 +++---- .../metrics/record_data_counts_worker_spec.rb | 8 ++-- 48 files changed, 184 insertions(+), 146 deletions(-) create mode 100644 app/lib/acts_as_forem_stats_driver.rb create mode 100644 app/lib/forem_stats_driver.rb create mode 100644 app/lib/forem_stats_drivers/datadog_driver.rb delete mode 100644 config/initializers/datadog_apm.rb create mode 100644 config/initializers/stats.rb diff --git a/app/controllers/follows_controller.rb b/app/controllers/follows_controller.rb index 1a1c990cb..8c818b122 100644 --- a/app/controllers/follows_controller.rb +++ b/app/controllers/follows_controller.rb @@ -105,7 +105,7 @@ class FollowsController < ApplicationController Notification.send_new_follower_notification(user_follow) if need_notification "followed" rescue ActiveRecord::RecordInvalid - DatadogStatsClient.increment("users.invalid_follow") + ForemStatsClient.increment("users.invalid_follow") "already followed" end diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb index e4fa8af38..1ed892228 100644 --- a/app/controllers/omniauth_callbacks_controller.rb +++ b/app/controllers/omniauth_callbacks_controller.rb @@ -23,7 +23,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController error = request.env["omniauth.error"] class_name = error.present? ? error.class.name : "" - DatadogStatsClient.increment( + ForemStatsClient.increment( "omniauth.failure", tags: [ "class:#{class_name}", diff --git a/app/controllers/stripe_active_cards_controller.rb b/app/controllers/stripe_active_cards_controller.rb index 337072078..2216efa88 100644 --- a/app/controllers/stripe_active_cards_controller.rb +++ b/app/controllers/stripe_active_cards_controller.rb @@ -14,13 +14,13 @@ class StripeActiveCardsController < ApplicationController flash[:settings_notice] = "Your billing information has been updated" audit_log("add") else - DatadogStatsClient.increment("stripe.errors", tags: ["action:create_card", "user_id:#{current_user.id}"]) + ForemStatsClient.increment("stripe.errors", tags: ["action:create_card", "user_id:#{current_user.id}"]) flash[:error] = "There was a problem updating your billing info." end redirect_to user_settings_path(:billing) rescue Payments::CardError, Payments::InvalidRequestError => e - DatadogStatsClient.increment("stripe.errors", tags: ["action:create_card", "user_id:#{current_user.id}"]) + ForemStatsClient.increment("stripe.errors", tags: ["action:create_card", "user_id:#{current_user.id}"]) redirect_to user_settings_path(:billing), flash: { error: e.message } end @@ -36,13 +36,13 @@ class StripeActiveCardsController < ApplicationController flash[:settings_notice] = "Your billing information has been updated" audit_log("update") else - DatadogStatsClient.increment("stripe.errors", tags: ["action:update_card", "user_id:#{current_user.id}"]) + ForemStatsClient.increment("stripe.errors", tags: ["action:update_card", "user_id:#{current_user.id}"]) flash[:error] = "There was a problem updating your billing info." end redirect_to user_settings_path(:billing) rescue Payments::CardError, Payments::InvalidRequestError => e - DatadogStatsClient.increment("stripe.errors", tags: ["action:update_card", "user_id:#{current_user.id}"]) + ForemStatsClient.increment("stripe.errors", tags: ["action:update_card", "user_id:#{current_user.id}"]) redirect_to user_settings_path(:billing), flash: { error: e.message } end @@ -65,7 +65,7 @@ class StripeActiveCardsController < ApplicationController redirect_to user_settings_path(:billing) rescue Payments::InvalidRequestError => e - DatadogStatsClient.increment("stripe.errors") + ForemStatsClient.increment("stripe.errors") redirect_to user_settings_path(:billing), flash: { error: e.message } end diff --git a/app/lib/acts_as_forem_stats_driver.rb b/app/lib/acts_as_forem_stats_driver.rb new file mode 100644 index 000000000..7a89aa47d --- /dev/null +++ b/app/lib/acts_as_forem_stats_driver.rb @@ -0,0 +1,15 @@ +module ActsAsForemStatsDriver + extend ActiveSupport::Concern + + class_methods do + def setup_driver + define_method(:initialize) do + @driver = yield + end + end + end + + included do + delegate :count, :increment, :time, :gauge, to: :@driver + end +end diff --git a/app/lib/forem_stats_driver.rb b/app/lib/forem_stats_driver.rb new file mode 100644 index 000000000..66aef96cf --- /dev/null +++ b/app/lib/forem_stats_driver.rb @@ -0,0 +1,16 @@ +class ForemStatsDriver + def initialize(*_args) + @driver = select_driver.new + end + + delegate(:count, :increment, :time, :gauge, to: :@driver) + + private + + def select_driver + # Currently, this only supports the default Datadog driver. + # Logic will be added here for selecting the correct driver based on + # the existence of configuration files for the desired stats recipient. + ForemStatsDrivers::DatadogDriver + end +end diff --git a/app/lib/forem_stats_drivers/datadog_driver.rb b/app/lib/forem_stats_drivers/datadog_driver.rb new file mode 100644 index 000000000..9279a9635 --- /dev/null +++ b/app/lib/forem_stats_drivers/datadog_driver.rb @@ -0,0 +1,19 @@ +module ForemStatsDrivers + class DatadogDriver + include ActsAsForemStatsDriver + setup_driver do + Datadog.configure do |c| + c.tracer env: Rails.env + c.tracer enabled: ENV["DD_API_KEY"].present? + c.tracer partial_flush: true + c.tracer priority_sampling: true + c.use :elasticsearch + c.use :sidekiq + c.use :redis + c.use :rails + c.use :http + end + Datadog::Statsd.new + end + end +end diff --git a/app/services/authentication/authenticator.rb b/app/services/authentication/authenticator.rb index a7449e2a2..ad8b813a2 100644 --- a/app/services/authentication/authenticator.rb +++ b/app/services/authentication/authenticator.rb @@ -59,7 +59,7 @@ module Authentication if log_to_datadog # Notify DataDog if a new identity was successfully created. - DatadogStatsClient.increment("identity.created", tags: ["provider:#{id_provider}"]) + ForemStatsClient.increment("identity.created", tags: ["provider:#{id_provider}"]) end # Return the successfully-authed used from the transaction. @@ -67,7 +67,7 @@ module Authentication rescue StandardError => e # Notify DataDog if something goes wrong in the transaction, # and then ensure that we re-raise and bubble up the error. - DatadogStatsClient.increment("identity.errors", tags: ["error:#{e.class}", "message:#{e.message}"]) + ForemStatsClient.increment("identity.errors", tags: ["error:#{e.class}", "message:#{e.message}"]) raise e end diff --git a/app/services/edge_cache/bust.rb b/app/services/edge_cache/bust.rb index 053823234..1d6b8dc1d 100644 --- a/app/services/edge_cache/bust.rb +++ b/app/services/edge_cache/bust.rb @@ -25,8 +25,8 @@ module EdgeCache true else Rails.logger.warn("#{provider_class} cannot be used without a #call implementation!") - DatadogStatsClient.increment("edgecache_bust.invalid_provider_class", - tags: ["provider_class:#{provider_class}"]) + ForemStatsClient.increment("edgecache_bust.invalid_provider_class", + tags: ["provider_class:#{provider_class}"]) false end end diff --git a/app/services/edge_cache/bust/nginx.rb b/app/services/edge_cache/bust/nginx.rb index 6453f2f1a..10630cb6c 100644 --- a/app/services/edge_cache/bust/nginx.rb +++ b/app/services/edge_cache/bust/nginx.rb @@ -29,8 +29,8 @@ module EdgeCache # If we can't connect to OpenResty, alert ourselves that # it is unavailable and return false. Rails.logger.error("Could not connect to OpenResty via #{ApplicationConfig['OPENRESTY_URL']}!") - DatadogStatsClient.increment("edgecache_bust.service_unavailable", - tags: ["path:#{ApplicationConfig['OPENRESTY_URL']}"]) + ForemStatsClient.increment("edgecache_bust.service_unavailable", + tags: ["path:#{ApplicationConfig['OPENRESTY_URL']}"]) false end end diff --git a/app/services/fastly_config/snippets.rb b/app/services/fastly_config/snippets.rb index 6d9ba023b..b449fa014 100644 --- a/app/services/fastly_config/snippets.rb +++ b/app/services/fastly_config/snippets.rb @@ -56,7 +56,7 @@ module FastlyConfig "new_version:#{new_version.number}", ] - DatadogStatsClient.increment("fastly.snippets", tags: tags) + ForemStatsClient.increment("fastly.snippets", tags: tags) end end end diff --git a/app/services/fastly_config/update.rb b/app/services/fastly_config/update.rb index 64f7720ee..de743cf5a 100644 --- a/app/services/fastly_config/update.rb +++ b/app/services/fastly_config/update.rb @@ -47,7 +47,7 @@ module FastlyConfig "configs_updated:#{configs.join(', ')}", ] - DatadogStatsClient.increment("fastly.update", tags: tags) + ForemStatsClient.increment("fastly.update", tags: tags) end def validate_configs(configs) diff --git a/app/services/feeds/import.rb b/app/services/feeds/import.rb index bac4013b4..204a427b6 100644 --- a/app/services/feeds/import.rb +++ b/app/services/feeds/import.rb @@ -21,10 +21,10 @@ module Feeds users.in_batches(of: users_batch_size) do |batch_of_users| feeds_per_user_id = fetch_feeds(batch_of_users) - DatadogStatsClient.count("feeds::import::fetch_feeds.count", feeds_per_user_id.length) + ForemStatsClient.count("feeds::import::fetch_feeds.count", feeds_per_user_id.length) feedjira_objects = parse_feeds(feeds_per_user_id) - DatadogStatsClient.count("feeds::import::parse_feeds.count", feedjira_objects.length) + ForemStatsClient.count("feeds::import::parse_feeds.count", feedjira_objects.length) # NOTE: doing this sequentially to avoid locking problems with the DB # and unnecessary conflicts @@ -33,7 +33,7 @@ module Feeds # only actually uses feed.url user = batch_of_users.detect { |u| u.id == user_id } - DatadogStatsClient.time("feeds::import::create_articles_from_user_feed", tags: ["user_id:#{user_id}"]) do + ForemStatsClient.time("feeds::import::create_articles_from_user_feed", tags: ["user_id:#{user_id}"]) do create_articles_from_user_feed(user, feed) end end @@ -46,7 +46,7 @@ module Feeds batch_of_users.update_all(feed_fetched_at: Time.current) end - DatadogStatsClient.count("feeds::import::articles.count", total_articles_count) + ForemStatsClient.count("feeds::import::articles.count", total_articles_count) total_articles_count end @@ -70,7 +70,7 @@ module Feeds cleaned_url = url.to_s.strip next if cleaned_url.blank? - response = DatadogStatsClient.time("feeds::import::fetch_feed", tags: ["user_id:#{user_id}", "url:#{url}"]) do + response = ForemStatsClient.time("feeds::import::fetch_feed", tags: ["user_id:#{user_id}", "url:#{url}"]) do HTTParty.get(cleaned_url, timeout: 10) end @@ -97,7 +97,7 @@ module Feeds # TODO: put this in separate service object def parse_feeds(feeds_per_user_id) result = Parallel.map(feeds_per_user_id, in_threads: num_parsers) do |user_id, feed_xml| - parsed_feed = DatadogStatsClient.time("feeds::import::parse_feed", tags: ["user_id:#{user_id}"]) do + parsed_feed = ForemStatsClient.time("feeds::import::parse_feed", tags: ["user_id:#{user_id}"]) do Feedjira.parse(feed_xml) end diff --git a/app/services/github/oauth_client.rb b/app/services/github/oauth_client.rb index 388051c0f..1cdd53280 100644 --- a/app/services/github/oauth_client.rb +++ b/app/services/github/oauth_client.rb @@ -73,7 +73,7 @@ module Github Honeycomb.add_field("github.result", "error") Honeycomb.add_field("github.error", class_name) - DatadogStatsClient.increment( + ForemStatsClient.increment( "github.errors", tags: ["error:#{class_name}", "message:#{exception.message}"], ) diff --git a/app/services/loggers/log_worker_queue_stats.rb b/app/services/loggers/log_worker_queue_stats.rb index 1f8eaa304..76747816d 100644 --- a/app/services/loggers/log_worker_queue_stats.rb +++ b/app/services/loggers/log_worker_queue_stats.rb @@ -27,7 +27,7 @@ module Loggers end def log_to_datadog(metric_name, value, tags = []) - DatadogStatsClient.gauge(metric_name, value, tags: tags) + ForemStatsClient.gauge(metric_name, value, tags: tags) end end end diff --git a/app/services/notifications/welcome_notification/send.rb b/app/services/notifications/welcome_notification/send.rb index 5a34c7ecc..34af72b32 100644 --- a/app/services/notifications/welcome_notification/send.rb +++ b/app/services/notifications/welcome_notification/send.rb @@ -39,7 +39,7 @@ module Notifications attr_reader :receiver_id, :welcome_broadcast def log_to_datadog - DatadogStatsClient.increment( + ForemStatsClient.increment( "notifications.welcome", tags: ["user_id:#{receiver_id}", "title:#{welcome_broadcast.title}"], ) diff --git a/app/services/payments/customer.rb b/app/services/payments/customer.rb index d5317cdbe..56fdbaf2a 100644 --- a/app/services/payments/customer.rb +++ b/app/services/payments/customer.rb @@ -65,14 +65,14 @@ module Payments def request yield rescue Stripe::InvalidRequestError => e - DatadogStatsClient.increment("stripe.errors", tags: ["error:InvalidRequestError"]) + ForemStatsClient.increment("stripe.errors", tags: ["error:InvalidRequestError"]) raise InvalidRequestError, e.message rescue Stripe::CardError => e - DatadogStatsClient.increment("stripe.errors", tags: ["error:CardError"]) + ForemStatsClient.increment("stripe.errors", tags: ["error:CardError"]) raise CardError, e.message rescue Stripe::StripeError => e Honeybadger.notify(e) - DatadogStatsClient.increment("stripe.errors", tags: ["error:StripeError"]) + ForemStatsClient.increment("stripe.errors", tags: ["error:StripeError"]) raise PaymentsError, e.message end end diff --git a/app/services/rate_limit_checker.rb b/app/services/rate_limit_checker.rb index b7fa8f5ef..2c186c35b 100644 --- a/app/services/rate_limit_checker.rb +++ b/app/services/rate_limit_checker.rb @@ -110,6 +110,6 @@ class RateLimitChecker end def log_to_datadog - DatadogStatsClient.increment("rate_limit.limit_reached", tags: ["user:#{user.id}", "action:#{action}"]) + ForemStatsClient.increment("rate_limit.limit_reached", tags: ["user:#{user.id}", "action:#{action}"]) end end diff --git a/app/services/search/client.rb b/app/services/search/client.rb index a73852b7d..985ea3b11 100644 --- a/app/services/search/client.rb +++ b/app/services/search/client.rb @@ -48,7 +48,7 @@ module Search def record_error(error_message, class_name) Honeycomb.add_field("elasticsearch.result", "error") Honeycomb.add_field("elasticsearch.error", class_name) - DatadogStatsClient.increment("elasticsearch.errors", tags: ["error:#{class_name}", "message:#{error_message}"]) + ForemStatsClient.increment("elasticsearch.errors", tags: ["error:#{class_name}", "message:#{error_message}"]) end def target diff --git a/app/services/twitter_client/client.rb b/app/services/twitter_client/client.rb index 2e39bd80d..c5c5d0fa8 100644 --- a/app/services/twitter_client/client.rb +++ b/app/services/twitter_client/client.rb @@ -31,7 +31,7 @@ module TwitterClient Honeycomb.add_field("twitter.result", "error") Honeycomb.add_field("twitter.error", class_name) - DatadogStatsClient.increment( + ForemStatsClient.increment( "twitter.errors", tags: ["error:#{class_name}", "message:#{exception.message}"], ) diff --git a/app/workers/data_update_worker.rb b/app/workers/data_update_worker.rb index 9786789b9..baecef3b0 100644 --- a/app/workers/data_update_worker.rb +++ b/app/workers/data_update_worker.rb @@ -37,6 +37,6 @@ class DataUpdateWorker "time=#{Time.current.rfc3339}, script=#{file_name}, status=#{status}", ) - DatadogStatsClient.increment("data_update_scripts.status", tags: ["status:#{status}", "script_name:#{file_name}"]) + ForemStatsClient.increment("data_update_scripts.status", tags: ["status:#{status}", "script_name:#{file_name}"]) end end diff --git a/app/workers/metrics/check_data_update_script_statuses.rb b/app/workers/metrics/check_data_update_script_statuses.rb index b3da8dd6c..7b87178e3 100644 --- a/app/workers/metrics/check_data_update_script_statuses.rb +++ b/app/workers/metrics/check_data_update_script_statuses.rb @@ -6,7 +6,7 @@ module Metrics def perform failed_scripts = DataUpdateScript.failed.where(created_at: 1.day.ago..Time.current) failed_scripts.find_each do |script| - DatadogStatsClient.count( + ForemStatsClient.count( "data_update_scripts.failures", 1, tags: ["file_name:#{script.file_name}"], diff --git a/app/workers/metrics/record_daily_notifications_worker.rb b/app/workers/metrics/record_daily_notifications_worker.rb index 9dfcc3120..4dc5d9e79 100644 --- a/app/workers/metrics/record_daily_notifications_worker.rb +++ b/app/workers/metrics/record_daily_notifications_worker.rb @@ -23,7 +23,7 @@ module Metrics .where("time > ?", 1.day.ago) .where("properties->>'title' = ?", title) - DatadogStatsClient.count( + ForemStatsClient.count( "ahoy_events", event.size, tags: ["title:#{title}"], diff --git a/app/workers/metrics/record_daily_usage_worker.rb b/app/workers/metrics/record_daily_usage_worker.rb index a0f3a1111..10f65dd27 100644 --- a/app/workers/metrics/record_daily_usage_worker.rb +++ b/app/workers/metrics/record_daily_usage_worker.rb @@ -6,7 +6,7 @@ module Metrics def perform # Articles published in the past 24 hours with at least 15 "score" (positive/negative reactions) articles_min_15_score_past_24h = Article.published.where("score >= ? AND published_at > ?", 15, 1.day.ago).size - DatadogStatsClient.count( + ForemStatsClient.count( "articles.min_15_score_past_24h", articles_min_15_score_past_24h, tags: ["resource:articles"], @@ -16,7 +16,7 @@ module Metrics articles_min_15_comment_score_past_24h = Article.published .where("comment_score >= ? AND published_at > ?", 15, 1.day.ago) .size - DatadogStatsClient.count( + ForemStatsClient.count( "articles.min_15_comment_score_past_24h", articles_min_15_comment_score_past_24h, tags: ["resource:articles"], @@ -24,11 +24,11 @@ module Metrics # Articles published in the past 24 which were that user's first article first_articles_past_24h = Article.where(nth_published_by_author: 1).where("published_at > ?", 1.day.ago).size - DatadogStatsClient.count("articles.first_past_24h", first_articles_past_24h, tags: ["resource:articles"]) + ForemStatsClient.count("articles.first_past_24h", first_articles_past_24h, tags: ["resource:articles"]) # Users who signed up in the past 24 hours who have made at least 1 comment so far new_users_min_1_comment_past_24h = User.where("comments_count >= ? AND registered_at > ?", 1, 24.hours.ago).size - DatadogStatsClient.count( + ForemStatsClient.count( "users.new_min_1_comment_past_24h", new_users_min_1_comment_past_24h, tags: ["resource:users"], @@ -36,12 +36,12 @@ module Metrics # Total negative reactions in the past 24 hours negative_reactions_past_24h = Reaction.where("points < 0").where("created_at > ?", 1.day.ago).size - DatadogStatsClient.count("reactions.negative_past_24h", negative_reactions_past_24h, tags: ["resource:reactions"]) + ForemStatsClient.count("reactions.negative_past_24h", negative_reactions_past_24h, tags: ["resource:reactions"]) # Total abuse (etc.) reports in the past 24 hours categories = ["spam", "other", "rude or vulgar", "harassment"] reports_past_24_hours = FeedbackMessage.where(category: categories).where("created_at > ?", 1.day.ago).size - DatadogStatsClient.count( + ForemStatsClient.count( "feedback_messages.reports_past_24_hours", reports_past_24_hours, tags: ["resource:feedback_messages"], @@ -76,8 +76,8 @@ module Metrics distinct_user_values = user_ids_by_day.flatten.group_by(&:itself).transform_values(&:count).values distinct_counts = distinct_user_values.group_by(&:itself).transform_values(&:count) distinct_counts.each_key do |key| - DatadogStatsClient.count("users.active_days_past_week", distinct_counts[key], - tags: ["resource:users", "group:#{group}", "day_count:#{key}"]) + ForemStatsClient.count("users.active_days_past_week", distinct_counts[key], + tags: ["resource:users", "group:#{group}", "day_count:#{key}"]) end end end diff --git a/app/workers/metrics/record_data_counts_worker.rb b/app/workers/metrics/record_data_counts_worker.rb index 9155a8910..916d5e04f 100644 --- a/app/workers/metrics/record_data_counts_worker.rb +++ b/app/workers/metrics/record_data_counts_worker.rb @@ -13,7 +13,7 @@ module Metrics end Rails.logger.info(message: "db_table_size", table_info: { table_name: model.table_name, table_size: db_count }) - DatadogStatsClient.gauge("postgres.db_table_size", db_count, tags: ["table_name:#{model.table_name}"]) + ForemStatsClient.gauge("postgres.db_table_size", db_count, tags: ["table_name:#{model.table_name}"]) next unless model.const_defined?(:SEARCH_CLASS) @@ -22,8 +22,8 @@ module Metrics else model::SEARCH_CLASS.document_count end - DatadogStatsClient.gauge("elasticsearch.document_count", document_count, - tags: ["table_name:#{model.table_name}"]) + ForemStatsClient.gauge("elasticsearch.document_count", document_count, + tags: ["table_name:#{model.table_name}"]) end end end diff --git a/app/workers/moderator/banish_user_worker.rb b/app/workers/moderator/banish_user_worker.rb index 358f85716..7a0a6251e 100644 --- a/app/workers/moderator/banish_user_worker.rb +++ b/app/workers/moderator/banish_user_worker.rb @@ -9,7 +9,7 @@ module Moderator admin = User.find(admin_id) Moderator::BanishUser.call(admin: admin, user: abuser) rescue StandardError => e - DatadogStatsClient.count("moderators.banishuser", 1, tags: ["action:failed", "user_id:#{abuser.id}"]) + ForemStatsClient.count("moderators.banishuser", 1, tags: ["action:failed", "user_id:#{abuser.id}"]) Honeybadger.notify(e) end end diff --git a/app/workers/moderator/sink_articles_worker.rb b/app/workers/moderator/sink_articles_worker.rb index 6bebe2b7d..7ac48d9ce 100644 --- a/app/workers/moderator/sink_articles_worker.rb +++ b/app/workers/moderator/sink_articles_worker.rb @@ -13,7 +13,7 @@ module Moderator new_score = reactions.sum(:points) + Reaction.where(reactable: user).sum(:points) articles.update_all(score: new_score) rescue StandardError => e - DatadogStatsClient.count("moderators.sink", 1, tags: ["action:failed", "user_id:#{user.id}"]) + ForemStatsClient.count("moderators.sink", 1, tags: ["action:failed", "user_id:#{user.id}"]) Honeybadger.notify(e) end end diff --git a/app/workers/users/delete_worker.rb b/app/workers/users/delete_worker.rb index a4c0789b0..02fdc45ee 100644 --- a/app/workers/users/delete_worker.rb +++ b/app/workers/users/delete_worker.rb @@ -19,7 +19,7 @@ module Users # whole object NotifyMailer.with(name: user.name, email: user.email).account_deleted_email.deliver_now rescue StandardError => e - DatadogStatsClient.count("users.delete", 1, tags: ["action:failed", "user_id:#{user.id}"]) + ForemStatsClient.count("users.delete", 1, tags: ["action:failed", "user_id:#{user.id}"]) Honeybadger.context({ user_id: user.id }) Honeybadger.notify(e) end diff --git a/config/initializers/datadog_apm.rb b/config/initializers/datadog_apm.rb deleted file mode 100644 index 28bcebb38..000000000 --- a/config/initializers/datadog_apm.rb +++ /dev/null @@ -1,13 +0,0 @@ -Datadog.configure do |c| - c.tracer env: Rails.env - c.tracer enabled: ENV["DD_API_KEY"].present? - c.tracer partial_flush: true - c.tracer priority_sampling: true - c.use :elasticsearch - c.use :sidekiq - c.use :redis - c.use :rails - c.use :http -end - -DatadogStatsClient = Datadog::Statsd.new diff --git a/config/initializers/stats.rb b/config/initializers/stats.rb new file mode 100644 index 000000000..e035a77bc --- /dev/null +++ b/config/initializers/stats.rb @@ -0,0 +1 @@ +ForemStatsClient = ForemStatsDriver.new diff --git a/lib/data_update_scripts/20200901085230_remove_draft_articles_with_duplicate_canonical_url.rb b/lib/data_update_scripts/20200901085230_remove_draft_articles_with_duplicate_canonical_url.rb index d5ec39206..60d580e0b 100644 --- a/lib/data_update_scripts/20200901085230_remove_draft_articles_with_duplicate_canonical_url.rb +++ b/lib/data_update_scripts/20200901085230_remove_draft_articles_with_duplicate_canonical_url.rb @@ -31,7 +31,7 @@ module DataUpdateScripts # Sending IDs of deleted articles to Datadog result.map { |row| row["id"] }.in_groups_of(1000) do |ids| - DatadogStatsClient.event( + ForemStatsClient.event( "DataUpdateScripts::RemoveDraftArticlesWithDuplicateCanonicalUrl", "deleted draft articles with the same canonical_url and same body_markdown", tags: ids, @@ -67,7 +67,7 @@ module DataUpdateScripts # Sending IDs of deleted articles to Datadog result.map { |row| row["id"] }.in_groups_of(1000) do |ids| - DatadogStatsClient.event( + ForemStatsClient.event( "DataUpdateScripts::RemoveDraftArticlesWithDuplicateCanonicalUrl", "deleted draft articles with the same canonical_url and different body_markdown", tags: ids, diff --git a/lib/sidekiq/worker_retries_exhausted_reporter.rb b/lib/sidekiq/worker_retries_exhausted_reporter.rb index d529832cd..9820e70e9 100644 --- a/lib/sidekiq/worker_retries_exhausted_reporter.rb +++ b/lib/sidekiq/worker_retries_exhausted_reporter.rb @@ -11,7 +11,7 @@ module Sidekiq "retry:#{job['retry']}", "retry_count:#{job['retry_count']}", ] - DatadogStatsClient.increment( + ForemStatsClient.increment( "sidekiq.worker.retries_exhausted", tags: tags ) end diff --git a/spec/lib/sidekiq/worker_retries_exhausted_reporter_spec.rb b/spec/lib/sidekiq/worker_retries_exhausted_reporter_spec.rb index c1cbaad9f..2165472ba 100644 --- a/spec/lib/sidekiq/worker_retries_exhausted_reporter_spec.rb +++ b/spec/lib/sidekiq/worker_retries_exhausted_reporter_spec.rb @@ -4,9 +4,9 @@ describe Sidekiq::WorkerRetriesExhaustedReporter, type: :labor do let(:job_hash) { { "class" => "TempWorker", "retry" => 15, "retry_count" => 1, "jid" => "123abc" } } it "increments worker retries exhausted in Datadog" do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) described_class.report_final_failure(job_hash) - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "sidekiq.worker.retries_exhausted", tags: [ "action:dead", diff --git a/spec/requests/stripe_active_cards_spec.rb b/spec/requests/stripe_active_cards_spec.rb index 2693d86e2..409c5f65c 100644 --- a/spec/requests/stripe_active_cards_spec.rb +++ b/spec/requests/stripe_active_cards_spec.rb @@ -50,7 +50,7 @@ RSpec.describe "StripeActiveCards", type: :request do end it "increments sidekiq.errors in Datadog on failure" do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) invalid_error = Stripe::InvalidRequestError.new("message", "param") allow(Stripe::Customer).to receive(:create).and_raise(invalid_error) @@ -59,7 +59,7 @@ RSpec.describe "StripeActiveCards", type: :request do expect(flash[:error]).to eq(invalid_error.message) tags = hash_including(tags: array_including("error:InvalidRequestError")) - expect(DatadogStatsClient).to have_received(:increment).with("stripe.errors", tags) + expect(ForemStatsClient).to have_received(:increment).with("stripe.errors", tags) end it "updates the user's updated_at" do @@ -73,13 +73,13 @@ RSpec.describe "StripeActiveCards", type: :request do end it "increments sidekiq.errors.new_subscription in Datadog on failure" do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) invalid_error = Stripe::InvalidRequestError.new(nil, nil) allow(Stripe::Customer).to receive(:create).and_raise(invalid_error) post "/stripe_active_cards", params: { stripe_token: stripe_helper.generate_card_token } tags = hash_including(tags: array_including("action:create_card", "user_id:#{user.id}")) - expect(DatadogStatsClient).to have_received(:increment).with("stripe.errors", tags) + expect(ForemStatsClient).to have_received(:increment).with("stripe.errors", tags) end end @@ -124,7 +124,7 @@ RSpec.describe "StripeActiveCards", type: :request do _, source = create_user_with_card(user, card_token) original_card_id = source.id - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) card_error = Stripe::CardError.new("message", "param") allow(Stripe::Customer).to receive(:retrieve).and_raise(card_error) @@ -133,7 +133,7 @@ RSpec.describe "StripeActiveCards", type: :request do expect(flash[:error]).to eq(card_error.message) tags = hash_including(tags: array_including("error:CardError")) - expect(DatadogStatsClient).to have_received(:increment).with("stripe.errors", tags) + expect(ForemStatsClient).to have_received(:increment).with("stripe.errors", tags) end it "updates the user's updated_at" do @@ -151,7 +151,7 @@ RSpec.describe "StripeActiveCards", type: :request do _, source = create_user_with_card(user, card_token) original_card_id = source.id - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) card_error = Stripe::CardError.new("message", "param") allow(Stripe::Customer).to receive(:retrieve).and_raise(card_error) @@ -159,7 +159,7 @@ RSpec.describe "StripeActiveCards", type: :request do expect(response).to redirect_to(user_settings_path(:billing)) expect(flash[:error]).to eq(card_error.message) tags = hash_including(tags: array_including("action:update_card", "user_id:#{user.id}")) - expect(DatadogStatsClient).to have_received(:increment).with("stripe.errors", tags) + expect(ForemStatsClient).to have_received(:increment).with("stripe.errors", tags) end end diff --git a/spec/services/authentication/authenticator_spec.rb b/spec/services/authentication/authenticator_spec.rb index 2fba98602..634de767a 100644 --- a/spec/services/authentication/authenticator_spec.rb +++ b/spec/services/authentication/authenticator_spec.rb @@ -83,10 +83,10 @@ RSpec.describe Authentication::Authenticator, type: :service do end it "records successful identity creation metric" do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) service.call - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "identity.created", tags: ["provider:apple"] ) end @@ -122,10 +122,10 @@ RSpec.describe Authentication::Authenticator, type: :service do end it "does not record an identity creation metric" do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) service.call - expect(DatadogStatsClient).not_to have_received(:increment) + expect(ForemStatsClient).not_to have_received(:increment) end it "updates the proper data from the auth payload" do @@ -281,10 +281,10 @@ RSpec.describe Authentication::Authenticator, type: :service do end it "records successful identity creation metric" do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) service.call - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "identity.created", tags: ["provider:github"] ) end @@ -293,12 +293,12 @@ RSpec.describe Authentication::Authenticator, type: :service do # rubocop:disable RSpec/AnyInstance allow_any_instance_of(Identity).to receive(:save!).and_raise(StandardError) # rubocop:enable RSpec/AnyInstance - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) expect { described_class.call(auth_payload) }.to raise_error(StandardError) tags = hash_including(tags: array_including("error:StandardError")) - expect(DatadogStatsClient).to have_received(:increment).with("identity.errors", tags) + expect(ForemStatsClient).to have_received(:increment).with("identity.errors", tags) end end @@ -332,10 +332,10 @@ RSpec.describe Authentication::Authenticator, type: :service do end it "does not record an identity creation metric" do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) service.call - expect(DatadogStatsClient).not_to have_received(:increment) + expect(ForemStatsClient).not_to have_received(:increment) end it "sets remember_me for the existing user" do @@ -391,12 +391,12 @@ RSpec.describe Authentication::Authenticator, type: :service do # rubocop:disable RSpec/AnyInstance allow_any_instance_of(Identity).to receive(:save!).and_raise(StandardError) # rubocop:enable RSpec/AnyInstance - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) expect { described_class.call(auth_payload) }.to raise_error(StandardError) tags = hash_including(tags: array_including("error:StandardError")) - expect(DatadogStatsClient).to have_received(:increment).with("identity.errors", tags) + expect(ForemStatsClient).to have_received(:increment).with("identity.errors", tags) end end @@ -492,10 +492,10 @@ RSpec.describe Authentication::Authenticator, type: :service do end it "records successful identity creation metric" do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) service.call - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "identity.created", tags: ["provider:facebook"] ) end @@ -504,12 +504,12 @@ RSpec.describe Authentication::Authenticator, type: :service do # rubocop:disable RSpec/AnyInstance allow_any_instance_of(Identity).to receive(:save!).and_raise(StandardError) # rubocop:enable RSpec/AnyInstance - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) expect { described_class.call(auth_payload) }.to raise_error(StandardError) tags = hash_including(tags: array_including("error:StandardError")) - expect(DatadogStatsClient).to have_received(:increment).with("identity.errors", tags) + expect(ForemStatsClient).to have_received(:increment).with("identity.errors", tags) end end end @@ -584,10 +584,10 @@ RSpec.describe Authentication::Authenticator, type: :service do end it "records successful identity creation metric" do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) service.call - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "identity.created", tags: ["provider:twitter"] ) end @@ -623,10 +623,10 @@ RSpec.describe Authentication::Authenticator, type: :service do end it "does not record an identity creation metric" do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) service.call - expect(DatadogStatsClient).not_to have_received(:increment) + expect(ForemStatsClient).not_to have_received(:increment) end it "updates the proper data from the auth payload" do diff --git a/spec/services/fastly_config/snippets_spec.rb b/spec/services/fastly_config/snippets_spec.rb index df3017303..27cba982a 100644 --- a/spec/services/fastly_config/snippets_spec.rb +++ b/spec/services/fastly_config/snippets_spec.rb @@ -35,7 +35,7 @@ RSpec.describe FastlyConfig::Snippets, type: :service do end it "logs success messages" do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) allow(fastly_version).to receive(:number).and_return(1) allow(fastly).to receive(:get_snippet).and_return(fastly_snippet) allow(fastly_snippet).to receive(:content).and_return("test") @@ -48,7 +48,7 @@ RSpec.describe FastlyConfig::Snippets, type: :service do tags = hash_including(tags: array_including("snippet_update_type:update", "snippet_name:test", "new_version:#{fastly_version.number}")) - expect(DatadogStatsClient).to have_received(:increment).with("fastly.snippets", tags).at_least(:once) + expect(ForemStatsClient).to have_received(:increment).with("fastly.snippets", tags).at_least(:once) end end end diff --git a/spec/services/fastly_config/update_spec.rb b/spec/services/fastly_config/update_spec.rb index 8c78efc46..f231296da 100644 --- a/spec/services/fastly_config/update_spec.rb +++ b/spec/services/fastly_config/update_spec.rb @@ -53,7 +53,7 @@ RSpec.describe FastlyConfig::Update, type: :service do it "logs success messages" do allow(Rails.logger).to receive(:info) - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) stub_const("#{described_class}::FASTLY_CONFIGS", ["Snippets"]) snippet_handler = instance_double FastlyConfig::Snippets @@ -66,7 +66,7 @@ RSpec.describe FastlyConfig::Update, type: :service do tags = hash_including(tags: array_including("new_version:#{fastly_version.number}", "configs_updated:Snippets")) - expect(DatadogStatsClient).to have_received(:increment).with("fastly.update", tags) + expect(ForemStatsClient).to have_received(:increment).with("fastly.update", tags) end end end diff --git a/spec/services/notifications/welcome_notification/send_spec.rb b/spec/services/notifications/welcome_notification/send_spec.rb index c108e3635..a4164e99b 100644 --- a/spec/services/notifications/welcome_notification/send_spec.rb +++ b/spec/services/notifications/welcome_notification/send_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Notifications::WelcomeNotification::Send, type: :service do before do allow(User).to receive(:mascot_account).and_return(create(:user)) - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) end it "creates a new welcome notification", :aggregate_failures do @@ -26,7 +26,7 @@ RSpec.describe Notifications::WelcomeNotification::Send, type: :service do welcome_notification = Notification.find_by(notifiable_id: welcome_broadcast.id) tags = ["user_id:#{welcome_notification.user_id}", "title:#{welcome_notification.notifiable.title}"] - expect(DatadogStatsClient).to have_received(:increment).with("notifications.welcome", tags: tags) + expect(ForemStatsClient).to have_received(:increment).with("notifications.welcome", tags: tags) end end end diff --git a/spec/services/payments/customer_spec.rb b/spec/services/payments/customer_spec.rb index 82ab63e04..c74b55255 100644 --- a/spec/services/payments/customer_spec.rb +++ b/spec/services/payments/customer_spec.rb @@ -21,11 +21,11 @@ RSpec.describe Payments::Customer, type: :service do end it "increments stripe.errors if the customer does not exist" do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) expect { described_class.get("foobar") }.to raise_error(Payments::InvalidRequestError) tags = hash_including(tags: array_including("error:InvalidRequestError")) - expect(DatadogStatsClient).to have_received(:increment).with("stripe.errors", tags) + expect(ForemStatsClient).to have_received(:increment).with("stripe.errors", tags) end it "raises Payments::PaymentsError for any other known error" do @@ -34,12 +34,12 @@ RSpec.describe Payments::Customer, type: :service do end it "increments stripe.errors for any other known error" do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) allow(Stripe::Customer).to receive(:retrieve).with("foobar").and_raise(Stripe::StripeError) expect { described_class.get("foobar") }.to raise_error(Payments::PaymentsError) tags = hash_including(tags: array_including("error:StripeError")) - expect(DatadogStatsClient).to have_received(:increment).with("stripe.errors", tags) + expect(ForemStatsClient).to have_received(:increment).with("stripe.errors", tags) end end @@ -76,11 +76,11 @@ RSpec.describe Payments::Customer, type: :service do it "increments stripe.errors if anything in the params is invalid" do error = Stripe::InvalidRequestError.new("message", :token) allow(Stripe::Customer).to receive(:create_source).and_raise(error) - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) expect { described_class.create_source("customer_id", "token") }.to raise_error(Payments::InvalidRequestError) tags = hash_including(tags: array_including("error:InvalidRequestError")) - expect(DatadogStatsClient).to have_received(:increment).with("stripe.errors", tags) + expect(ForemStatsClient).to have_received(:increment).with("stripe.errors", tags) end it "raises Payments::PaymentsError for any other known error" do @@ -90,11 +90,11 @@ RSpec.describe Payments::Customer, type: :service do it "increments stripe.errors for any other known error" do allow(Stripe::Customer).to receive(:create_source).and_raise(Stripe::StripeError) - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) expect { described_class.create_source("customer_id", "token") }.to raise_error(Payments::PaymentsError) tags = hash_including(tags: array_including("error:StripeError")) - expect(DatadogStatsClient).to have_received(:increment).with("stripe.errors", tags) + expect(ForemStatsClient).to have_received(:increment).with("stripe.errors", tags) end end @@ -166,7 +166,7 @@ RSpec.describe Payments::Customer, type: :service do it "increments stripe.errors if the card has any troubles" do StripeMock.prepare_card_error(:expired_card) - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) customer = Stripe::Customer.create token = stripe_helper.generate_card_token @@ -176,7 +176,7 @@ RSpec.describe Payments::Customer, type: :service do described_class.charge(customer: customer, amount: 1, description: "Test charge", card_id: card.id) end.to raise_error(Payments::CardError) tags = hash_including(tags: array_including("error:CardError")) - expect(DatadogStatsClient).to have_received(:increment).with("stripe.errors", tags) + expect(ForemStatsClient).to have_received(:increment).with("stripe.errors", tags) end end end diff --git a/spec/services/rate_limit_checker_spec.rb b/spec/services/rate_limit_checker_spec.rb index faa73f3f5..eefd03b5d 100644 --- a/spec/services/rate_limit_checker_spec.rb +++ b/spec/services/rate_limit_checker_spec.rb @@ -110,10 +110,10 @@ RSpec.describe RateLimitChecker, type: :service do allow(Rails.cache) .to receive(:read).with("#{user.id}_organization_creation", raw: true) .and_return(SiteConfig.rate_limit_organization_creation + 1) - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) described_class.new(user).limit_by_action("organization_creation") - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "rate_limit.limit_reached", tags: ["user:#{user.id}", "action:organization_creation"], ) diff --git a/spec/system/authentication/user_logs_in_with_apple_spec.rb b/spec/system/authentication/user_logs_in_with_apple_spec.rb index d9aeee677..3523daf46 100644 --- a/spec/system/authentication/user_logs_in_with_apple_spec.rb +++ b/spec/system/authentication/user_logs_in_with_apple_spec.rb @@ -61,7 +61,7 @@ RSpec.describe "Authenticating with Apple", vcr: { cassette_name: "fastly_sloan" before do omniauth_setup_invalid_credentials(:apple) - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) end after do @@ -86,7 +86,7 @@ RSpec.describe "Authenticating with Apple", vcr: { cassette_name: "fastly_sloan" click_on(sign_in_link, match: :first) args = omniauth_failure_args(error, "apple", "{}") - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "omniauth.failure", *args ) end @@ -102,7 +102,7 @@ RSpec.describe "Authenticating with Apple", vcr: { cassette_name: "fastly_sloan" click_on(sign_in_link, match: :first) args = omniauth_failure_args(error, "apple", "{}") - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "omniauth.failure", *args ) end @@ -115,7 +115,7 @@ RSpec.describe "Authenticating with Apple", vcr: { cassette_name: "fastly_sloan" click_on(sign_in_link, match: :first) args = omniauth_failure_args(error, "apple", "{}") - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "omniauth.failure", *args ) end diff --git a/spec/system/authentication/user_logs_in_with_facebook_spec.rb b/spec/system/authentication/user_logs_in_with_facebook_spec.rb index 7e05dc289..94db77c45 100644 --- a/spec/system/authentication/user_logs_in_with_facebook_spec.rb +++ b/spec/system/authentication/user_logs_in_with_facebook_spec.rb @@ -92,7 +92,7 @@ RSpec.describe "Authenticating with Facebook" do before do omniauth_setup_invalid_credentials(:facebook) - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) end after do @@ -125,7 +125,7 @@ RSpec.describe "Authenticating with Facebook" do click_on(sign_in_link, match: :first) args = omniauth_failure_args(error, "facebook", params) - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "omniauth.failure", *args ) end @@ -141,7 +141,7 @@ RSpec.describe "Authenticating with Facebook" do click_on(sign_in_link, match: :first) args = omniauth_failure_args(error, "facebook", params) - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "omniauth.failure", *args ) end @@ -154,7 +154,7 @@ RSpec.describe "Authenticating with Facebook" do click_on(sign_in_link, match: :first) args = omniauth_failure_args(error, "facebook", params) - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "omniauth.failure", *args ) end diff --git a/spec/system/authentication/user_logs_in_with_github_spec.rb b/spec/system/authentication/user_logs_in_with_github_spec.rb index a0ddbf61f..5778c34c8 100644 --- a/spec/system/authentication/user_logs_in_with_github_spec.rb +++ b/spec/system/authentication/user_logs_in_with_github_spec.rb @@ -59,7 +59,7 @@ RSpec.describe "Authenticating with GitHub" do before do omniauth_setup_invalid_credentials(:github) - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) end after do @@ -92,7 +92,7 @@ RSpec.describe "Authenticating with GitHub" do click_on(sign_in_link, match: :first) args = omniauth_failure_args(error, "github", params) - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "omniauth.failure", *args ) end @@ -108,7 +108,7 @@ RSpec.describe "Authenticating with GitHub" do click_on(sign_in_link, match: :first) args = omniauth_failure_args(error, "github", params) - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "omniauth.failure", *args ) end @@ -121,7 +121,7 @@ RSpec.describe "Authenticating with GitHub" do click_on(sign_in_link, match: :first) args = omniauth_failure_args(error, "github", params) - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "omniauth.failure", *args ) end diff --git a/spec/system/authentication/user_logs_in_with_twitter_spec.rb b/spec/system/authentication/user_logs_in_with_twitter_spec.rb index 9dfaf3240..16d17c9e7 100644 --- a/spec/system/authentication/user_logs_in_with_twitter_spec.rb +++ b/spec/system/authentication/user_logs_in_with_twitter_spec.rb @@ -55,7 +55,7 @@ RSpec.describe "Authenticating with Twitter" do before do omniauth_setup_invalid_credentials(:twitter) - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) end after do @@ -88,7 +88,7 @@ RSpec.describe "Authenticating with Twitter" do click_on(sign_in_link, match: :first) args = omniauth_failure_args(error, "twitter", "{}") - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "omniauth.failure", *args ) end @@ -104,7 +104,7 @@ RSpec.describe "Authenticating with Twitter" do click_on(sign_in_link, match: :first) args = omniauth_failure_args(error, "twitter", "{}") - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "omniauth.failure", *args ) end @@ -117,7 +117,7 @@ RSpec.describe "Authenticating with Twitter" do click_on(sign_in_link, match: :first) args = omniauth_failure_args(error, "twitter", "{}") - expect(DatadogStatsClient).to have_received(:increment).with( + expect(ForemStatsClient).to have_received(:increment).with( "omniauth.failure", *args ) end diff --git a/spec/workers/data_update_worker_spec.rb b/spec/workers/data_update_worker_spec.rb index 1a0d4039d..7acbc66ca 100644 --- a/spec/workers/data_update_worker_spec.rb +++ b/spec/workers/data_update_worker_spec.rb @@ -51,7 +51,7 @@ RSpec.describe DataUpdateWorker, type: :worker do end it "logs data to Datadog", :aggregate_failures do - allow(DatadogStatsClient).to receive(:increment) + allow(ForemStatsClient).to receive(:increment) worker.perform statuses.each do |status| @@ -59,7 +59,7 @@ RSpec.describe DataUpdateWorker, type: :worker do "data_update_scripts.status", { tags: ["status:#{status}", "script_name:20200214151804_data_update_test_script"] }, ] - expect(DatadogStatsClient).to have_received(:increment).once.with(*expected_args) + expect(ForemStatsClient).to have_received(:increment).once.with(*expected_args) end end end diff --git a/spec/workers/metrics/check_data_update_script_statuses_spec.rb b/spec/workers/metrics/check_data_update_script_statuses_spec.rb index a299193c0..bfa4bf2a2 100644 --- a/spec/workers/metrics/check_data_update_script_statuses_spec.rb +++ b/spec/workers/metrics/check_data_update_script_statuses_spec.rb @@ -8,12 +8,12 @@ RSpec.describe Metrics::CheckDataUpdateScriptStatuses, type: :worker do create(:data_update_script) create(:data_update_script, status: :failed, created_at: 1.month.ago) failed_script = create(:data_update_script, status: :failed) - allow(DatadogStatsClient).to receive(:count) + allow(ForemStatsClient).to receive(:count) described_class.new.perform - expect(DatadogStatsClient).to have_received(:count).once + expect(ForemStatsClient).to have_received(:count).once expect( - DatadogStatsClient, + ForemStatsClient, ).to have_received(:count).with( "data_update_scripts.failures", 1, { tags: ["file_name:#{failed_script.file_name}"] } ).at_least(1) diff --git a/spec/workers/metrics/record_daily_notifications_worker_spec.rb b/spec/workers/metrics/record_daily_notifications_worker_spec.rb index 4d5579662..385c8b9b9 100644 --- a/spec/workers/metrics/record_daily_notifications_worker_spec.rb +++ b/spec/workers/metrics/record_daily_notifications_worker_spec.rb @@ -9,15 +9,15 @@ RSpec.describe Metrics::RecordDailyNotificationsWorker, type: :worker do let(:event_title_count) { Metrics::RecordDailyNotificationsWorker::EVENT_TITLES.count } before do - allow(DatadogStatsClient).to receive(:count) + allow(ForemStatsClient).to receive(:count) ahoy_event described_class.new.perform end it "logs welcome notification click events created in the past day" do - expect(DatadogStatsClient).to have_received(:count).exactly(event_title_count).times + expect(ForemStatsClient).to have_received(:count).exactly(event_title_count).times expect( - DatadogStatsClient, + ForemStatsClient, ).to have_received(:count) .with("ahoy_events", 1, { tags: ["title:welcome_notification_welcome_thread"] }) .at_least(1) diff --git a/spec/workers/metrics/record_daily_usage_worker_spec.rb b/spec/workers/metrics/record_daily_usage_worker_spec.rb index 0fde00aca..a73a316cb 100644 --- a/spec/workers/metrics/record_daily_usage_worker_spec.rb +++ b/spec/workers/metrics/record_daily_usage_worker_spec.rb @@ -27,43 +27,43 @@ RSpec.describe Metrics::RecordDailyUsageWorker, type: :worker do describe "#perform" do before do - allow(DatadogStatsClient).to receive(:count) + allow(ForemStatsClient).to receive(:count) described_class.new.perform end it "logs articles with at least 15 score" do expect( - DatadogStatsClient, + ForemStatsClient, ).to have_received(:count).with("articles.min_15_score_past_24h", 2, tags: Array).at_least(1) end it "logs articles with at least comment 15 score" do expect( - DatadogStatsClient, + ForemStatsClient, ).to have_received(:count).with("articles.min_15_comment_score_past_24h", 1, tags: Array).at_least(1) end it "records first articles" do expect( - DatadogStatsClient, + ForemStatsClient, ).to have_received(:count).with("articles.first_past_24h", 1, tags: Array).at_least(1) end it "records new users with at least one comment" do expect( - DatadogStatsClient, + ForemStatsClient, ).to have_received(:count).with("users.new_min_1_comment_past_24h", 2, tags: Array).at_least(1) end it "records negative reactions" do expect( - DatadogStatsClient, + ForemStatsClient, ).to have_received(:count).with("reactions.negative_past_24h", 1, tags: Array).at_least(1) end it "records report feedback_messages" do expect( - DatadogStatsClient, + ForemStatsClient, ).to have_received(:count).with("feedback_messages.reports_past_24_hours", 1, tags: Array).at_least(1) end end diff --git a/spec/workers/metrics/record_data_counts_worker_spec.rb b/spec/workers/metrics/record_data_counts_worker_spec.rb index c6292cd4d..833cfa106 100644 --- a/spec/workers/metrics/record_data_counts_worker_spec.rb +++ b/spec/workers/metrics/record_data_counts_worker_spec.rb @@ -21,20 +21,20 @@ RSpec.describe Metrics::RecordDataCountsWorker, type: :worker do end it "logs estimated counts in Datadog" do - allow(DatadogStatsClient).to receive(:gauge) + allow(ForemStatsClient).to receive(:gauge) described_class.new.perform expect( - DatadogStatsClient, + ForemStatsClient, ).to have_received(:gauge).with("postgres.db_table_size", 0, tags: Array).at_least(1) end it "logs index counts in Datadog" do - allow(DatadogStatsClient).to receive(:gauge) + allow(ForemStatsClient).to receive(:gauge) described_class.new.perform expect( - DatadogStatsClient, + ForemStatsClient, ).to have_received(:gauge).with("elasticsearch.document_count", Integer, tags: Array).at_least(1) end end