-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'pact_broker/api/resources/base_resource' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class Metrics < BaseResource | ||
def content_types_provided | ||
[["application/hal+json", :to_json]] | ||
end | ||
|
||
def allowed_methods | ||
["GET", "OPTIONS"] | ||
end | ||
|
||
def to_json | ||
metrics_service.metrics.to_json | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'pact_broker/pacts/pact_publication' | ||
require 'pact_broker/pacts/pact_version' | ||
require 'pact_broker/domain/pacticipant' | ||
require 'pact_broker/integrations/integration' | ||
require 'pact_broker/domain/verification' | ||
require 'pact_broker/domain/version' | ||
require 'pact_broker/api/decorators/format_date_time' | ||
require 'pact_broker/webhooks/webhook' | ||
require 'pact_broker/webhooks/triggered_webhook' | ||
require 'pact_broker/webhooks/execution' | ||
|
||
module PactBroker | ||
module Metrics | ||
module Service | ||
include PactBroker::Api::Decorators::FormatDateTime | ||
|
||
extend self | ||
|
||
def metrics | ||
{ | ||
pacticipants: { | ||
count: PactBroker::Domain::Pacticipant.count | ||
}, | ||
integrations: { | ||
count: PactBroker::Integrations::Integration.count | ||
}, | ||
pactPublications: { | ||
count: PactBroker::Pacts::PactPublication.count, | ||
first: format_date_time(PactBroker::Pacts::PactPublication.order(:id).first&.created_at), | ||
last: format_date_time(PactBroker::Pacts::PactPublication.order(:id).last&.created_at) | ||
}, | ||
pactVersions: { | ||
count: PactBroker::Pacts::PactVersion.count | ||
}, | ||
verificationResults: { | ||
count: PactBroker::Domain::Verification.count, | ||
first: format_date_time(PactBroker::Domain::Verification.order(:id).first.created_at), | ||
last: format_date_time(PactBroker::Domain::Verification.order(:id).last.created_at) | ||
}, | ||
pacticipantVersions: { | ||
count: PactBroker::Domain::Version.count | ||
}, | ||
webhooks: { | ||
count: PactBroker::Webhooks::Webhook.count | ||
}, | ||
triggeredWebhooks: { | ||
count: PactBroker::Webhooks::TriggeredWebhook.count | ||
}, | ||
webhookExecutions: { | ||
count: PactBroker::Webhooks::Execution.count | ||
} | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
describe "get metrics" do | ||
let(:path) { "/metrics"} | ||
let(:json_response_body) { JSON.parse(subject.body, symbolize_names: true) } | ||
|
||
subject { get(path) } | ||
|
||
before do | ||
TestDataBuilder.new | ||
.create_consumer("Consumer") | ||
.create_provider("Provider") | ||
.create_consumer_version("1.2.3") | ||
.create_consumer_version_tag("prod") | ||
.create_pact | ||
.create_verification(provider_version: "4.5.6") | ||
.create_webhook | ||
.create_triggered_webhook | ||
.create_webhook_execution | ||
end | ||
|
||
it "returns some metrics" do | ||
expect(json_response_body).to be_instance_of(Hash) | ||
end | ||
end |