Last active
February 23, 2020 11:38
-
-
Save prashanth-sams/c5b1553d1876f0c11f6304366548f663 to your computer and use it in GitHub Desktop.
Ruby Client Exporter for Prometheus server
This file contains hidden or 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
RSpec.configure do |config| | |
config.before(:all) do | |
@prometheus = Prometheus::Client.registry | |
@http_requests = Prometheus::Client::Counter.new(:website_baseline, docstring: 'desktop tests', labels: [:passed, :failed, :pending]) | |
@prometheus.register(@http_requests) | |
$data ||= [] | |
$passed = 0 | |
$failed ||= 0 | |
$pending ||= 0 | |
end | |
config.after(:each) do |scenario| | |
if (scenario.exception) && (!scenario.exception.message.include? 'pending') | |
status_id = 0 | |
message = scenario.exception.message | |
elsif scenario.skipped? | |
status_id = 2 | |
message = "This test scenario is skipped from test execution" | |
elsif scenario.pending? | |
status_id = 2 | |
message = "This test scenario is pending for test execution" | |
else | |
status_id = 1 | |
message = "This test scenario was automated and passed successfully" | |
end | |
$data << {'status_id' => status_id, 'scenario' => scenario.description, 'comment' => message} | |
end | |
config.after(:all) do | |
$data.map do |value| | |
$failed += 1 if value['status_id'] == 0 | |
$passed += 1 if value['status_id'] == 1 | |
$pending += 1 if value['status_id'] == 2 | |
end | |
@http_requests.increment(labels: { passed: $passed, failed: $failed, pending: $pending }) | |
Prometheus::Client::Push.new('desktop').add(@prometheus) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment