diff --git a/app/models/user.rb b/app/models/user.rb index 6370ed01..725582ef 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -115,6 +115,8 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength raise Errors::AnsweringSelfBlockedOther if self.blocking?(question.user) # rubocop:enable Style/RedundantSelf + Retrospring::Metrics::QUESTIONS_ANSWERED.increment + Answer.create!(content:, user: self, question:) end @@ -128,6 +130,8 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength raise Errors::CommentingOtherBlockedSelf if answer.user.blocking?(self) # rubocop:enable Style/RedundantSelf + Retrospring::Metrics::COMMENTS_CREATED.increment + Comment.create!(user: self, answer:, content:) end diff --git a/lib/retrospring/metrics.rb b/lib/retrospring/metrics.rb index 0072fd81..7259f33f 100644 --- a/lib/retrospring/metrics.rb +++ b/lib/retrospring/metrics.rb @@ -4,7 +4,7 @@ module Retrospring module Metrics PROMETHEUS = Prometheus::Client.registry - # avoid re-registering metrics to make autoreloader happy: + # avoid re-registering metrics to make autoreloader happy during dev: class << self %i[counter gauge histogram summary].each do |meth| define_method meth do |name, *args, **kwargs| @@ -32,5 +32,15 @@ module Retrospring docstring: "How many questions got asked", labels: %i[anonymous followers generated] ) + + QUESTIONS_ANSWERED = counter( + :retrospring_questions_answered_total, + docstring: "How many questions got answered" + ) + + COMMENTS_CREATED = counter( + :retrospring_comments_created_total, + docstring: "How many comments got created" + ) end end