diff --git a/lib/pact_broker/metrics/service.rb b/lib/pact_broker/metrics/service.rb index 67af5bc7c..3bb06b137 100644 --- a/lib/pact_broker/metrics/service.rb +++ b/lib/pact_broker/metrics/service.rb @@ -34,6 +34,9 @@ def metrics pactVersions: { count: PactBroker::Pacts::PactVersion.count }, + pactRevisions: { + counts: pact_revision_counts + }, verificationResults: { count: PactBroker::Domain::Verification.count, first: format_date_time(PactBroker::Domain::Verification.order(:id).first.created_at), @@ -59,6 +62,13 @@ def metrics } } end + + def pact_revision_counts + query = "select revision_count as number_of_revisions, count(consumer_version_id) as consumer_version_count + from (select consumer_version_id, count(*) as revision_count from pact_publications group by consumer_version_id) foo + group by revision_count" + PactBroker::Pacts::PactPublication.db[query].all.each_with_object({}) { |row, hash| hash[row[:number_of_revisions]] = row[:consumer_version_count] } + end end end end