Skip to content

Commit

Permalink
feat(metrics): add revision count
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 8, 2019
1 parent 5fb705e commit 4369f22
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/pact_broker/metrics/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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

0 comments on commit 4369f22

Please sign in to comment.