hawkular-client 5.0.0.pre1 → 5.0.0.pre2
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 +4 -4
- data/README.rdoc +0 -1
- data/lib/hawkular/alerts/alerts_api.rb +16 -15
- data/lib/hawkular/base_client.rb +3 -3
- data/lib/hawkular/hawkular_client.rb +33 -21
- data/lib/hawkular/inventory/entities.rb +24 -24
- data/lib/hawkular/inventory/inventory_api.rb +3 -0
- data/lib/hawkular/metrics/metric_api.rb +24 -17
- data/lib/hawkular/metrics/metrics_client.rb +1 -1
- data/lib/hawkular/operations/operations_api.rb +19 -16
- data/lib/hawkular/prometheus/prometheus_api.rb +66 -0
- data/lib/hawkular/version.rb +1 -1
- data/lib/hawkularclient.rb +1 -0
- metadata +55 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 125d32626ed72fe6dab9a3413b025002c3a1dda3
|
4
|
+
data.tar.gz: ae957eb3a34c40d273b1db2c3cb04edeae17639d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adc002be0c18fa0d666c076ab0d34e36571b7c9b6359f3c970850b74326292ecc661668699aa69b68f9358ffc4e8394ccc88fb36e272a60d931c01e263a6b6f7
|
7
|
+
data.tar.gz: a38704b444dd7b832eb9507acd25b1f398e949d10bf4f8705ed4154cd388ff63d56651f42df4da8c2080d555203446f61c658b3f4e1ec4b164392f7dd68c42f2
|
data/README.rdoc
CHANGED
@@ -135,7 +135,6 @@ Check each resource API for a detailed description of what methods are available
|
|
135
135
|
Integration tests are recorded and played against cassettes recorded with VCR
|
136
136
|
(http://www.relishapp.com/vcr/vcr/docs)
|
137
137
|
|
138
|
-
* Edit the endpoint properties in the file +spec/endpoint.yml+ (user, password and host name) if needed
|
139
138
|
* From command line run
|
140
139
|
rake spec
|
141
140
|
* To run the tests against a live server, set +VCR_OFF+ to +1+ as in
|
@@ -182,11 +182,7 @@ module Hawkular::Alerts
|
|
182
182
|
# Obtains action definition/plugin from the server.
|
183
183
|
# @param [String] action_plugin Id of the action plugin to fetch. If nil, all the plugins are fetched
|
184
184
|
def get_action_definition(action_plugin = nil)
|
185
|
-
|
186
|
-
plugins = http_get('plugins')
|
187
|
-
else
|
188
|
-
plugins = [action_plugin]
|
189
|
-
end
|
185
|
+
plugins = action_plugin.nil? ? http_get('plugins') : [action_plugin]
|
190
186
|
ret = {}
|
191
187
|
plugins.each do |p|
|
192
188
|
ret[p] = http_get("/plugins/#{p}")
|
@@ -232,7 +228,8 @@ module Hawkular::Alerts
|
|
232
228
|
# Obtain the alerts for the Trigger with the passed id
|
233
229
|
# @param [String] trigger_id Id of the trigger that has fired the alerts
|
234
230
|
# @return [Array<Alert>] List of alerts for the trigger. Can be empty
|
235
|
-
def get_alerts_for_trigger(trigger_id)
|
231
|
+
def get_alerts_for_trigger(trigger_id)
|
232
|
+
# TODO: add additional filters
|
236
233
|
return [] unless trigger_id
|
237
234
|
|
238
235
|
url = '/?triggerIds=' + trigger_id
|
@@ -254,7 +251,7 @@ module Hawkular::Alerts
|
|
254
251
|
# @param [Array] tenants optional list of tenants. The elements of the array can be any object
|
255
252
|
# convertible to a string
|
256
253
|
# @return [Array<Alert>] List of alerts in the system. Can be empty
|
257
|
-
def alerts(criteria: {}, tenants:nil)
|
254
|
+
def alerts(criteria: {}, tenants: nil)
|
258
255
|
query = generate_query_params(criteria)
|
259
256
|
uri = tenants ? '/admin/alerts/' : '/'
|
260
257
|
ret = http_get(uri + query, multi_tenants_header(tenants))
|
@@ -389,7 +386,7 @@ module Hawkular::Alerts
|
|
389
386
|
attr_accessor :auto_resolve, :auto_resolve_alerts, :tags, :type
|
390
387
|
attr_accessor :tenant, :description, :group, :severity, :event_type, :event_category, :member_of, :data_id_map
|
391
388
|
attr_reader :conditions, :dampenings
|
392
|
-
attr_accessor :enabled, :
|
389
|
+
attr_accessor :enabled, :firing_match, :auto_resolve_match
|
393
390
|
|
394
391
|
def initialize(trigger_hash)
|
395
392
|
return if trigger_hash.nil?
|
@@ -427,9 +424,10 @@ module Hawkular::Alerts
|
|
427
424
|
ret = x.to_s.split('_').collect(&:capitalize).join
|
428
425
|
ret[0, 1].downcase + ret[1..-1]
|
429
426
|
end
|
430
|
-
fields = [
|
431
|
-
|
432
|
-
|
427
|
+
fields = %i[id name enabled severity auto_resolve auto_resolve_alerts
|
428
|
+
event_type event_category description auto_enable auto_disable
|
429
|
+
context type tags member_of data_id_map firing_match
|
430
|
+
auto_resolve_match]
|
433
431
|
|
434
432
|
fields.each do |field|
|
435
433
|
camelized_field = to_camel.call(field)
|
@@ -448,6 +446,7 @@ module Hawkular::Alerts
|
|
448
446
|
class Condition
|
449
447
|
attr_accessor :condition_id, :type, :operator, :threshold
|
450
448
|
attr_accessor :trigger_mode, :data_id, :data2_id, :data2_multiplier
|
449
|
+
attr_accessor :alerter_id, :expression
|
451
450
|
attr_reader :condition_set_size, :condition_set_index, :trigger_id
|
452
451
|
|
453
452
|
def initialize(cond_hash)
|
@@ -461,7 +460,8 @@ module Hawkular::Alerts
|
|
461
460
|
@data2_id = cond_hash['data2Id']
|
462
461
|
@data2_multiplier = cond_hash['data2Multiplier']
|
463
462
|
@trigger_id = cond_hash['triggerId']
|
464
|
-
@
|
463
|
+
@alerter_id = cond_hash['alerterId']
|
464
|
+
@expression = cond_hash['expression']
|
465
465
|
end
|
466
466
|
|
467
467
|
def to_h
|
@@ -476,7 +476,8 @@ module Hawkular::Alerts
|
|
476
476
|
cond_hash['data2Id'] = @data2_id
|
477
477
|
cond_hash['data2Multiplier'] = @data2_multiplier
|
478
478
|
cond_hash['triggerId'] = @trigger_id
|
479
|
-
cond_hash['
|
479
|
+
cond_hash['alerterId'] = @alerter_id
|
480
|
+
cond_hash['expression'] = @expression
|
480
481
|
cond_hash
|
481
482
|
end
|
482
483
|
end
|
@@ -601,8 +602,8 @@ module Hawkular::Alerts
|
|
601
602
|
end
|
602
603
|
|
603
604
|
# for some API back compatibility
|
604
|
-
|
605
|
-
|
605
|
+
alias ackBy ack_by
|
606
|
+
alias resolvedBy resolved_by
|
606
607
|
end
|
607
608
|
|
608
609
|
# Representation of one event.
|
data/lib/hawkular/base_client.rb
CHANGED
@@ -95,7 +95,7 @@ module Hawkular
|
|
95
95
|
opts[:user] = @credentials[:username]
|
96
96
|
opts[:password] = @credentials[:password]
|
97
97
|
# strip @endpoint in case suburl is absolute
|
98
|
-
suburl = suburl[@entrypoint.length, suburl.length] if suburl
|
98
|
+
suburl = suburl[@entrypoint.length, suburl.length] if suburl =~ /^http/
|
99
99
|
RestClient::Resource.new(@entrypoint, opts)[suburl]
|
100
100
|
end
|
101
101
|
|
@@ -131,12 +131,12 @@ module Hawkular
|
|
131
131
|
# @param params [Hash] key-values pairs
|
132
132
|
# @return [String] complete query string to append to a base url, '' if no valid params
|
133
133
|
def generate_query_params(params = {})
|
134
|
-
params = params.
|
134
|
+
params = params.reject { |_k, v| v.nil? || ((v.instance_of? Array) && v.empty?) }
|
135
135
|
return '' if params.empty?
|
136
136
|
|
137
137
|
params.inject('?') do |ret, (k, v)|
|
138
138
|
ret += '&' unless ret == '?'
|
139
|
-
part =
|
139
|
+
part = v.instance_of?(Array) ? "#{k}=#{v.join(',')}" : "#{k}=#{v}"
|
140
140
|
ret + hawk_escape(part)
|
141
141
|
end
|
142
142
|
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
require 'hawkular/inventory/inventory_api'
|
2
|
-
require 'hawkular/metrics/metrics_client'
|
3
2
|
require 'hawkular/alerts/alerts_api'
|
4
3
|
require 'hawkular/tokens/tokens_api'
|
5
4
|
require 'hawkular/operations/operations_api'
|
5
|
+
require 'hawkular/prometheus/prometheus_api'
|
6
6
|
require 'hawkular/base_client'
|
7
7
|
|
8
8
|
module Hawkular
|
9
9
|
class Client
|
10
|
-
attr_reader :inventory, :metrics, :alerts, :operations, :tokens, :state
|
11
|
-
|
12
10
|
def initialize(hash)
|
13
11
|
hash[:credentials] ||= {}
|
14
12
|
hash[:options] ||= {}
|
@@ -18,19 +16,19 @@ module Hawkular
|
|
18
16
|
@state = hash
|
19
17
|
end
|
20
18
|
|
19
|
+
def respond_to_missing?(method_name, include_private = false)
|
20
|
+
delegate_client = client_for_method(method_name)
|
21
|
+
return super if delegate_client.nil?
|
22
|
+
|
23
|
+
method = submethod_name_for(method_name)
|
24
|
+
return super unless delegate_client.respond_to?(method)
|
25
|
+
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
21
29
|
def method_missing(name, *args, &block)
|
22
|
-
|
23
|
-
|
24
|
-
when /^metrics_/ then metrics
|
25
|
-
when /^alerts_/ then alerts
|
26
|
-
when /^operations_/ then operations
|
27
|
-
when /^tokens_/ then tokens
|
28
|
-
else
|
29
|
-
fail Hawkular::ArgumentError, "unknown method prefix `#{name}`, allowed prefixes:"\
|
30
|
-
'`inventory_`, `metrics_`,`alerts_`,`operations_`, `tokens_`'
|
31
|
-
end
|
32
|
-
method = name.to_s.sub(/^[^_]+_/, '')
|
33
|
-
delegate_client.__send__(method, *args, &block)
|
30
|
+
super unless respond_to?(name)
|
31
|
+
client_for_method(name).__send__(submethod_name_for(name), *args, &block)
|
34
32
|
end
|
35
33
|
|
36
34
|
def inventory
|
@@ -39,12 +37,6 @@ module Hawkular
|
|
39
37
|
@state[:options])
|
40
38
|
end
|
41
39
|
|
42
|
-
def metrics
|
43
|
-
@metrics ||= Metrics::Client.new("#{@state[:entrypoint]}/hawkular/metrics",
|
44
|
-
@state[:credentials],
|
45
|
-
@state[:options])
|
46
|
-
end
|
47
|
-
|
48
40
|
def alerts
|
49
41
|
@alerts ||= Alerts::Client.new("#{@state[:entrypoint]}/hawkular/alerts",
|
50
42
|
@state[:credentials],
|
@@ -64,6 +56,12 @@ module Hawkular
|
|
64
56
|
@state[:options])
|
65
57
|
end
|
66
58
|
|
59
|
+
def prometheus
|
60
|
+
@prometheus ||= Prometheus::Client.new(@state[:entrypoint],
|
61
|
+
@state[:credentials],
|
62
|
+
@state[:options])
|
63
|
+
end
|
64
|
+
|
67
65
|
private
|
68
66
|
|
69
67
|
# this is in a dedicated method, because constructor opens the websocket connection to make the handshake
|
@@ -72,5 +70,19 @@ module Hawkular
|
|
72
70
|
credentials: @state[:credentials],
|
73
71
|
options: @state[:options])
|
74
72
|
end
|
73
|
+
|
74
|
+
def client_for_method(method_name)
|
75
|
+
case method_name
|
76
|
+
when /^inventory_/ then inventory
|
77
|
+
when /^alerts_/ then alerts
|
78
|
+
when /^operations_/ then operations
|
79
|
+
when /^tokens_/ then tokens
|
80
|
+
when /^prometheus_/ then prometheus
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def submethod_name_for(method_name)
|
85
|
+
method_name.to_s.sub(/^[^_]+_/, '')
|
86
|
+
end
|
75
87
|
end
|
76
88
|
end
|
@@ -1,32 +1,36 @@
|
|
1
1
|
# It contains class definitions that are used by the inventory REST client
|
2
2
|
module Hawkular::Inventory
|
3
3
|
class Metric
|
4
|
-
# @return [String] Name of the metric
|
4
|
+
# @return [String] Provider Name of the metric
|
5
5
|
attr_reader :name
|
6
|
-
# @return [String]
|
7
|
-
attr_reader :
|
6
|
+
# @return [String] Display Name of the metric
|
7
|
+
attr_reader :display_name
|
8
|
+
# @return [String] Family of the metric (Prometheus family name)
|
9
|
+
attr_reader :family
|
10
|
+
# @return [String] Promql expression for fetching the time series
|
11
|
+
attr_reader :expression
|
8
12
|
# @return [String] Unit of the metric
|
9
13
|
attr_reader :unit
|
14
|
+
# @return [Hash<String,String>] Labels of this metric (Prometheus labels)
|
15
|
+
attr_reader :labels
|
10
16
|
# @return [Hash<String,String>] Properties of this metric
|
11
17
|
attr_reader :properties
|
12
18
|
|
13
19
|
def initialize(hash)
|
14
|
-
@name = hash['
|
15
|
-
@
|
20
|
+
@name = hash['displayName']
|
21
|
+
@display_name = hash['displayName']
|
22
|
+
@family = hash['family']
|
23
|
+
@expression = hash['expression']
|
16
24
|
@unit = hash['unit']
|
25
|
+
@labels = hash['labels'] || {}
|
17
26
|
@properties = hash['properties'] || {}
|
27
|
+
@_hash = hash.dup
|
18
28
|
end
|
19
29
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
def hawkular_type
|
25
|
-
@properties.fetch('hawkular.metric.type')
|
26
|
-
end
|
27
|
-
|
28
|
-
def hawkular_type_id
|
29
|
-
@properties.fetch('hawkular.metric.typeId')
|
30
|
+
# Returns a hash representation of the metric type
|
31
|
+
# @return [Hash<String,Object>] hash of the metric type
|
32
|
+
def to_h
|
33
|
+
@_hash.dup
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
@@ -37,7 +41,7 @@ module Hawkular::Inventory
|
|
37
41
|
|
38
42
|
def initialize(op_hash)
|
39
43
|
@name = op_hash['name']
|
40
|
-
@params =
|
44
|
+
@params = op_hash.key?('parameters') ? op_hash['parameters'] : {}
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
@@ -57,7 +61,7 @@ module Hawkular::Inventory
|
|
57
61
|
end
|
58
62
|
|
59
63
|
def ==(other)
|
60
|
-
|
64
|
+
equal?(other) || other.class == self.class && other.id == @id
|
61
65
|
end
|
62
66
|
|
63
67
|
# Returns a hash representation of the resource type
|
@@ -82,10 +86,6 @@ module Hawkular::Inventory
|
|
82
86
|
attr_reader :properties
|
83
87
|
# @return [Hash<String,String>] Config map of this resource
|
84
88
|
attr_reader :config
|
85
|
-
# @return [List<Metric>] Metrics associated to this resource
|
86
|
-
attr_reader :metrics
|
87
|
-
# @return [List<Resource>] List of children (present when the whole tree is loaded, else nil)
|
88
|
-
attr_reader :children
|
89
89
|
|
90
90
|
def initialize(hash)
|
91
91
|
@id = hash['id']
|
@@ -117,12 +117,12 @@ module Hawkular::Inventory
|
|
117
117
|
children(recursive).collect(&:metrics).flat_map(&:itself).concat(@metrics)
|
118
118
|
end
|
119
119
|
|
120
|
-
def
|
121
|
-
@metrics.select { |m| m.
|
120
|
+
def metrics_by_family(family)
|
121
|
+
@metrics.select { |m| m.family == family }
|
122
122
|
end
|
123
123
|
|
124
124
|
def ==(other)
|
125
|
-
|
125
|
+
equal?(other) || other.class == self.class && other.id == @id
|
126
126
|
end
|
127
127
|
|
128
128
|
# Returns a hash representation of the resource
|
@@ -39,6 +39,9 @@ module Hawkular::Inventory
|
|
39
39
|
def resource(id)
|
40
40
|
hash = http_get(url('/resources/%s', id))
|
41
41
|
Resource.new(hash)
|
42
|
+
rescue ::Hawkular::Exception => e
|
43
|
+
return if e.cause.is_a?(::RestClient::NotFound)
|
44
|
+
raise
|
42
45
|
end
|
43
46
|
|
44
47
|
# Get resource by id with its complete subtree
|
@@ -23,7 +23,8 @@ module Hawkular::Metrics
|
|
23
23
|
# @param starts [Integer] optional timestamp (default now - 8h)
|
24
24
|
# @param ends [Integer] optional timestamp (default now)
|
25
25
|
# @return [Array[Hash]] datapoints
|
26
|
-
def data_by_tags(tags, buckets: nil, bucketDuration:
|
26
|
+
def data_by_tags(tags, buckets: nil, bucketDuration: nil, # rubocop:disable Naming/VariableName
|
27
|
+
start: nil, ends: nil)
|
27
28
|
data = {
|
28
29
|
tags: tags_param(tags), buckets: buckets, bucketDuration: bucketDuration, start: start, end: ends
|
29
30
|
}
|
@@ -56,7 +57,7 @@ module Hawkular::Metrics
|
|
56
57
|
strings.each { |g| default_timestamp g[:data] }
|
57
58
|
data = { gauges: gauges, counters: counters, availabilities: availabilities, strings: strings }
|
58
59
|
path = '/metrics/'
|
59
|
-
@legacy_api ?
|
60
|
+
path << (@legacy_api ? 'data' : 'raw')
|
60
61
|
http_post(path, data)
|
61
62
|
end
|
62
63
|
|
@@ -84,7 +85,7 @@ module Hawkular::Metrics
|
|
84
85
|
path = '/metrics/stats/query'
|
85
86
|
metrics = { gauge: gauge_ids, counter: counter_ids, availability: avail_ids }
|
86
87
|
data = { metrics: metrics, start: starts, end: ends, bucketDuration: bucket_duration }
|
87
|
-
data['types'] = %w
|
88
|
+
data['types'] = %w[gauge gauge_rate counter counter_rate availability] if rates
|
88
89
|
http_post(path, data)
|
89
90
|
end
|
90
91
|
|
@@ -93,9 +94,11 @@ module Hawkular::Metrics
|
|
93
94
|
def tags
|
94
95
|
tags = []
|
95
96
|
http_get('/metrics/').map do |g|
|
97
|
+
next if g['tags'].nil?
|
98
|
+
|
96
99
|
g['tags'].map do |k, v|
|
97
100
|
tags << { k => v }
|
98
|
-
end
|
101
|
+
end
|
99
102
|
end
|
100
103
|
tags.uniq!
|
101
104
|
end
|
@@ -171,7 +174,7 @@ module Hawkular::Metrics
|
|
171
174
|
def push_data(id, data)
|
172
175
|
data = [data] unless data.is_a?(Array)
|
173
176
|
uri = "/#{@resource}/#{ERB::Util.url_encode(id)}/"
|
174
|
-
@legacy_api ?
|
177
|
+
uri << (@legacy_api ? 'data' : 'raw')
|
175
178
|
@client.default_timestamp data
|
176
179
|
@client.http_post(uri, data)
|
177
180
|
end
|
@@ -187,8 +190,8 @@ module Hawkular::Metrics
|
|
187
190
|
# @param order [String] optional Data point sort order, based on timestamp (ASC, DESC)
|
188
191
|
# @return [Array[Hash]] datapoints
|
189
192
|
# @see #push_data #push_data for datapoint detail
|
190
|
-
def get_data(id, starts: nil, ends: nil, bucketDuration: nil,
|
191
|
-
order: nil)
|
193
|
+
def get_data(id, starts: nil, ends: nil, bucketDuration: nil, # rubocop:disable Naming/VariableName
|
194
|
+
buckets: nil, percentiles: nil, limit: nil, order: nil)
|
192
195
|
params = { start: starts, end: ends, bucketDuration: bucketDuration, buckets: buckets,
|
193
196
|
percentiles: percentiles, limit: limit, order: order }
|
194
197
|
get_data_helper(id, params)
|
@@ -214,28 +217,32 @@ module Hawkular::Metrics
|
|
214
217
|
# @param buckets [Integer] optional number of buckets
|
215
218
|
# @return [Array[Hash]] datapoints
|
216
219
|
# @see #push_data #push_data for datapoint detail
|
217
|
-
def get_data_by_tags(tags, starts: nil, ends: nil, bucketDuration: nil,
|
220
|
+
def get_data_by_tags(tags, starts: nil, ends: nil, bucketDuration: nil, # rubocop:disable Naming/VariableName
|
221
|
+
buckets: nil)
|
218
222
|
params = { tags: @client.tags_param(tags), start: starts,
|
219
223
|
end: ends, bucketDuration: bucketDuration, buckets: buckets }
|
220
224
|
path = "/#{@resource}/"
|
221
|
-
@legacy_api ?
|
225
|
+
path << (@legacy_api ? 'data/?' : 'stats/?')
|
222
226
|
resp = @client.http_get(path + encode_params(params))
|
223
227
|
resp.is_a?(Array) ? resp : [] # API returns no content (empty Hash) instead of empty array
|
224
228
|
end
|
225
229
|
|
226
230
|
def encode_params(params)
|
227
|
-
URI.encode_www_form(params.
|
231
|
+
URI.encode_www_form(params.reject { |_k, v| v.nil? })
|
228
232
|
end
|
229
233
|
|
230
234
|
private
|
231
235
|
|
232
236
|
def get_data_helper(id, params)
|
233
237
|
path = "/#{@resource}/#{ERB::Util.url_encode(id)}/"
|
234
|
-
if @legacy_api
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
238
|
+
path << if @legacy_api
|
239
|
+
'data/?'
|
240
|
+
elsif params[:bucketDuration].nil? && params[:buckets].nil?
|
241
|
+
'raw/?'
|
242
|
+
else
|
243
|
+
'stats/?'
|
244
|
+
end
|
245
|
+
|
239
246
|
path << encode_params(params)
|
240
247
|
resp = @client.http_get(path)
|
241
248
|
resp.is_a?(Array) ? resp : [] # API returns no content (empty Hash) instead of empty array
|
@@ -329,8 +336,8 @@ module Hawkular::Metrics
|
|
329
336
|
# @param order [String] optional Data point sort order, based on timestamp (ASC, DESC)
|
330
337
|
# @return [Array[Hash]] datapoints
|
331
338
|
# @see #push_data #push_data for datapoint detail
|
332
|
-
def get_data(id, starts: nil, ends: nil, bucketDuration: nil,
|
333
|
-
|
339
|
+
def get_data(id, starts: nil, ends: nil, bucketDuration: nil, # rubocop:disable Naming/VariableName
|
340
|
+
buckets: nil, distinct: nil, limit: nil, order: nil)
|
334
341
|
params = { start: starts, end: ends, bucketDuration: bucketDuration, buckets: buckets,
|
335
342
|
distinct: distinct, limit: limit, order: order }
|
336
343
|
get_data_helper(id, params)
|
@@ -41,7 +41,7 @@ module Hawkular::Metrics
|
|
41
41
|
version = version_status_hash['Implementation-Version']
|
42
42
|
major, minor = version.scan(/\d+/).map(&:to_i)
|
43
43
|
fail Hawkular::Exception, fail_version_msg if major.nil? || minor.nil?
|
44
|
-
@legacy_api = (major
|
44
|
+
@legacy_api = (major.zero? && minor < 16)
|
45
45
|
end
|
46
46
|
|
47
47
|
# Construct a new Hawkular Metrics client class.
|
@@ -95,7 +95,7 @@ module Hawkular::Operations
|
|
95
95
|
if args[:entrypoint]
|
96
96
|
uri = URI.parse(args[:entrypoint].to_s)
|
97
97
|
args[:host] = "#{uri.host}:#{uri.port}"
|
98
|
-
args[:use_secure_connection] = %w
|
98
|
+
args[:use_secure_connection] = %w[https wss].include?(uri.scheme) ? true : false
|
99
99
|
end
|
100
100
|
|
101
101
|
fail Hawkular::ArgumentError, 'no parameter ":host" or ":entrypoint" given' if args[:host].nil?
|
@@ -153,7 +153,7 @@ module Hawkular::Operations
|
|
153
153
|
# which the operation is about to run, feedId [String], operationName [String]
|
154
154
|
# @param callback [Block] callback that is run after the operation is done
|
155
155
|
def invoke_generic_operation(hash, &callback)
|
156
|
-
required = [
|
156
|
+
required = %i[resourceId feedId operationName]
|
157
157
|
check_pre_conditions hash, required, &callback
|
158
158
|
|
159
159
|
invoke_operation_helper(hash, &callback)
|
@@ -168,7 +168,7 @@ module Hawkular::Operations
|
|
168
168
|
# @param callback [Block] callback that is run after the operation is done
|
169
169
|
def invoke_specific_operation(operation_payload, operation_name, &callback)
|
170
170
|
fail Hawkular::ArgumentError, 'Operation must be specified' if operation_name.nil?
|
171
|
-
required = [
|
171
|
+
required = %i[resourceId feedId]
|
172
172
|
check_pre_conditions operation_payload, required, &callback
|
173
173
|
|
174
174
|
invoke_operation_helper(operation_payload, operation_name, &callback)
|
@@ -190,7 +190,7 @@ module Hawkular::Operations
|
|
190
190
|
def add_deployment(hash, &callback)
|
191
191
|
hash[:enabled] = hash.key?(:enabled) ? hash[:enabled] : true
|
192
192
|
hash[:force_deploy] = hash.key?(:force_deploy) ? hash[:force_deploy] : false
|
193
|
-
required = [
|
193
|
+
required = %i[resource_id feed_id destination_file_name binary_content]
|
194
194
|
check_pre_conditions hash, required, &callback
|
195
195
|
|
196
196
|
operation_payload = prepare_payload_hash([:binary_content], hash)
|
@@ -209,7 +209,7 @@ module Hawkular::Operations
|
|
209
209
|
# @param callback [Block] callback that is run after the operation is done
|
210
210
|
def undeploy(hash, &callback)
|
211
211
|
hash[:remove_content] = hash.key?(:remove_content) ? hash[:remove_content] : true
|
212
|
-
required = [
|
212
|
+
required = %i[resource_id feed_id deployment_name]
|
213
213
|
check_pre_conditions hash, required, &callback
|
214
214
|
|
215
215
|
hash[:destination_file_name] = hash[:deployment_name]
|
@@ -228,7 +228,7 @@ module Hawkular::Operations
|
|
228
228
|
#
|
229
229
|
# @param callback [Block] callback that is run after the operation is done
|
230
230
|
def enable_deployment(hash, &callback)
|
231
|
-
required = [
|
231
|
+
required = %i[resource_id feed_id deployment_name]
|
232
232
|
check_pre_conditions hash, required, &callback
|
233
233
|
|
234
234
|
hash[:destination_file_name] = hash[:deployment_name]
|
@@ -247,7 +247,7 @@ module Hawkular::Operations
|
|
247
247
|
#
|
248
248
|
# @param callback [Block] callback that is run after the operation is done
|
249
249
|
def disable_deployment(hash, &callback)
|
250
|
-
required = [
|
250
|
+
required = %i[resource_id feed_id deployment_name]
|
251
251
|
check_pre_conditions hash, required, &callback
|
252
252
|
|
253
253
|
hash[:destination_file_name] = hash[:deployment_name]
|
@@ -266,7 +266,7 @@ module Hawkular::Operations
|
|
266
266
|
#
|
267
267
|
# @param callback [Block] callback that is run after the operation is done
|
268
268
|
def restart_deployment(hash, &callback)
|
269
|
-
required = [
|
269
|
+
required = %i[resource_id feed_id deployment_name]
|
270
270
|
check_pre_conditions hash, required, &callback
|
271
271
|
|
272
272
|
hash[:destination_file_name] = hash[:deployment_name]
|
@@ -292,8 +292,8 @@ module Hawkular::Operations
|
|
292
292
|
#
|
293
293
|
# @param callback [Block] callback that is run after the operation is done
|
294
294
|
def add_datasource(hash, &callback)
|
295
|
-
required = [
|
296
|
-
|
295
|
+
required = %i[resourceId feedId xaDatasource datasourceName jndiName
|
296
|
+
driverName driverClass connectionUrl]
|
297
297
|
check_pre_conditions hash, required, &callback
|
298
298
|
|
299
299
|
invoke_specific_operation(hash, 'AddDatasource', &callback)
|
@@ -312,8 +312,8 @@ module Hawkular::Operations
|
|
312
312
|
#
|
313
313
|
# @param callback [Block] callback that is run after the operation is done
|
314
314
|
def add_jdbc_driver(hash, &callback)
|
315
|
-
required = [
|
316
|
-
|
315
|
+
required = %i[resource_id feed_id driver_jar_name driver_name module_name
|
316
|
+
driver_class binary_content]
|
317
317
|
check_pre_conditions hash, required, &callback
|
318
318
|
|
319
319
|
operation_payload = prepare_payload_hash([:binary_content], hash)
|
@@ -351,7 +351,7 @@ module Hawkular::Operations
|
|
351
351
|
#
|
352
352
|
# @param callback [Block] callback that is run after the operation is done
|
353
353
|
def update_collection_intervals(hash, &callback)
|
354
|
-
required = [
|
354
|
+
required = %i[resourceId feedId metricTypes availTypes]
|
355
355
|
check_pre_conditions hash, required, &callback
|
356
356
|
invoke_specific_operation(hash, 'UpdateCollectionIntervals', &callback)
|
357
357
|
end
|
@@ -424,15 +424,18 @@ module Hawkular::Operations
|
|
424
424
|
def self.handle_error(parsed_message, &callback)
|
425
425
|
callback.perform(:failure, parsed_message == {} ? 'error' : parsed_message[:data]['errorMessage'])
|
426
426
|
end
|
427
|
+
private_class_method :handle_error
|
427
428
|
|
428
429
|
def prepare_payload_hash(ignored_params, hash)
|
429
430
|
# it filters out ignored params and convert keys from snake_case to camelCase
|
430
|
-
Hash[hash.
|
431
|
+
Hash[hash.reject { |k, _| ignored_params.include? k }.map { |k, v| [to_camel_case(k.to_s).to_sym, v] }]
|
431
432
|
end
|
432
433
|
|
433
434
|
def to_camel_case(str)
|
434
|
-
|
435
|
-
ret
|
435
|
+
subs = str.split('_')
|
436
|
+
ret = subs.length > 1 ? subs.collect(&:capitalize).join : subs[0]
|
437
|
+
ret[0] = ret[0].downcase
|
438
|
+
ret
|
436
439
|
end
|
437
440
|
end
|
438
441
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'hawkular/base_client'
|
2
|
+
require 'hawkular/inventory/entities'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module Hawkular::Prometheus
|
6
|
+
class Alerter < Hawkular::BaseClient
|
7
|
+
def initialize(entrypoint, credentials = {}, options = {})
|
8
|
+
@entrypoint = normalize_entrypoint_url entrypoint, 'hawkular/alerter'
|
9
|
+
super(@entrypoint, credentials, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def prometheus_entrypoint
|
13
|
+
rest_client('/prometheus/endpoint').get
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Interface to talk with the Prometheus server used for Middleware Manager
|
18
|
+
# @param entrypoint [String] base url of Hawkular Services
|
19
|
+
class Client < Hawkular::BaseClient
|
20
|
+
attr_reader :entrypoint
|
21
|
+
|
22
|
+
def initialize(entrypoint, credentials = {}, options = {})
|
23
|
+
prometheus_entrypoint = Alerter.new(entrypoint, credentials, options).prometheus_entrypoint
|
24
|
+
@entrypoint = normalize_entrypoint_url prometheus_entrypoint, 'api/v1'
|
25
|
+
super(@entrypoint, credentials, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def query(metrics: [], time: nil)
|
29
|
+
results = []
|
30
|
+
metrics.each do |metric|
|
31
|
+
query = metric['expression']
|
32
|
+
response = http_get "/query?start=#{time}&query=#{query}"
|
33
|
+
result = response['data']['result'].empty? ? {} : response['data']['result'].first
|
34
|
+
result['metric'] = metric
|
35
|
+
results << result
|
36
|
+
end
|
37
|
+
results
|
38
|
+
end
|
39
|
+
|
40
|
+
def query_range(metrics: [], starts: nil, ends: nil, step: nil)
|
41
|
+
results = []
|
42
|
+
metrics.each do |metric|
|
43
|
+
query = metric['expression']
|
44
|
+
response = http_get "/query_range?start=#{starts}&end=#{ends}&step=#{step}&query=#{query}"
|
45
|
+
result = response['data']['result'].empty? ? {} : response['data']['result'].first
|
46
|
+
result['metric'] = metric
|
47
|
+
results << result
|
48
|
+
end
|
49
|
+
results
|
50
|
+
end
|
51
|
+
|
52
|
+
def up_time(feed_id: nil, starts: nil, ends: nil, step: nil)
|
53
|
+
query = "up{feed_id=\"#{feed_id}\"}"
|
54
|
+
response = http_get "/query_range?start=#{starts}&end=#{ends}&step=#{step}&query=#{query}"
|
55
|
+
if response['data']['result'].empty?
|
56
|
+
[]
|
57
|
+
else
|
58
|
+
response['data']['result'].first['values']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def ping
|
63
|
+
http_get '/query?query=up'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/hawkular/version.rb
CHANGED
data/lib/hawkularclient.rb
CHANGED
@@ -4,5 +4,6 @@ require 'hawkular/metrics/metrics_client'
|
|
4
4
|
require 'hawkular/alerts/alerts_api'
|
5
5
|
require 'hawkular/tokens/tokens_api'
|
6
6
|
require 'hawkular/operations/operations_api'
|
7
|
+
require 'hawkular/prometheus/prometheus_api'
|
7
8
|
require 'hawkular/base_client'
|
8
9
|
require 'hawkular/hawkular_client'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hawkular-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.0.
|
4
|
+
version: 5.0.0.pre2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Libor Zoubek
|
@@ -11,22 +11,36 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2020-09-03 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: addressable
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
16
30
|
- !ruby/object:Gem::Dependency
|
17
31
|
name: rest-client
|
18
32
|
requirement: !ruby/object:Gem::Requirement
|
19
33
|
requirements:
|
20
34
|
- - "~>"
|
21
35
|
- !ruby/object:Gem::Version
|
22
|
-
version: 2.
|
36
|
+
version: '2.1'
|
23
37
|
type: :runtime
|
24
38
|
prerelease: false
|
25
39
|
version_requirements: !ruby/object:Gem::Requirement
|
26
40
|
requirements:
|
27
41
|
- - "~>"
|
28
42
|
- !ruby/object:Gem::Version
|
29
|
-
version: 2.
|
43
|
+
version: '2.1'
|
30
44
|
- !ruby/object:Gem::Dependency
|
31
45
|
name: websocket-client-simple
|
32
46
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,21 +56,21 @@ dependencies:
|
|
42
56
|
- !ruby/object:Gem::Version
|
43
57
|
version: 0.3.0
|
44
58
|
- !ruby/object:Gem::Dependency
|
45
|
-
name:
|
59
|
+
name: actionpack
|
46
60
|
requirement: !ruby/object:Gem::Requirement
|
47
61
|
requirements:
|
48
|
-
- - "
|
62
|
+
- - "~>"
|
49
63
|
- !ruby/object:Gem::Version
|
50
|
-
version: '
|
51
|
-
type: :
|
64
|
+
version: '4'
|
65
|
+
type: :development
|
52
66
|
prerelease: false
|
53
67
|
version_requirements: !ruby/object:Gem::Requirement
|
54
68
|
requirements:
|
55
|
-
- - "
|
69
|
+
- - "~>"
|
56
70
|
- !ruby/object:Gem::Version
|
57
|
-
version: '
|
71
|
+
version: '4'
|
58
72
|
- !ruby/object:Gem::Dependency
|
59
|
-
name:
|
73
|
+
name: coveralls
|
60
74
|
requirement: !ruby/object:Gem::Requirement
|
61
75
|
requirements:
|
62
76
|
- - ">="
|
@@ -70,33 +84,33 @@ dependencies:
|
|
70
84
|
- !ruby/object:Gem::Version
|
71
85
|
version: '0'
|
72
86
|
- !ruby/object:Gem::Dependency
|
73
|
-
name:
|
87
|
+
name: pry-byebug
|
74
88
|
requirement: !ruby/object:Gem::Requirement
|
75
89
|
requirements:
|
76
|
-
- - "
|
90
|
+
- - ">="
|
77
91
|
- !ruby/object:Gem::Version
|
78
|
-
version: '
|
92
|
+
version: '0'
|
79
93
|
type: :development
|
80
94
|
prerelease: false
|
81
95
|
version_requirements: !ruby/object:Gem::Requirement
|
82
96
|
requirements:
|
83
|
-
- - "
|
97
|
+
- - ">="
|
84
98
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
99
|
+
version: '0'
|
86
100
|
- !ruby/object:Gem::Dependency
|
87
|
-
name:
|
101
|
+
name: rack
|
88
102
|
requirement: !ruby/object:Gem::Requirement
|
89
103
|
requirements:
|
90
104
|
- - "~>"
|
91
105
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
106
|
+
version: 1.6.4
|
93
107
|
type: :development
|
94
108
|
prerelease: false
|
95
109
|
version_requirements: !ruby/object:Gem::Requirement
|
96
110
|
requirements:
|
97
111
|
- - "~>"
|
98
112
|
- !ruby/object:Gem::Version
|
99
|
-
version:
|
113
|
+
version: 1.6.4
|
100
114
|
- !ruby/object:Gem::Dependency
|
101
115
|
name: rake
|
102
116
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,49 +126,35 @@ dependencies:
|
|
112
126
|
- !ruby/object:Gem::Version
|
113
127
|
version: '11'
|
114
128
|
- !ruby/object:Gem::Dependency
|
115
|
-
name:
|
116
|
-
requirement: !ruby/object:Gem::Requirement
|
117
|
-
requirements:
|
118
|
-
- - '='
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
version: 0.1.0
|
121
|
-
type: :development
|
122
|
-
prerelease: false
|
123
|
-
version_requirements: !ruby/object:Gem::Requirement
|
124
|
-
requirements:
|
125
|
-
- - '='
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
version: 0.1.0
|
128
|
-
- !ruby/object:Gem::Dependency
|
129
|
-
name: yard
|
129
|
+
name: rspec-rails
|
130
130
|
requirement: !ruby/object:Gem::Requirement
|
131
131
|
requirements:
|
132
|
-
- - "
|
132
|
+
- - "~>"
|
133
133
|
- !ruby/object:Gem::Version
|
134
|
-
version: '
|
134
|
+
version: '3.1'
|
135
135
|
type: :development
|
136
136
|
prerelease: false
|
137
137
|
version_requirements: !ruby/object:Gem::Requirement
|
138
138
|
requirements:
|
139
|
-
- - "
|
139
|
+
- - "~>"
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version: '
|
141
|
+
version: '3.1'
|
142
142
|
- !ruby/object:Gem::Dependency
|
143
|
-
name:
|
143
|
+
name: rubocop
|
144
144
|
requirement: !ruby/object:Gem::Requirement
|
145
145
|
requirements:
|
146
|
-
- -
|
146
|
+
- - '='
|
147
147
|
- !ruby/object:Gem::Version
|
148
|
-
version:
|
148
|
+
version: 0.51.0
|
149
149
|
type: :development
|
150
150
|
prerelease: false
|
151
151
|
version_requirements: !ruby/object:Gem::Requirement
|
152
152
|
requirements:
|
153
|
-
- -
|
153
|
+
- - '='
|
154
154
|
- !ruby/object:Gem::Version
|
155
|
-
version:
|
155
|
+
version: 0.51.0
|
156
156
|
- !ruby/object:Gem::Dependency
|
157
|
-
name:
|
157
|
+
name: shoulda
|
158
158
|
requirement: !ruby/object:Gem::Requirement
|
159
159
|
requirements:
|
160
160
|
- - ">="
|
@@ -168,21 +168,21 @@ dependencies:
|
|
168
168
|
- !ruby/object:Gem::Version
|
169
169
|
version: '0'
|
170
170
|
- !ruby/object:Gem::Dependency
|
171
|
-
name:
|
171
|
+
name: simple-websocket-vcr
|
172
172
|
requirement: !ruby/object:Gem::Requirement
|
173
173
|
requirements:
|
174
174
|
- - '='
|
175
175
|
- !ruby/object:Gem::Version
|
176
|
-
version: 0.
|
176
|
+
version: 0.1.0
|
177
177
|
type: :development
|
178
178
|
prerelease: false
|
179
179
|
version_requirements: !ruby/object:Gem::Requirement
|
180
180
|
requirements:
|
181
181
|
- - '='
|
182
182
|
- !ruby/object:Gem::Version
|
183
|
-
version: 0.
|
183
|
+
version: 0.1.0
|
184
184
|
- !ruby/object:Gem::Dependency
|
185
|
-
name:
|
185
|
+
name: vcr
|
186
186
|
requirement: !ruby/object:Gem::Requirement
|
187
187
|
requirements:
|
188
188
|
- - ">="
|
@@ -196,21 +196,21 @@ dependencies:
|
|
196
196
|
- !ruby/object:Gem::Version
|
197
197
|
version: '0'
|
198
198
|
- !ruby/object:Gem::Dependency
|
199
|
-
name:
|
199
|
+
name: webmock
|
200
200
|
requirement: !ruby/object:Gem::Requirement
|
201
201
|
requirements:
|
202
202
|
- - "~>"
|
203
203
|
- !ruby/object:Gem::Version
|
204
|
-
version:
|
204
|
+
version: '3.0'
|
205
205
|
type: :development
|
206
206
|
prerelease: false
|
207
207
|
version_requirements: !ruby/object:Gem::Requirement
|
208
208
|
requirements:
|
209
209
|
- - "~>"
|
210
210
|
- !ruby/object:Gem::Version
|
211
|
-
version:
|
211
|
+
version: '3.0'
|
212
212
|
- !ruby/object:Gem::Dependency
|
213
|
-
name:
|
213
|
+
name: yard
|
214
214
|
requirement: !ruby/object:Gem::Requirement
|
215
215
|
requirements:
|
216
216
|
- - ">="
|
@@ -223,7 +223,7 @@ dependencies:
|
|
223
223
|
- - ">="
|
224
224
|
- !ruby/object:Gem::Version
|
225
225
|
version: '0'
|
226
|
-
description:
|
226
|
+
description: A Ruby client for Hawkular
|
227
227
|
email:
|
228
228
|
- lzoubek@redhat.com
|
229
229
|
- hrupp@redhat.com
|
@@ -250,6 +250,7 @@ files:
|
|
250
250
|
- lib/hawkular/metrics/tenant_api.rb
|
251
251
|
- lib/hawkular/metrics/types.rb
|
252
252
|
- lib/hawkular/operations/operations_api.rb
|
253
|
+
- lib/hawkular/prometheus/prometheus_api.rb
|
253
254
|
- lib/hawkular/tokens/tokens_api.rb
|
254
255
|
- lib/hawkular/version.rb
|
255
256
|
- lib/hawkularclient.rb
|
@@ -279,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
279
280
|
version: 1.3.1
|
280
281
|
requirements: []
|
281
282
|
rubyforge_project:
|
282
|
-
rubygems_version: 2.6.
|
283
|
+
rubygems_version: 2.6.14
|
283
284
|
signing_key:
|
284
285
|
specification_version: 4
|
285
286
|
summary: A Ruby client for Hawkular
|