Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/prometheus/api_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ def get(command, options)
def run_command(command, options)
response = get(command, options)

JSON.parse(response.body)['data']
body = JSON.parse(response.body)
raise RequestError, body['error'] if body['status'] != 'success'

body['data']
rescue StandardError => err
raise RequestError, err.message
end
Expand Down
31 changes: 31 additions & 0 deletions spec/prometheus/api_client/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,35 @@
end
end
end

describe '.run_command' do
it 'returns a hash' do
VCR.use_cassette('prometheus/api_client/client') do # , record: :new_episodes) do
prometheus = Prometheus::ApiClient::Client.new(
url: url,
credentials: { token: token },
options: { verify_ssl: OpenSSL::SSL::VERIFY_NONE },
)

response = prometheus.run_command(
"query_range",
{ query: "up", start: "2015-07-01T20:10:30.781Z", end: "2015-07-01T20:11:00.781Z", step: "15s"}
)

expect(response).to eq({ "resultType"=>"matrix", "result"=>[], "explanation" => nil })
end
end

it 'raises on error' do
VCR.use_cassette('prometheus/api_client/client') do # , record: :new_episodes) do
prometheus = Prometheus::ApiClient::Client.new(
url: url,
credentials: { token: token },
options: { verify_ssl: OpenSSL::SSL::VERIFY_NONE },
)

expect { prometheus.run_command("query_ranage", { query: "(not a valid command"}) } .to raise_error(Prometheus::ApiClient::Client::RequestError)
end
end
end
end
88 changes: 88 additions & 0 deletions spec/vcr_cassettes/prometheus/api_client/client.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.