From 4369f22771c6c6f32fd459f4056de07da31aaa7c Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Tue, 8 Oct 2019 17:27:54 +1100 Subject: [PATCH] feat(metrics): add revision count --- lib/pact_broker/metrics/service.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) 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