Skip to content

Commit

Permalink
feat: update metrics output
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Nov 29, 2020
1 parent 66734c8 commit 0617e9d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
8 changes: 5 additions & 3 deletions lib/pact_broker/metrics/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def metrics
webhooks: {
count: PactBroker::Webhooks::Webhook.count
},
tags: {
count: PactBroker::Domain::Tag.count,
distinctCount: PactBroker::Domain::Tag.select(:name).distinct.count,
distinctWithPacticipantCount: PactBroker::Domain::Tag.join(:versions, { id: :version_id }).select_group(:name, :pacticipant_id).count
},
triggeredWebhooks: {
count: PactBroker::Webhooks::TriggeredWebhook.count
},
Expand All @@ -62,9 +67,6 @@ def metrics
},
matrix: {
count: PactBroker::Matrix::Row.count
},
headMatrix: {
count: PactBroker::Matrix::HeadRow.count
}
}
end
Expand Down
32 changes: 23 additions & 9 deletions spec/lib/pact_broker/domain/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,29 @@ module Domain
.create_consumer_version_tag("test")
end

it "returns the latest tags for the given pacticipant ids" do
pacticipant = PactBroker::Domain::Pacticipant.order(:id).first
tags = Tag.latest_tags_for_pacticipant_ids([pacticipant.id]).all
expect(tags.collect(&:name).sort).to eq %w{bloop dev prod}
expect(tags.find{ |t| t.name == "dev" }.version.number).to eq "3"
expect(tags.find{ |t| t.name == "prod" }.version.number).to eq "1"
expect(tags.find{ |t| t.name == "bloop" }.version.number).to eq "2"
expect(tags.collect(&:version_id).compact.size).to eq 3
expect(tags.collect(&:created_at).compact.size).to eq 3
describe "#latest_tags_for_pacticipant_ids" do
it "returns the latest tags for the given pacticipant ids" do
pacticipant = PactBroker::Domain::Pacticipant.order(:id).first
tags = Tag.latest_tags_for_pacticipant_ids([pacticipant.id]).all
expect(tags.collect(&:name).sort).to eq %w{bloop dev prod}
expect(tags.find{ |t| t.name == "dev" }.version.number).to eq "3"
expect(tags.find{ |t| t.name == "prod" }.version.number).to eq "1"
expect(tags.find{ |t| t.name == "bloop" }.version.number).to eq "2"
expect(tags.collect(&:version_id).compact.size).to eq 3
expect(tags.collect(&:created_at).compact.size).to eq 3
end
end

describe "latest_tags" do
it "returns the tags that belong to the most recent version with that tag/pacticipant" do
tags = Tag.latest_tags.all
expect(tags.collect(&:name).sort).to eq %w{bloop dev prod test}
expect(tags.find{ |t| t.name == "dev" }.version.number).to eq "3"
expect(tags.find{ |t| t.name == "prod" }.version.number).to eq "1"
expect(tags.find{ |t| t.name == "bloop" }.version.number).to eq "2"
expect(tags.collect(&:version_id).compact.size).to eq 4
expect(tags.collect(&:created_at).compact.size).to eq 4
end
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion spec/lib/pact_broker/metrics/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ module Service
describe "verificationResultsPerPactVersion" do
before do
td.create_pact_with_hierarchy
.create_consumer_version_tag("prod")
.comment("this pact version will have 2 verifications")
.create_verification
.create_verification(number: 2)
.create_verification(number: 2, tag_names: ["main"])
.revise_pact
.comment("this pact version will have 1 verification")
.create_verification
.create_consumer_version
.create_consumer_version_tag("main")
.create_pact
.comment("this pact will have 1 verification")
.create_verification
.create_consumer_version
.create_consumer_version_tag("main")
.create_pact
.comment("this pact will have 1 verification")
.create_verification
Expand Down

0 comments on commit 0617e9d

Please sign in to comment.