Skip to content

Commit 1f9346b

Browse files
committed
more tests
1 parent 6cb0628 commit 1f9346b

File tree

5 files changed

+276
-10
lines changed

5 files changed

+276
-10
lines changed

lib/prometheus/api_client/cadvisor.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def initialize(options = {})
5757
# A client with special labels for container cadvisor metrics
5858
class Container < CadvisorClient
5959
def initialize(options = {})
60-
container_name = args[:container_name]
61-
pod_name = args[:pod_name]
62-
namespace = args[:namespace] || 'default'
60+
container_name = options[:container_name]
61+
pod_name = options[:pod_name]
62+
namespace = options[:namespace] || 'default'
6363

6464
@labels = "job=\"kubernetes-cadvisor\",namespace=\"#{namespace}\"," \
6565
"pod_name=\"#{pod_name}\",container_name=\"#{container_name}\""

spec/prometheus/api_client/cadvisor_spec.rb

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
end
1111

1212
describe Prometheus::ApiClient::Cadvisor do
13-
token = 'topSecret'
13+
token = 'toSecret'
1414
url = 'https://prometheus.example.com:443'
1515
instance = 'example.com'
16+
pod_name = 'prometheus'
17+
container_name = 'hawkular'
1618

1719
describe 'Node' do
1820
it 'reads metrics' do
@@ -53,4 +55,86 @@
5355
end
5456
end
5557
end
58+
59+
describe 'Pod' do
60+
it 'reads metrics' do
61+
VCR.use_cassette('prometheus/api_client/cadvisor_pod') do # , record: :new_episodes) do
62+
prometheus = Prometheus::ApiClient::Cadvisor::Pod.new(
63+
pod_name: pod_name,
64+
url: url,
65+
credentials: { token: token },
66+
options: { verify_ssl: OpenSSL::SSL::VERIFY_NONE },
67+
)
68+
69+
response = prometheus.query(
70+
query: 'sum(container_cpu_usage_seconds_total)',
71+
time: '2017-08-07T06:10:30.781Z',
72+
)
73+
74+
expect(response).to be_a(Hash)
75+
end
76+
end
77+
78+
it 'reads metrics range' do
79+
VCR.use_cassette('prometheus/api_client/cadvisor_pod') do # , record: :new_episodes) do
80+
prometheus = Prometheus::ApiClient::Cadvisor::Pod.new(
81+
pod_name: pod_name,
82+
url: url,
83+
credentials: { token: token },
84+
options: { verify_ssl: OpenSSL::SSL::VERIFY_NONE },
85+
)
86+
87+
response = prometheus.query_range(
88+
query: 'sum(container_cpu_usage_seconds_total)',
89+
start: '2017-08-07T06:10:30.781Z',
90+
end: '2017-08-07T06:14:30.781Z',
91+
step: '120s',
92+
)
93+
94+
expect(response).to be_a(Hash)
95+
end
96+
end
97+
end
98+
99+
describe 'Container' do
100+
it 'reads metrics' do
101+
VCR.use_cassette('prometheus/api_client/cadvisor_container') do # , record: :new_episodes) do
102+
prometheus = Prometheus::ApiClient::Cadvisor::Container.new(
103+
container_name: container_name,
104+
pod_name: pod_name,
105+
url: url,
106+
credentials: { token: token },
107+
options: { verify_ssl: OpenSSL::SSL::VERIFY_NONE },
108+
)
109+
110+
response = prometheus.query(
111+
query: 'sum(container_cpu_usage_seconds_total)',
112+
time: '2017-08-07T06:10:30.781Z',
113+
)
114+
115+
expect(response).to be_a(Hash)
116+
end
117+
end
118+
119+
it 'reads metrics range' do
120+
VCR.use_cassette('prometheus/api_client/cadvisor_container') do # , record: :new_episodes) do
121+
prometheus = Prometheus::ApiClient::Cadvisor::Container.new(
122+
container_name: container_name,
123+
pod_name: pod_name,
124+
url: url,
125+
credentials: { token: token },
126+
options: { verify_ssl: OpenSSL::SSL::VERIFY_NONE },
127+
)
128+
129+
response = prometheus.query_range(
130+
query: 'sum(container_cpu_usage_seconds_total)',
131+
start: '2017-08-07T06:10:30.781Z',
132+
end: '2017-08-07T06:14:30.781Z',
133+
step: '120s',
134+
)
135+
136+
expect(response).to be_a(Hash)
137+
end
138+
end
139+
end
56140
end

spec/vcr_cassettes/prometheus/api_client/cadvisor_container.yml

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/vcr_cassettes/prometheus/api_client/cadvisor_node.yml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/vcr_cassettes/prometheus/api_client/cadvisor_pod.yml

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)