Skip to content
This repository was archived by the owner on Sep 29, 2021. It is now read-only.

Commit d4a32a4

Browse files
committed
Change .get() return value to entire http response body
Extend get return value to a hash that also includes 'generationID', in addition to previously returned 'messages'
1 parent 080e6b2 commit d4a32a4

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ alerts = prometheus.get()
3737

3838
alerts = prometheus.get(generation_id: '12497ca8-b597-4590-ac5d-d55af7f3d185', from_index: 34)
3939

40+
Alerts will be returned in a Hash with following keys:
41+
* generationID
42+
* messages
43+
4044
#### Posting alerts
4145
\# post an alert JSON to server
4246

examples/get_alerts.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
prometheus = Prometheus::AlertBufferClient::Client.new(url: 'http://localhost:9099', path: '/topics/test')
55

66
alerts = prometheus.get(generation_id: '12497ca8-b597-4590-ac5d-d55af7f3d185', from_index: 1)
7-
puts alerts
7+
8+
puts "Generation Id: #{alerts['generationID']}"
9+
puts "Alerts: #{alerts['messages']}"

lib/prometheus/alert_buffer_client/client.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@ def initialize(options = {})
4949
# @option options [String] :generation_id Database generation Id.
5050
# @option options [Integer] :from_index Minimal index of alerts to fetch.
5151
#
52+
# @return [Hash] response with keys: generationID, messages
5253
# All alerts will be fetched if options are omitted.
5354
def get(options = {})
5455
response = @client.get do |req|
5556
req.params['generationID'] = options[:generation_id]
5657
req.params['fromIndex'] = options[:from_index]
5758
end
5859

59-
JSON.parse(response.body)['messages']
60+
JSON.parse(response.body)
61+
rescue
62+
raise RequestError, 'Bad response from server'
6063
end
6164

6265
# post alert:

lib/prometheus/alert_buffer_client/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module Prometheus
44
module AlertBufferClient
5-
VERSION = '0.1.0'
5+
VERSION = '0.2.0'
66
end
77
end

0 commit comments

Comments
 (0)