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.
This commit is contained in:
parent
23f3386f3f
commit
ed74f2f245
48 changed files with 184 additions and 146 deletions
|
|
@ -105,7 +105,7 @@ class FollowsController < ApplicationController
|
||||||
Notification.send_new_follower_notification(user_follow) if need_notification
|
Notification.send_new_follower_notification(user_follow) if need_notification
|
||||||
"followed"
|
"followed"
|
||||||
rescue ActiveRecord::RecordInvalid
|
rescue ActiveRecord::RecordInvalid
|
||||||
DatadogStatsClient.increment("users.invalid_follow")
|
ForemStatsClient.increment("users.invalid_follow")
|
||||||
"already followed"
|
"already followed"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||||
error = request.env["omniauth.error"]
|
error = request.env["omniauth.error"]
|
||||||
class_name = error.present? ? error.class.name : ""
|
class_name = error.present? ? error.class.name : ""
|
||||||
|
|
||||||
DatadogStatsClient.increment(
|
ForemStatsClient.increment(
|
||||||
"omniauth.failure",
|
"omniauth.failure",
|
||||||
tags: [
|
tags: [
|
||||||
"class:#{class_name}",
|
"class:#{class_name}",
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,13 @@ class StripeActiveCardsController < ApplicationController
|
||||||
flash[:settings_notice] = "Your billing information has been updated"
|
flash[:settings_notice] = "Your billing information has been updated"
|
||||||
audit_log("add")
|
audit_log("add")
|
||||||
else
|
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."
|
flash[:error] = "There was a problem updating your billing info."
|
||||||
end
|
end
|
||||||
redirect_to user_settings_path(:billing)
|
redirect_to user_settings_path(:billing)
|
||||||
rescue Payments::CardError, Payments::InvalidRequestError => e
|
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 }
|
redirect_to user_settings_path(:billing), flash: { error: e.message }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -36,13 +36,13 @@ class StripeActiveCardsController < ApplicationController
|
||||||
flash[:settings_notice] = "Your billing information has been updated"
|
flash[:settings_notice] = "Your billing information has been updated"
|
||||||
audit_log("update")
|
audit_log("update")
|
||||||
else
|
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."
|
flash[:error] = "There was a problem updating your billing info."
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to user_settings_path(:billing)
|
redirect_to user_settings_path(:billing)
|
||||||
rescue Payments::CardError, Payments::InvalidRequestError => e
|
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 }
|
redirect_to user_settings_path(:billing), flash: { error: e.message }
|
||||||
end
|
end
|
||||||
|
|
@ -65,7 +65,7 @@ class StripeActiveCardsController < ApplicationController
|
||||||
|
|
||||||
redirect_to user_settings_path(:billing)
|
redirect_to user_settings_path(:billing)
|
||||||
rescue Payments::InvalidRequestError => e
|
rescue Payments::InvalidRequestError => e
|
||||||
DatadogStatsClient.increment("stripe.errors")
|
ForemStatsClient.increment("stripe.errors")
|
||||||
|
|
||||||
redirect_to user_settings_path(:billing), flash: { error: e.message }
|
redirect_to user_settings_path(:billing), flash: { error: e.message }
|
||||||
end
|
end
|
||||||
|
|
|
||||||
15
app/lib/acts_as_forem_stats_driver.rb
Normal file
15
app/lib/acts_as_forem_stats_driver.rb
Normal file
|
|
@ -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
|
||||||
16
app/lib/forem_stats_driver.rb
Normal file
16
app/lib/forem_stats_driver.rb
Normal file
|
|
@ -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
|
||||||
19
app/lib/forem_stats_drivers/datadog_driver.rb
Normal file
19
app/lib/forem_stats_drivers/datadog_driver.rb
Normal file
|
|
@ -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
|
||||||
|
|
@ -59,7 +59,7 @@ module Authentication
|
||||||
|
|
||||||
if log_to_datadog
|
if log_to_datadog
|
||||||
# Notify DataDog if a new identity was successfully created.
|
# 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
|
end
|
||||||
|
|
||||||
# Return the successfully-authed used from the transaction.
|
# Return the successfully-authed used from the transaction.
|
||||||
|
|
@ -67,7 +67,7 @@ module Authentication
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
# Notify DataDog if something goes wrong in the transaction,
|
# Notify DataDog if something goes wrong in the transaction,
|
||||||
# and then ensure that we re-raise and bubble up the error.
|
# 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
|
raise e
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ module EdgeCache
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
Rails.logger.warn("#{provider_class} cannot be used without a #call implementation!")
|
Rails.logger.warn("#{provider_class} cannot be used without a #call implementation!")
|
||||||
DatadogStatsClient.increment("edgecache_bust.invalid_provider_class",
|
ForemStatsClient.increment("edgecache_bust.invalid_provider_class",
|
||||||
tags: ["provider_class:#{provider_class}"])
|
tags: ["provider_class:#{provider_class}"])
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ module EdgeCache
|
||||||
# If we can't connect to OpenResty, alert ourselves that
|
# If we can't connect to OpenResty, alert ourselves that
|
||||||
# it is unavailable and return false.
|
# it is unavailable and return false.
|
||||||
Rails.logger.error("Could not connect to OpenResty via #{ApplicationConfig['OPENRESTY_URL']}!")
|
Rails.logger.error("Could not connect to OpenResty via #{ApplicationConfig['OPENRESTY_URL']}!")
|
||||||
DatadogStatsClient.increment("edgecache_bust.service_unavailable",
|
ForemStatsClient.increment("edgecache_bust.service_unavailable",
|
||||||
tags: ["path:#{ApplicationConfig['OPENRESTY_URL']}"])
|
tags: ["path:#{ApplicationConfig['OPENRESTY_URL']}"])
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ module FastlyConfig
|
||||||
"new_version:#{new_version.number}",
|
"new_version:#{new_version.number}",
|
||||||
]
|
]
|
||||||
|
|
||||||
DatadogStatsClient.increment("fastly.snippets", tags: tags)
|
ForemStatsClient.increment("fastly.snippets", tags: tags)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ module FastlyConfig
|
||||||
"configs_updated:#{configs.join(', ')}",
|
"configs_updated:#{configs.join(', ')}",
|
||||||
]
|
]
|
||||||
|
|
||||||
DatadogStatsClient.increment("fastly.update", tags: tags)
|
ForemStatsClient.increment("fastly.update", tags: tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_configs(configs)
|
def validate_configs(configs)
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ module Feeds
|
||||||
|
|
||||||
users.in_batches(of: users_batch_size) do |batch_of_users|
|
users.in_batches(of: users_batch_size) do |batch_of_users|
|
||||||
feeds_per_user_id = fetch_feeds(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)
|
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
|
# NOTE: doing this sequentially to avoid locking problems with the DB
|
||||||
# and unnecessary conflicts
|
# and unnecessary conflicts
|
||||||
|
|
@ -33,7 +33,7 @@ module Feeds
|
||||||
# only actually uses feed.url
|
# only actually uses feed.url
|
||||||
user = batch_of_users.detect { |u| u.id == user_id }
|
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)
|
create_articles_from_user_feed(user, feed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -46,7 +46,7 @@ module Feeds
|
||||||
batch_of_users.update_all(feed_fetched_at: Time.current)
|
batch_of_users.update_all(feed_fetched_at: Time.current)
|
||||||
end
|
end
|
||||||
|
|
||||||
DatadogStatsClient.count("feeds::import::articles.count", total_articles_count)
|
ForemStatsClient.count("feeds::import::articles.count", total_articles_count)
|
||||||
total_articles_count
|
total_articles_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -70,7 +70,7 @@ module Feeds
|
||||||
cleaned_url = url.to_s.strip
|
cleaned_url = url.to_s.strip
|
||||||
next if cleaned_url.blank?
|
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)
|
HTTParty.get(cleaned_url, timeout: 10)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ module Feeds
|
||||||
# TODO: put this in separate service object
|
# TODO: put this in separate service object
|
||||||
def parse_feeds(feeds_per_user_id)
|
def parse_feeds(feeds_per_user_id)
|
||||||
result = Parallel.map(feeds_per_user_id, in_threads: num_parsers) do |user_id, feed_xml|
|
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)
|
Feedjira.parse(feed_xml)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ module Github
|
||||||
|
|
||||||
Honeycomb.add_field("github.result", "error")
|
Honeycomb.add_field("github.result", "error")
|
||||||
Honeycomb.add_field("github.error", class_name)
|
Honeycomb.add_field("github.error", class_name)
|
||||||
DatadogStatsClient.increment(
|
ForemStatsClient.increment(
|
||||||
"github.errors",
|
"github.errors",
|
||||||
tags: ["error:#{class_name}", "message:#{exception.message}"],
|
tags: ["error:#{class_name}", "message:#{exception.message}"],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ module Loggers
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_to_datadog(metric_name, value, tags = [])
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ module Notifications
|
||||||
attr_reader :receiver_id, :welcome_broadcast
|
attr_reader :receiver_id, :welcome_broadcast
|
||||||
|
|
||||||
def log_to_datadog
|
def log_to_datadog
|
||||||
DatadogStatsClient.increment(
|
ForemStatsClient.increment(
|
||||||
"notifications.welcome",
|
"notifications.welcome",
|
||||||
tags: ["user_id:#{receiver_id}", "title:#{welcome_broadcast.title}"],
|
tags: ["user_id:#{receiver_id}", "title:#{welcome_broadcast.title}"],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -65,14 +65,14 @@ module Payments
|
||||||
def request
|
def request
|
||||||
yield
|
yield
|
||||||
rescue Stripe::InvalidRequestError => e
|
rescue Stripe::InvalidRequestError => e
|
||||||
DatadogStatsClient.increment("stripe.errors", tags: ["error:InvalidRequestError"])
|
ForemStatsClient.increment("stripe.errors", tags: ["error:InvalidRequestError"])
|
||||||
raise InvalidRequestError, e.message
|
raise InvalidRequestError, e.message
|
||||||
rescue Stripe::CardError => e
|
rescue Stripe::CardError => e
|
||||||
DatadogStatsClient.increment("stripe.errors", tags: ["error:CardError"])
|
ForemStatsClient.increment("stripe.errors", tags: ["error:CardError"])
|
||||||
raise CardError, e.message
|
raise CardError, e.message
|
||||||
rescue Stripe::StripeError => e
|
rescue Stripe::StripeError => e
|
||||||
Honeybadger.notify(e)
|
Honeybadger.notify(e)
|
||||||
DatadogStatsClient.increment("stripe.errors", tags: ["error:StripeError"])
|
ForemStatsClient.increment("stripe.errors", tags: ["error:StripeError"])
|
||||||
raise PaymentsError, e.message
|
raise PaymentsError, e.message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,6 @@ class RateLimitChecker
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_to_datadog
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ module Search
|
||||||
def record_error(error_message, class_name)
|
def record_error(error_message, class_name)
|
||||||
Honeycomb.add_field("elasticsearch.result", "error")
|
Honeycomb.add_field("elasticsearch.result", "error")
|
||||||
Honeycomb.add_field("elasticsearch.error", class_name)
|
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
|
end
|
||||||
|
|
||||||
def target
|
def target
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ module TwitterClient
|
||||||
|
|
||||||
Honeycomb.add_field("twitter.result", "error")
|
Honeycomb.add_field("twitter.result", "error")
|
||||||
Honeycomb.add_field("twitter.error", class_name)
|
Honeycomb.add_field("twitter.error", class_name)
|
||||||
DatadogStatsClient.increment(
|
ForemStatsClient.increment(
|
||||||
"twitter.errors",
|
"twitter.errors",
|
||||||
tags: ["error:#{class_name}", "message:#{exception.message}"],
|
tags: ["error:#{class_name}", "message:#{exception.message}"],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,6 @@ class DataUpdateWorker
|
||||||
"time=#{Time.current.rfc3339}, script=#{file_name}, status=#{status}",
|
"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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ module Metrics
|
||||||
def perform
|
def perform
|
||||||
failed_scripts = DataUpdateScript.failed.where(created_at: 1.day.ago..Time.current)
|
failed_scripts = DataUpdateScript.failed.where(created_at: 1.day.ago..Time.current)
|
||||||
failed_scripts.find_each do |script|
|
failed_scripts.find_each do |script|
|
||||||
DatadogStatsClient.count(
|
ForemStatsClient.count(
|
||||||
"data_update_scripts.failures",
|
"data_update_scripts.failures",
|
||||||
1,
|
1,
|
||||||
tags: ["file_name:#{script.file_name}"],
|
tags: ["file_name:#{script.file_name}"],
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ module Metrics
|
||||||
.where("time > ?", 1.day.ago)
|
.where("time > ?", 1.day.ago)
|
||||||
.where("properties->>'title' = ?", title)
|
.where("properties->>'title' = ?", title)
|
||||||
|
|
||||||
DatadogStatsClient.count(
|
ForemStatsClient.count(
|
||||||
"ahoy_events",
|
"ahoy_events",
|
||||||
event.size,
|
event.size,
|
||||||
tags: ["title:#{title}"],
|
tags: ["title:#{title}"],
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ module Metrics
|
||||||
def perform
|
def perform
|
||||||
# Articles published in the past 24 hours with at least 15 "score" (positive/negative reactions)
|
# 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
|
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",
|
||||||
articles_min_15_score_past_24h,
|
articles_min_15_score_past_24h,
|
||||||
tags: ["resource:articles"],
|
tags: ["resource:articles"],
|
||||||
|
|
@ -16,7 +16,7 @@ module Metrics
|
||||||
articles_min_15_comment_score_past_24h = Article.published
|
articles_min_15_comment_score_past_24h = Article.published
|
||||||
.where("comment_score >= ? AND published_at > ?", 15, 1.day.ago)
|
.where("comment_score >= ? AND published_at > ?", 15, 1.day.ago)
|
||||||
.size
|
.size
|
||||||
DatadogStatsClient.count(
|
ForemStatsClient.count(
|
||||||
"articles.min_15_comment_score_past_24h",
|
"articles.min_15_comment_score_past_24h",
|
||||||
articles_min_15_comment_score_past_24h,
|
articles_min_15_comment_score_past_24h,
|
||||||
tags: ["resource:articles"],
|
tags: ["resource:articles"],
|
||||||
|
|
@ -24,11 +24,11 @@ module Metrics
|
||||||
|
|
||||||
# Articles published in the past 24 which were that user's first article
|
# 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
|
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
|
# 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
|
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",
|
"users.new_min_1_comment_past_24h",
|
||||||
new_users_min_1_comment_past_24h,
|
new_users_min_1_comment_past_24h,
|
||||||
tags: ["resource:users"],
|
tags: ["resource:users"],
|
||||||
|
|
@ -36,12 +36,12 @@ module Metrics
|
||||||
|
|
||||||
# Total negative reactions in the past 24 hours
|
# Total negative reactions in the past 24 hours
|
||||||
negative_reactions_past_24h = Reaction.where("points < 0").where("created_at > ?", 1.day.ago).size
|
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
|
# Total abuse (etc.) reports in the past 24 hours
|
||||||
categories = ["spam", "other", "rude or vulgar", "harassment"]
|
categories = ["spam", "other", "rude or vulgar", "harassment"]
|
||||||
reports_past_24_hours = FeedbackMessage.where(category: categories).where("created_at > ?", 1.day.ago).size
|
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",
|
"feedback_messages.reports_past_24_hours",
|
||||||
reports_past_24_hours,
|
reports_past_24_hours,
|
||||||
tags: ["resource:feedback_messages"],
|
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_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 = distinct_user_values.group_by(&:itself).transform_values(&:count)
|
||||||
distinct_counts.each_key do |key|
|
distinct_counts.each_key do |key|
|
||||||
DatadogStatsClient.count("users.active_days_past_week", distinct_counts[key],
|
ForemStatsClient.count("users.active_days_past_week", distinct_counts[key],
|
||||||
tags: ["resource:users", "group:#{group}", "day_count:#{key}"])
|
tags: ["resource:users", "group:#{group}", "day_count:#{key}"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ module Metrics
|
||||||
end
|
end
|
||||||
|
|
||||||
Rails.logger.info(message: "db_table_size", table_info: { table_name: model.table_name, table_size: db_count })
|
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)
|
next unless model.const_defined?(:SEARCH_CLASS)
|
||||||
|
|
||||||
|
|
@ -22,8 +22,8 @@ module Metrics
|
||||||
else
|
else
|
||||||
model::SEARCH_CLASS.document_count
|
model::SEARCH_CLASS.document_count
|
||||||
end
|
end
|
||||||
DatadogStatsClient.gauge("elasticsearch.document_count", document_count,
|
ForemStatsClient.gauge("elasticsearch.document_count", document_count,
|
||||||
tags: ["table_name:#{model.table_name}"])
|
tags: ["table_name:#{model.table_name}"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ module Moderator
|
||||||
admin = User.find(admin_id)
|
admin = User.find(admin_id)
|
||||||
Moderator::BanishUser.call(admin: admin, user: abuser)
|
Moderator::BanishUser.call(admin: admin, user: abuser)
|
||||||
rescue StandardError => e
|
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)
|
Honeybadger.notify(e)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ module Moderator
|
||||||
new_score = reactions.sum(:points) + Reaction.where(reactable: user).sum(:points)
|
new_score = reactions.sum(:points) + Reaction.where(reactable: user).sum(:points)
|
||||||
articles.update_all(score: new_score)
|
articles.update_all(score: new_score)
|
||||||
rescue StandardError => e
|
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)
|
Honeybadger.notify(e)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ module Users
|
||||||
# whole object
|
# whole object
|
||||||
NotifyMailer.with(name: user.name, email: user.email).account_deleted_email.deliver_now
|
NotifyMailer.with(name: user.name, email: user.email).account_deleted_email.deliver_now
|
||||||
rescue StandardError => e
|
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.context({ user_id: user.id })
|
||||||
Honeybadger.notify(e)
|
Honeybadger.notify(e)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
1
config/initializers/stats.rb
Normal file
1
config/initializers/stats.rb
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ForemStatsClient = ForemStatsDriver.new
|
||||||
|
|
@ -31,7 +31,7 @@ module DataUpdateScripts
|
||||||
|
|
||||||
# Sending IDs of deleted articles to Datadog
|
# Sending IDs of deleted articles to Datadog
|
||||||
result.map { |row| row["id"] }.in_groups_of(1000) do |ids|
|
result.map { |row| row["id"] }.in_groups_of(1000) do |ids|
|
||||||
DatadogStatsClient.event(
|
ForemStatsClient.event(
|
||||||
"DataUpdateScripts::RemoveDraftArticlesWithDuplicateCanonicalUrl",
|
"DataUpdateScripts::RemoveDraftArticlesWithDuplicateCanonicalUrl",
|
||||||
"deleted draft articles with the same canonical_url and same body_markdown",
|
"deleted draft articles with the same canonical_url and same body_markdown",
|
||||||
tags: ids,
|
tags: ids,
|
||||||
|
|
@ -67,7 +67,7 @@ module DataUpdateScripts
|
||||||
|
|
||||||
# Sending IDs of deleted articles to Datadog
|
# Sending IDs of deleted articles to Datadog
|
||||||
result.map { |row| row["id"] }.in_groups_of(1000) do |ids|
|
result.map { |row| row["id"] }.in_groups_of(1000) do |ids|
|
||||||
DatadogStatsClient.event(
|
ForemStatsClient.event(
|
||||||
"DataUpdateScripts::RemoveDraftArticlesWithDuplicateCanonicalUrl",
|
"DataUpdateScripts::RemoveDraftArticlesWithDuplicateCanonicalUrl",
|
||||||
"deleted draft articles with the same canonical_url and different body_markdown",
|
"deleted draft articles with the same canonical_url and different body_markdown",
|
||||||
tags: ids,
|
tags: ids,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ module Sidekiq
|
||||||
"retry:#{job['retry']}",
|
"retry:#{job['retry']}",
|
||||||
"retry_count:#{job['retry_count']}",
|
"retry_count:#{job['retry_count']}",
|
||||||
]
|
]
|
||||||
DatadogStatsClient.increment(
|
ForemStatsClient.increment(
|
||||||
"sidekiq.worker.retries_exhausted", tags: tags
|
"sidekiq.worker.retries_exhausted", tags: tags
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ describe Sidekiq::WorkerRetriesExhaustedReporter, type: :labor do
|
||||||
let(:job_hash) { { "class" => "TempWorker", "retry" => 15, "retry_count" => 1, "jid" => "123abc" } }
|
let(:job_hash) { { "class" => "TempWorker", "retry" => 15, "retry_count" => 1, "jid" => "123abc" } }
|
||||||
|
|
||||||
it "increments worker retries exhausted in Datadog" do
|
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)
|
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",
|
"sidekiq.worker.retries_exhausted",
|
||||||
tags: [
|
tags: [
|
||||||
"action:dead",
|
"action:dead",
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ RSpec.describe "StripeActiveCards", type: :request do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "increments sidekiq.errors in Datadog on failure" do
|
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")
|
invalid_error = Stripe::InvalidRequestError.new("message", "param")
|
||||||
allow(Stripe::Customer).to receive(:create).and_raise(invalid_error)
|
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)
|
expect(flash[:error]).to eq(invalid_error.message)
|
||||||
|
|
||||||
tags = hash_including(tags: array_including("error: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
|
end
|
||||||
|
|
||||||
it "updates the user's updated_at" do
|
it "updates the user's updated_at" do
|
||||||
|
|
@ -73,13 +73,13 @@ RSpec.describe "StripeActiveCards", type: :request do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "increments sidekiq.errors.new_subscription in Datadog on failure" do
|
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)
|
invalid_error = Stripe::InvalidRequestError.new(nil, nil)
|
||||||
allow(Stripe::Customer).to receive(:create).and_raise(invalid_error)
|
allow(Stripe::Customer).to receive(:create).and_raise(invalid_error)
|
||||||
post "/stripe_active_cards", params: { stripe_token: stripe_helper.generate_card_token }
|
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}"))
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -124,7 +124,7 @@ RSpec.describe "StripeActiveCards", type: :request do
|
||||||
_, source = create_user_with_card(user, card_token)
|
_, source = create_user_with_card(user, card_token)
|
||||||
original_card_id = source.id
|
original_card_id = source.id
|
||||||
|
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
card_error = Stripe::CardError.new("message", "param")
|
card_error = Stripe::CardError.new("message", "param")
|
||||||
allow(Stripe::Customer).to receive(:retrieve).and_raise(card_error)
|
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)
|
expect(flash[:error]).to eq(card_error.message)
|
||||||
|
|
||||||
tags = hash_including(tags: array_including("error: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
|
||||||
|
|
||||||
it "updates the user's updated_at" do
|
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)
|
_, source = create_user_with_card(user, card_token)
|
||||||
original_card_id = source.id
|
original_card_id = source.id
|
||||||
|
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
card_error = Stripe::CardError.new("message", "param")
|
card_error = Stripe::CardError.new("message", "param")
|
||||||
allow(Stripe::Customer).to receive(:retrieve).and_raise(card_error)
|
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(response).to redirect_to(user_settings_path(:billing))
|
||||||
expect(flash[:error]).to eq(card_error.message)
|
expect(flash[:error]).to eq(card_error.message)
|
||||||
tags = hash_including(tags: array_including("action:update_card", "user_id:#{user.id}"))
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,10 +83,10 @@ RSpec.describe Authentication::Authenticator, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "records successful identity creation metric" do
|
it "records successful identity creation metric" do
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
service.call
|
service.call
|
||||||
|
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"identity.created", tags: ["provider:apple"]
|
"identity.created", tags: ["provider:apple"]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -122,10 +122,10 @@ RSpec.describe Authentication::Authenticator, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not record an identity creation metric" do
|
it "does not record an identity creation metric" do
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
service.call
|
service.call
|
||||||
|
|
||||||
expect(DatadogStatsClient).not_to have_received(:increment)
|
expect(ForemStatsClient).not_to have_received(:increment)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "updates the proper data from the auth payload" do
|
it "updates the proper data from the auth payload" do
|
||||||
|
|
@ -281,10 +281,10 @@ RSpec.describe Authentication::Authenticator, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "records successful identity creation metric" do
|
it "records successful identity creation metric" do
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
service.call
|
service.call
|
||||||
|
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"identity.created", tags: ["provider:github"]
|
"identity.created", tags: ["provider:github"]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -293,12 +293,12 @@ RSpec.describe Authentication::Authenticator, type: :service do
|
||||||
# rubocop:disable RSpec/AnyInstance
|
# rubocop:disable RSpec/AnyInstance
|
||||||
allow_any_instance_of(Identity).to receive(:save!).and_raise(StandardError)
|
allow_any_instance_of(Identity).to receive(:save!).and_raise(StandardError)
|
||||||
# rubocop:enable RSpec/AnyInstance
|
# rubocop:enable RSpec/AnyInstance
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
|
|
||||||
expect { described_class.call(auth_payload) }.to raise_error(StandardError)
|
expect { described_class.call(auth_payload) }.to raise_error(StandardError)
|
||||||
|
|
||||||
tags = hash_including(tags: array_including("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
|
end
|
||||||
|
|
||||||
|
|
@ -332,10 +332,10 @@ RSpec.describe Authentication::Authenticator, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not record an identity creation metric" do
|
it "does not record an identity creation metric" do
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
service.call
|
service.call
|
||||||
|
|
||||||
expect(DatadogStatsClient).not_to have_received(:increment)
|
expect(ForemStatsClient).not_to have_received(:increment)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets remember_me for the existing user" do
|
it "sets remember_me for the existing user" do
|
||||||
|
|
@ -391,12 +391,12 @@ RSpec.describe Authentication::Authenticator, type: :service do
|
||||||
# rubocop:disable RSpec/AnyInstance
|
# rubocop:disable RSpec/AnyInstance
|
||||||
allow_any_instance_of(Identity).to receive(:save!).and_raise(StandardError)
|
allow_any_instance_of(Identity).to receive(:save!).and_raise(StandardError)
|
||||||
# rubocop:enable RSpec/AnyInstance
|
# rubocop:enable RSpec/AnyInstance
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
|
|
||||||
expect { described_class.call(auth_payload) }.to raise_error(StandardError)
|
expect { described_class.call(auth_payload) }.to raise_error(StandardError)
|
||||||
|
|
||||||
tags = hash_including(tags: array_including("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
|
end
|
||||||
|
|
||||||
|
|
@ -492,10 +492,10 @@ RSpec.describe Authentication::Authenticator, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "records successful identity creation metric" do
|
it "records successful identity creation metric" do
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
service.call
|
service.call
|
||||||
|
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"identity.created", tags: ["provider:facebook"]
|
"identity.created", tags: ["provider:facebook"]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -504,12 +504,12 @@ RSpec.describe Authentication::Authenticator, type: :service do
|
||||||
# rubocop:disable RSpec/AnyInstance
|
# rubocop:disable RSpec/AnyInstance
|
||||||
allow_any_instance_of(Identity).to receive(:save!).and_raise(StandardError)
|
allow_any_instance_of(Identity).to receive(:save!).and_raise(StandardError)
|
||||||
# rubocop:enable RSpec/AnyInstance
|
# rubocop:enable RSpec/AnyInstance
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
|
|
||||||
expect { described_class.call(auth_payload) }.to raise_error(StandardError)
|
expect { described_class.call(auth_payload) }.to raise_error(StandardError)
|
||||||
|
|
||||||
tags = hash_including(tags: array_including("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
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -584,10 +584,10 @@ RSpec.describe Authentication::Authenticator, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "records successful identity creation metric" do
|
it "records successful identity creation metric" do
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
service.call
|
service.call
|
||||||
|
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"identity.created", tags: ["provider:twitter"]
|
"identity.created", tags: ["provider:twitter"]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -623,10 +623,10 @@ RSpec.describe Authentication::Authenticator, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not record an identity creation metric" do
|
it "does not record an identity creation metric" do
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
service.call
|
service.call
|
||||||
|
|
||||||
expect(DatadogStatsClient).not_to have_received(:increment)
|
expect(ForemStatsClient).not_to have_received(:increment)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "updates the proper data from the auth payload" do
|
it "updates the proper data from the auth payload" do
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ RSpec.describe FastlyConfig::Snippets, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "logs success messages" do
|
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_version).to receive(:number).and_return(1)
|
||||||
allow(fastly).to receive(:get_snippet).and_return(fastly_snippet)
|
allow(fastly).to receive(:get_snippet).and_return(fastly_snippet)
|
||||||
allow(fastly_snippet).to receive(:content).and_return("test")
|
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",
|
tags = hash_including(tags: array_including("snippet_update_type:update", "snippet_name:test",
|
||||||
"new_version:#{fastly_version.number}"))
|
"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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ RSpec.describe FastlyConfig::Update, type: :service do
|
||||||
|
|
||||||
it "logs success messages" do
|
it "logs success messages" do
|
||||||
allow(Rails.logger).to receive(:info)
|
allow(Rails.logger).to receive(:info)
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
|
|
||||||
stub_const("#{described_class}::FASTLY_CONFIGS", ["Snippets"])
|
stub_const("#{described_class}::FASTLY_CONFIGS", ["Snippets"])
|
||||||
snippet_handler = instance_double FastlyConfig::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"))
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ RSpec.describe Notifications::WelcomeNotification::Send, type: :service do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(User).to receive(:mascot_account).and_return(create(:user))
|
allow(User).to receive(:mascot_account).and_return(create(:user))
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a new welcome notification", :aggregate_failures do
|
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)
|
welcome_notification = Notification.find_by(notifiable_id: welcome_broadcast.id)
|
||||||
tags = ["user_id:#{welcome_notification.user_id}", "title:#{welcome_notification.notifiable.title}"]
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,11 @@ RSpec.describe Payments::Customer, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "increments stripe.errors if the customer does not exist" do
|
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)
|
expect { described_class.get("foobar") }.to raise_error(Payments::InvalidRequestError)
|
||||||
tags = hash_including(tags: array_including("error: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
|
end
|
||||||
|
|
||||||
it "raises Payments::PaymentsError for any other known error" do
|
it "raises Payments::PaymentsError for any other known error" do
|
||||||
|
|
@ -34,12 +34,12 @@ RSpec.describe Payments::Customer, type: :service do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "increments stripe.errors for any other known error" do
|
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)
|
allow(Stripe::Customer).to receive(:retrieve).with("foobar").and_raise(Stripe::StripeError)
|
||||||
|
|
||||||
expect { described_class.get("foobar") }.to raise_error(Payments::PaymentsError)
|
expect { described_class.get("foobar") }.to raise_error(Payments::PaymentsError)
|
||||||
tags = hash_including(tags: array_including("error:StripeError"))
|
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
|
||||||
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
|
it "increments stripe.errors if anything in the params is invalid" do
|
||||||
error = Stripe::InvalidRequestError.new("message", :token)
|
error = Stripe::InvalidRequestError.new("message", :token)
|
||||||
allow(Stripe::Customer).to receive(:create_source).and_raise(error)
|
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)
|
expect { described_class.create_source("customer_id", "token") }.to raise_error(Payments::InvalidRequestError)
|
||||||
tags = hash_including(tags: array_including("error: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
|
end
|
||||||
|
|
||||||
it "raises Payments::PaymentsError for any other known error" do
|
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
|
it "increments stripe.errors for any other known error" do
|
||||||
allow(Stripe::Customer).to receive(:create_source).and_raise(Stripe::StripeError)
|
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)
|
expect { described_class.create_source("customer_id", "token") }.to raise_error(Payments::PaymentsError)
|
||||||
tags = hash_including(tags: array_including("error:StripeError"))
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -166,7 +166,7 @@ RSpec.describe Payments::Customer, type: :service do
|
||||||
|
|
||||||
it "increments stripe.errors if the card has any troubles" do
|
it "increments stripe.errors if the card has any troubles" do
|
||||||
StripeMock.prepare_card_error(:expired_card)
|
StripeMock.prepare_card_error(:expired_card)
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
|
|
||||||
customer = Stripe::Customer.create
|
customer = Stripe::Customer.create
|
||||||
token = stripe_helper.generate_card_token
|
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)
|
described_class.charge(customer: customer, amount: 1, description: "Test charge", card_id: card.id)
|
||||||
end.to raise_error(Payments::CardError)
|
end.to raise_error(Payments::CardError)
|
||||||
tags = hash_including(tags: array_including("error: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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -110,10 +110,10 @@ RSpec.describe RateLimitChecker, type: :service do
|
||||||
allow(Rails.cache)
|
allow(Rails.cache)
|
||||||
.to receive(:read).with("#{user.id}_organization_creation", raw: true)
|
.to receive(:read).with("#{user.id}_organization_creation", raw: true)
|
||||||
.and_return(SiteConfig.rate_limit_organization_creation + 1)
|
.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")
|
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",
|
"rate_limit.limit_reached",
|
||||||
tags: ["user:#{user.id}", "action:organization_creation"],
|
tags: ["user:#{user.id}", "action:organization_creation"],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ RSpec.describe "Authenticating with Apple", vcr: { cassette_name: "fastly_sloan"
|
||||||
before do
|
before do
|
||||||
omniauth_setup_invalid_credentials(:apple)
|
omniauth_setup_invalid_credentials(:apple)
|
||||||
|
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
|
|
@ -86,7 +86,7 @@ RSpec.describe "Authenticating with Apple", vcr: { cassette_name: "fastly_sloan"
|
||||||
click_on(sign_in_link, match: :first)
|
click_on(sign_in_link, match: :first)
|
||||||
|
|
||||||
args = omniauth_failure_args(error, "apple", "{}")
|
args = omniauth_failure_args(error, "apple", "{}")
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"omniauth.failure", *args
|
"omniauth.failure", *args
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -102,7 +102,7 @@ RSpec.describe "Authenticating with Apple", vcr: { cassette_name: "fastly_sloan"
|
||||||
click_on(sign_in_link, match: :first)
|
click_on(sign_in_link, match: :first)
|
||||||
|
|
||||||
args = omniauth_failure_args(error, "apple", "{}")
|
args = omniauth_failure_args(error, "apple", "{}")
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"omniauth.failure", *args
|
"omniauth.failure", *args
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -115,7 +115,7 @@ RSpec.describe "Authenticating with Apple", vcr: { cassette_name: "fastly_sloan"
|
||||||
click_on(sign_in_link, match: :first)
|
click_on(sign_in_link, match: :first)
|
||||||
|
|
||||||
args = omniauth_failure_args(error, "apple", "{}")
|
args = omniauth_failure_args(error, "apple", "{}")
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"omniauth.failure", *args
|
"omniauth.failure", *args
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ RSpec.describe "Authenticating with Facebook" do
|
||||||
before do
|
before do
|
||||||
omniauth_setup_invalid_credentials(:facebook)
|
omniauth_setup_invalid_credentials(:facebook)
|
||||||
|
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
|
|
@ -125,7 +125,7 @@ RSpec.describe "Authenticating with Facebook" do
|
||||||
click_on(sign_in_link, match: :first)
|
click_on(sign_in_link, match: :first)
|
||||||
|
|
||||||
args = omniauth_failure_args(error, "facebook", params)
|
args = omniauth_failure_args(error, "facebook", params)
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"omniauth.failure", *args
|
"omniauth.failure", *args
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -141,7 +141,7 @@ RSpec.describe "Authenticating with Facebook" do
|
||||||
click_on(sign_in_link, match: :first)
|
click_on(sign_in_link, match: :first)
|
||||||
|
|
||||||
args = omniauth_failure_args(error, "facebook", params)
|
args = omniauth_failure_args(error, "facebook", params)
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"omniauth.failure", *args
|
"omniauth.failure", *args
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -154,7 +154,7 @@ RSpec.describe "Authenticating with Facebook" do
|
||||||
click_on(sign_in_link, match: :first)
|
click_on(sign_in_link, match: :first)
|
||||||
|
|
||||||
args = omniauth_failure_args(error, "facebook", params)
|
args = omniauth_failure_args(error, "facebook", params)
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"omniauth.failure", *args
|
"omniauth.failure", *args
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ RSpec.describe "Authenticating with GitHub" do
|
||||||
before do
|
before do
|
||||||
omniauth_setup_invalid_credentials(:github)
|
omniauth_setup_invalid_credentials(:github)
|
||||||
|
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
|
|
@ -92,7 +92,7 @@ RSpec.describe "Authenticating with GitHub" do
|
||||||
click_on(sign_in_link, match: :first)
|
click_on(sign_in_link, match: :first)
|
||||||
|
|
||||||
args = omniauth_failure_args(error, "github", params)
|
args = omniauth_failure_args(error, "github", params)
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"omniauth.failure", *args
|
"omniauth.failure", *args
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -108,7 +108,7 @@ RSpec.describe "Authenticating with GitHub" do
|
||||||
click_on(sign_in_link, match: :first)
|
click_on(sign_in_link, match: :first)
|
||||||
|
|
||||||
args = omniauth_failure_args(error, "github", params)
|
args = omniauth_failure_args(error, "github", params)
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"omniauth.failure", *args
|
"omniauth.failure", *args
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -121,7 +121,7 @@ RSpec.describe "Authenticating with GitHub" do
|
||||||
click_on(sign_in_link, match: :first)
|
click_on(sign_in_link, match: :first)
|
||||||
|
|
||||||
args = omniauth_failure_args(error, "github", params)
|
args = omniauth_failure_args(error, "github", params)
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"omniauth.failure", *args
|
"omniauth.failure", *args
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ RSpec.describe "Authenticating with Twitter" do
|
||||||
before do
|
before do
|
||||||
omniauth_setup_invalid_credentials(:twitter)
|
omniauth_setup_invalid_credentials(:twitter)
|
||||||
|
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
|
|
@ -88,7 +88,7 @@ RSpec.describe "Authenticating with Twitter" do
|
||||||
click_on(sign_in_link, match: :first)
|
click_on(sign_in_link, match: :first)
|
||||||
|
|
||||||
args = omniauth_failure_args(error, "twitter", "{}")
|
args = omniauth_failure_args(error, "twitter", "{}")
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"omniauth.failure", *args
|
"omniauth.failure", *args
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -104,7 +104,7 @@ RSpec.describe "Authenticating with Twitter" do
|
||||||
click_on(sign_in_link, match: :first)
|
click_on(sign_in_link, match: :first)
|
||||||
|
|
||||||
args = omniauth_failure_args(error, "twitter", "{}")
|
args = omniauth_failure_args(error, "twitter", "{}")
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"omniauth.failure", *args
|
"omniauth.failure", *args
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -117,7 +117,7 @@ RSpec.describe "Authenticating with Twitter" do
|
||||||
click_on(sign_in_link, match: :first)
|
click_on(sign_in_link, match: :first)
|
||||||
|
|
||||||
args = omniauth_failure_args(error, "twitter", "{}")
|
args = omniauth_failure_args(error, "twitter", "{}")
|
||||||
expect(DatadogStatsClient).to have_received(:increment).with(
|
expect(ForemStatsClient).to have_received(:increment).with(
|
||||||
"omniauth.failure", *args
|
"omniauth.failure", *args
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ RSpec.describe DataUpdateWorker, type: :worker do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "logs data to Datadog", :aggregate_failures do
|
it "logs data to Datadog", :aggregate_failures do
|
||||||
allow(DatadogStatsClient).to receive(:increment)
|
allow(ForemStatsClient).to receive(:increment)
|
||||||
worker.perform
|
worker.perform
|
||||||
|
|
||||||
statuses.each do |status|
|
statuses.each do |status|
|
||||||
|
|
@ -59,7 +59,7 @@ RSpec.describe DataUpdateWorker, type: :worker do
|
||||||
"data_update_scripts.status",
|
"data_update_scripts.status",
|
||||||
{ tags: ["status:#{status}", "script_name:20200214151804_data_update_test_script"] },
|
{ 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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@ RSpec.describe Metrics::CheckDataUpdateScriptStatuses, type: :worker do
|
||||||
create(:data_update_script)
|
create(:data_update_script)
|
||||||
create(:data_update_script, status: :failed, created_at: 1.month.ago)
|
create(:data_update_script, status: :failed, created_at: 1.month.ago)
|
||||||
failed_script = create(:data_update_script, status: :failed)
|
failed_script = create(:data_update_script, status: :failed)
|
||||||
allow(DatadogStatsClient).to receive(:count)
|
allow(ForemStatsClient).to receive(:count)
|
||||||
described_class.new.perform
|
described_class.new.perform
|
||||||
|
|
||||||
expect(DatadogStatsClient).to have_received(:count).once
|
expect(ForemStatsClient).to have_received(:count).once
|
||||||
expect(
|
expect(
|
||||||
DatadogStatsClient,
|
ForemStatsClient,
|
||||||
).to have_received(:count).with(
|
).to have_received(:count).with(
|
||||||
"data_update_scripts.failures", 1, { tags: ["file_name:#{failed_script.file_name}"] }
|
"data_update_scripts.failures", 1, { tags: ["file_name:#{failed_script.file_name}"] }
|
||||||
).at_least(1)
|
).at_least(1)
|
||||||
|
|
|
||||||
|
|
@ -9,15 +9,15 @@ RSpec.describe Metrics::RecordDailyNotificationsWorker, type: :worker do
|
||||||
let(:event_title_count) { Metrics::RecordDailyNotificationsWorker::EVENT_TITLES.count }
|
let(:event_title_count) { Metrics::RecordDailyNotificationsWorker::EVENT_TITLES.count }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(DatadogStatsClient).to receive(:count)
|
allow(ForemStatsClient).to receive(:count)
|
||||||
ahoy_event
|
ahoy_event
|
||||||
described_class.new.perform
|
described_class.new.perform
|
||||||
end
|
end
|
||||||
|
|
||||||
it "logs welcome notification click events created in the past day" do
|
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(
|
expect(
|
||||||
DatadogStatsClient,
|
ForemStatsClient,
|
||||||
).to have_received(:count)
|
).to have_received(:count)
|
||||||
.with("ahoy_events", 1, { tags: ["title:welcome_notification_welcome_thread"] })
|
.with("ahoy_events", 1, { tags: ["title:welcome_notification_welcome_thread"] })
|
||||||
.at_least(1)
|
.at_least(1)
|
||||||
|
|
|
||||||
|
|
@ -27,43 +27,43 @@ RSpec.describe Metrics::RecordDailyUsageWorker, type: :worker do
|
||||||
|
|
||||||
describe "#perform" do
|
describe "#perform" do
|
||||||
before do
|
before do
|
||||||
allow(DatadogStatsClient).to receive(:count)
|
allow(ForemStatsClient).to receive(:count)
|
||||||
described_class.new.perform
|
described_class.new.perform
|
||||||
end
|
end
|
||||||
|
|
||||||
it "logs articles with at least 15 score" do
|
it "logs articles with at least 15 score" do
|
||||||
expect(
|
expect(
|
||||||
DatadogStatsClient,
|
ForemStatsClient,
|
||||||
).to have_received(:count).with("articles.min_15_score_past_24h", 2, tags: Array).at_least(1)
|
).to have_received(:count).with("articles.min_15_score_past_24h", 2, tags: Array).at_least(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "logs articles with at least comment 15 score" do
|
it "logs articles with at least comment 15 score" do
|
||||||
expect(
|
expect(
|
||||||
DatadogStatsClient,
|
ForemStatsClient,
|
||||||
).to have_received(:count).with("articles.min_15_comment_score_past_24h", 1, tags: Array).at_least(1)
|
).to have_received(:count).with("articles.min_15_comment_score_past_24h", 1, tags: Array).at_least(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "records first articles" do
|
it "records first articles" do
|
||||||
expect(
|
expect(
|
||||||
DatadogStatsClient,
|
ForemStatsClient,
|
||||||
).to have_received(:count).with("articles.first_past_24h", 1, tags: Array).at_least(1)
|
).to have_received(:count).with("articles.first_past_24h", 1, tags: Array).at_least(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "records new users with at least one comment" do
|
it "records new users with at least one comment" do
|
||||||
expect(
|
expect(
|
||||||
DatadogStatsClient,
|
ForemStatsClient,
|
||||||
).to have_received(:count).with("users.new_min_1_comment_past_24h", 2, tags: Array).at_least(1)
|
).to have_received(:count).with("users.new_min_1_comment_past_24h", 2, tags: Array).at_least(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "records negative reactions" do
|
it "records negative reactions" do
|
||||||
expect(
|
expect(
|
||||||
DatadogStatsClient,
|
ForemStatsClient,
|
||||||
).to have_received(:count).with("reactions.negative_past_24h", 1, tags: Array).at_least(1)
|
).to have_received(:count).with("reactions.negative_past_24h", 1, tags: Array).at_least(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "records report feedback_messages" do
|
it "records report feedback_messages" do
|
||||||
expect(
|
expect(
|
||||||
DatadogStatsClient,
|
ForemStatsClient,
|
||||||
).to have_received(:count).with("feedback_messages.reports_past_24_hours", 1, tags: Array).at_least(1)
|
).to have_received(:count).with("feedback_messages.reports_past_24_hours", 1, tags: Array).at_least(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -21,20 +21,20 @@ RSpec.describe Metrics::RecordDataCountsWorker, type: :worker do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "logs estimated counts in Datadog" do
|
it "logs estimated counts in Datadog" do
|
||||||
allow(DatadogStatsClient).to receive(:gauge)
|
allow(ForemStatsClient).to receive(:gauge)
|
||||||
described_class.new.perform
|
described_class.new.perform
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
DatadogStatsClient,
|
ForemStatsClient,
|
||||||
).to have_received(:gauge).with("postgres.db_table_size", 0, tags: Array).at_least(1)
|
).to have_received(:gauge).with("postgres.db_table_size", 0, tags: Array).at_least(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "logs index counts in Datadog" do
|
it "logs index counts in Datadog" do
|
||||||
allow(DatadogStatsClient).to receive(:gauge)
|
allow(ForemStatsClient).to receive(:gauge)
|
||||||
described_class.new.perform
|
described_class.new.perform
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
DatadogStatsClient,
|
ForemStatsClient,
|
||||||
).to have_received(:gauge).with("elasticsearch.document_count", Integer, tags: Array).at_least(1)
|
).to have_received(:gauge).with("elasticsearch.document_count", Integer, tags: Array).at_least(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue