Skip to content

Commit

Permalink
Merge a57f62f into 5e16541
Browse files Browse the repository at this point in the history
  • Loading branch information
colszowka committed Nov 21, 2016
2 parents 5e16541 + a57f62f commit 1451f7a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ Style/TrailingCommaInLiteral:

Metrics/AbcSize:
Max: 18

Style/GuardClause:
Enabled: false
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ group :test do
gem 'rack-test'
gem 'rake'
gem 'rspec'
gem 'rubocop', ruby_version?('< 2.0') ? '< 0.42' : nil
gem 'rubocop', ruby_version?('< 2.0') ? '< 0.42' : '~> 0.45.0'
gem 'tins', '< 1.7' if ruby_version?('< 2.0')
# 1.4+ is not compatible with ruby 1.9
gem 'term-ansicolor', '~> 1.3.2'
end
4 changes: 3 additions & 1 deletion lib/prometheus/client/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Push
PATH = '/metrics/jobs/%s'.freeze
INSTANCE_PATH = '/metrics/jobs/%s/instances/%s'.freeze
HEADER = { 'Content-Type' => Formats::Text::CONTENT_TYPE }.freeze
SUPPORTED_SCHEMES = %w(http https).freeze

attr_reader :job, :instance, :gateway, :path

Expand All @@ -26,6 +27,7 @@ def initialize(job, instance = nil, gateway = nil)
@uri = parse(@gateway)
@path = build_path(job, instance)
@http = Net::HTTP.new(@uri.host, @uri.port)
@http.use_ssl = @uri.scheme == 'https'
end

def add(registry)
Expand All @@ -45,7 +47,7 @@ def delete
def parse(url)
uri = URI.parse(url)

if uri.scheme == 'http'
if SUPPORTED_SCHEMES.include? uri.scheme
uri
else
raise ArgumentError, 'only HTTP gateway URLs are supported currently.'
Expand Down
2 changes: 1 addition & 1 deletion spec/prometheus/client/counter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:counter) { Prometheus::Client::Counter.new(:foo, 'foo description') }

it_behaves_like Prometheus::Client::Metric do
let(:type) { Fixnum }
let(:type) { Integer }
end

describe '#increment' do
Expand Down
19 changes: 18 additions & 1 deletion spec/prometheus/client/push_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,33 @@
end

describe '#add' do
it 'pushes a given registry to the configured Pushgateway' do
it 'pushes a given registry to the configured Pushgateway via HTTP' do
http = double(:http)
expect(http).to receive(:send_request).with(
'POST',
'/metrics/jobs/foo/instances/bar',
Prometheus::Client::Formats::Text.marshal(registry),
'Content-Type' => Prometheus::Client::Formats::Text::CONTENT_TYPE,
)
expect(http).to receive(:use_ssl=).with(false)
expect(Net::HTTP).to receive(:new).with('pu.sh', 9091).and_return(http)

described_class.new('foo', 'bar', 'http://pu.sh:9091').add(registry)
end

it 'pushes a given registry to the configured Pushgateway via HTTPS' do
http = double(:http)
expect(http).to receive(:send_request).with(
'POST',
'/metrics/jobs/foo/instances/bar',
Prometheus::Client::Formats::Text.marshal(registry),
'Content-Type' => Prometheus::Client::Formats::Text::CONTENT_TYPE,
)
expect(http).to receive(:use_ssl=).with(true)
expect(Net::HTTP).to receive(:new).with('pu.sh', 9091).and_return(http)

described_class.new('foo', 'bar', 'https://pu.sh:9091').add(registry)
end
end

describe '#replace' do
Expand All @@ -75,6 +90,7 @@
Prometheus::Client::Formats::Text.marshal(registry),
'Content-Type' => Prometheus::Client::Formats::Text::CONTENT_TYPE,
)
expect(http).to receive(:use_ssl=).with(false)
expect(Net::HTTP).to receive(:new).with('pu.sh', 9091).and_return(http)

described_class.new('foo', 'bar', 'http://pu.sh:9091').replace(registry)
Expand All @@ -88,6 +104,7 @@
'DELETE',
'/metrics/jobs/foo/instances/bar',
)
expect(http).to receive(:use_ssl=).with(false)
expect(Net::HTTP).to receive(:new).with('pu.sh', 9091).and_return(http)

described_class.new('foo', 'bar', 'http://pu.sh:9091').delete
Expand Down

0 comments on commit 1451f7a

Please sign in to comment.