prometheus-api-client 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68b5e8ad6dbe1997d62603c9513afbc071e60866
4
- data.tar.gz: a07c99492ae8c8757ea8a9661545c877ba2f625c
3
+ metadata.gz: ddd53e20644407d4d1a2a11b3e3116e967ac30f5
4
+ data.tar.gz: 0f659ddb1bbfb994550f353913c0dad214f70d6a
5
5
  SHA512:
6
- metadata.gz: 41fa1d531d03bc368bc20827979637d51e8b802aed1d003562eddd8fd1832dda6cba03b92affb6550566b4802eec55eb313b2fa5d17bfc7cec91389d59957166
7
- data.tar.gz: b7d3cf27b368f189bbc28136cdf1101fa9965d6916de13b263b8bf207c5783b6430281b6fd6dad53c523493c295441907585f58652758d869bf38e282de916be
6
+ metadata.gz: fadfded50f9012c9d8e922765b078ba008c48d9ce6edf6742c4e96b1a39758b76ae1e7e3e2d0df6c7e1608ce78ed0b3d3a73266a2bc3ba39178b30c045fda9e7
7
+ data.tar.gz: d0680011ec2ca3fecda3e4daeb66fcd2db1bb92310b03c77842845fd482a7c21f6b455b77acb1e14431da10d1c8f392f022e72cc72319b5293cbfb3f2e41c3df
data/README.md CHANGED
@@ -1,7 +1,16 @@
1
- # Prometheus Ruby Client
1
+ # Prometheus API Ruby Client
2
+
3
+ [![Gem Version][1]](http://badge.fury.io/rb/prometheus-api-client)
4
+ [![Build Status][2]](http://travis-ci.org/yaacov/prometheus_api_client_ruby)
5
+ [![Build Status][3]](https://codeclimate.com/github/yaacov/prometheus_api_client_ruby)
6
+ [![Coverage Status][4]](https://coveralls.io/github/yaacov/prometheus_api_client_ruby?branch=master)
2
7
 
3
8
  A Ruby library for reading Prometheus metrics API.
4
9
 
10
+ ### Authentication proxy
11
+
12
+ If an authentication proxy ( e.g. oauth2 ) is used in a layer above the prometheus REST server, this client can use ssl and authentication headears.
13
+
5
14
  ## Usage
6
15
 
7
16
  ### Overview
@@ -29,3 +38,8 @@ rspec:
29
38
  ```bash
30
39
  rake
31
40
  ```
41
+
42
+ [1]: https://badge.fury.io/rb/prometheus-api-client.svg
43
+ [2]: https://secure.travis-ci.org/yaacov/prometheus_api_client_ruby.svg
44
+ [3]: https://codeclimate.com/github/yaacov/prometheus_api_client_ruby.svg
45
+ [4]: https://coveralls.io/repos/github/yaacov/prometheus_api_client_ruby/badge.svg
@@ -1,28 +1,76 @@
1
1
  # encoding: UTF-8
2
2
 
3
+ require 'uri'
3
4
  require 'faraday'
4
5
 
5
6
  module Prometheus
6
7
  # Client is a ruby implementation for a Prometheus compatible api_client.
7
8
  module ApiClient
9
+ DEFAULT_HOST = 'localhost'.freeze
10
+ DEFAULT_SCHEME = 'http'.freeze
11
+ DEFAULT_PORT = 9090
12
+ DEFAULT_PATH = '/api/v1/'.freeze
13
+ DEFAULT_CREDENTIALS = {}.freeze
14
+ DEFAULT_OPTIONS = {}.freeze
15
+
8
16
  # Returns a default client object
9
- def self.client(uri, credentials={}, options={})
10
- @args = { url: uri.to_s, request: { open_timeout: 2, timeout: 5 } }
11
- @args.merge!(prometheus_args(credentials, options))
17
+ def self.client(host = DEFAULT_HOST, args = {})
18
+ args = {
19
+ scheme: DEFAULT_SCHEME,
20
+ port: DEFAULT_PORT,
21
+ path: DEFAULT_PATH,
22
+ credentials: DEFAULT_CREDENTIALS,
23
+ options: DEFAULT_OPTIONS,
24
+ }.merge(args)
25
+
26
+ Faraday.new(
27
+ prometheus_args(host, args),
28
+ )
29
+ end
30
+
31
+ def self.prometheus_uri(host, scheme, port, path)
32
+ builder = {
33
+ http: URI::HTTP,
34
+ https: URI::HTTPS,
35
+ }[scheme.to_sym]
36
+
37
+ builder.build(
38
+ host: host,
39
+ port: port,
40
+ path: path,
41
+ ).to_s
42
+ end
43
+
44
+ def self.prometheus_proxy(options)
45
+ options[:http_proxy_uri] if options[:http_proxy_uri]
46
+ end
12
47
 
13
- Faraday.new(@args)
48
+ def self.prometheus_verify_ssl(options)
49
+ return unless options[:verify_ssl]
50
+
51
+ {
52
+ verify: options[:verify_ssl] != OpenSSL::SSL::VERIFY_NONE,
53
+ cert_store: options[:ssl_cert_store],
54
+ }
55
+ end
56
+
57
+ def self.prometheus_headers(credentials)
58
+ return unless credentials[:token]
59
+
60
+ {
61
+ Authorization: 'Bearer ' + credentials[:token].to_s,
62
+ }
14
63
  end
15
64
 
16
- def self.prometheus_args(credentials, options)
65
+ def self.prometheus_args(host, args = {})
17
66
  {
18
- proxy: options[:http_proxy_uri],
19
- headers: { Authorization: 'Bearer ' + credentials[:token].to_s },
20
- ssl: if options[:verify_ssl]
21
- {
22
- verify: options[:verify_ssl] != OpenSSL::SSL::VERIFY_NONE,
23
- cert_store: options[:ssl_cert_store],
24
- }
25
- end,
67
+ url: prometheus_uri(
68
+ host, args[:scheme], args[:port], args[:path]
69
+ ),
70
+ proxy: prometheus_proxy(args[:options]),
71
+ ssl: prometheus_verify_ssl(args[:options]),
72
+ headers: prometheus_headers(args[:credentials]),
73
+ request: { open_timeout: 2, timeout: 5 },
26
74
  }
27
75
  end
28
76
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Prometheus
4
4
  module ApiClient
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus-api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaacov Zamir