ruby-grafana-reporter 0.5.4 → 0.6.0
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.md +1 -0
- data/lib/VERSION.rb +2 -2
- data/lib/grafana/abstract_datasource.rb +1 -0
- data/lib/grafana/dashboard.rb +8 -1
- data/lib/grafana/grafana.rb +15 -1
- data/lib/grafana/prometheus_datasource.rb +61 -13
- data/lib/grafana/variable.rb +1 -1
- data/lib/grafana_reporter/abstract_query.rb +2 -2
- data/lib/grafana_reporter/asciidoctor/panel_query_value_inline_macro.rb +0 -0
- data/lib/grafana_reporter/panel_property_query.rb +0 -0
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e198f995d87598512fbe2a4578edf8be48630bab415d14c5348cf23a57e47df7
|
4
|
+
data.tar.gz: c1f5a3c85ba1081fbfc0b526b1c4e15412d146a8f88af897a0620fd762687482
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e5af10cd799f63a8ac662db422cebe1a8f7d1484c5e29e54ec73280c966efc7a57059c5fbe2bef2717b27fe6c2fa1c22c819fce3c851d98d568fd556291d933
|
7
|
+
data.tar.gz: 97c1477d8e97a6afa096d7dc4557d4ae15e9aee87ca541af165f898f3cfd1a20d002e2b06c68c98dd4f0c436299129e766e0023f34b6f1a2639d4fcabcfde73d
|
data/README.md
CHANGED
@@ -310,6 +310,7 @@ webservice or a rendering process starts.
|
|
310
310
|
This is just a collection of things, I am heading for in future, without a schedule.
|
311
311
|
|
312
312
|
* Support grafana internal datasources
|
313
|
+
* Support additional templating variable types
|
313
314
|
* Solve code TODOs
|
314
315
|
* Become [rubocop](https://rubocop.org/) ready
|
315
316
|
|
data/lib/VERSION.rb
CHANGED
@@ -82,6 +82,7 @@ module Grafana
|
|
82
82
|
# }
|
83
83
|
#
|
84
84
|
# @param query_description [Hash] query description, which will requested:
|
85
|
+
# @option query_description [String] :grafana_version grafana version, for which the request is to be prepared
|
85
86
|
# @option query_description [String] :from +from+ timestamp
|
86
87
|
# @option query_description [String] :to +to+ timestamp
|
87
88
|
# @option query_description [Integer] :timeout expected timeout for the request
|
data/lib/grafana/dashboard.rb
CHANGED
@@ -58,7 +58,14 @@ module Grafana
|
|
58
58
|
list = @model['templating']['list']
|
59
59
|
return unless list.is_a? Array
|
60
60
|
|
61
|
-
list.each
|
61
|
+
list.each do |item|
|
62
|
+
begin
|
63
|
+
@variables << Variable.new(item, self)
|
64
|
+
rescue => e
|
65
|
+
# TODO: show this message as a warning - needs test cleanup
|
66
|
+
@grafana.logger.debug(e.message)
|
67
|
+
end
|
68
|
+
end
|
62
69
|
end
|
63
70
|
|
64
71
|
# read panels
|
data/lib/grafana/grafana.rb
CHANGED
@@ -86,7 +86,15 @@ module Grafana
|
|
86
86
|
# @param datasource_uid [String] unique id of the searched datasource
|
87
87
|
# @return [Datasource] Datasource for the specified datasource unique id
|
88
88
|
def datasource_by_uid(datasource_uid)
|
89
|
-
datasource = @datasources.select
|
89
|
+
datasource = @datasources.select do |ds_name, ds|
|
90
|
+
if (ds.nil?)
|
91
|
+
# print debug info for https://github.com/divinity666/ruby-grafana-reporter/issues/29
|
92
|
+
@logger.warn("Datasource with name #{ds_name} is nil, which should never happen. Check logs for details.")
|
93
|
+
false
|
94
|
+
else
|
95
|
+
ds.uid == datasource_uid
|
96
|
+
end
|
97
|
+
end.values.first
|
90
98
|
raise DatasourceDoesNotExistError.new('uid', datasource_uid) unless datasource
|
91
99
|
|
92
100
|
datasource
|
@@ -156,6 +164,12 @@ module Grafana
|
|
156
164
|
json = JSON.parse(settings.body)
|
157
165
|
json['datasources'].select { |_k, v| v['id'].to_i.positive? }.each do |ds_name, ds_value|
|
158
166
|
@datasources[ds_name] = AbstractDatasource.build_instance(ds_value)
|
167
|
+
|
168
|
+
# print debug info for https://github.com/divinity666/ruby-grafana-reporter/issues/29
|
169
|
+
if @datasources[ds_name].nil?
|
170
|
+
@logger.error("Datasource with name '#{ds_name}' and configuration: '#{ds_value}' could not be initialized.")
|
171
|
+
@datasources.delete(ds_name)
|
172
|
+
end
|
159
173
|
end
|
160
174
|
@datasources['default'] = @datasources[json['defaultDatasource']]
|
161
175
|
end
|
@@ -24,21 +24,15 @@ module Grafana
|
|
24
24
|
interval = interval.raw_value if interval.is_a?(Variable)
|
25
25
|
query = query_hash[:query] || query_description[:raw_query]
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
ver = query_description[:grafana_version].split('.').map{|x| x.to_i}
|
28
|
+
request = nil
|
29
|
+
if (ver[0] == 7 and ver[1] < 5) or ver[0] < 7
|
30
|
+
request = prepare_get_request({query_description: query_description, instant: instant, interval: interval, query: query})
|
30
31
|
else
|
31
|
-
|
32
|
-
"&end=#{query_description[:to]}"\
|
33
|
-
"&query=#{CGI.escape(replace_variables(query, query_description[:variables]))}"\
|
34
|
-
"&step=#{interval}"
|
32
|
+
request = prepare_post_request({query_description: query_description, instant: instant, interval: interval, query: query})
|
35
33
|
end
|
36
34
|
|
37
|
-
|
38
|
-
webrequest.relative_url = url
|
39
|
-
webrequest.options.merge!({ request: Net::HTTP::Get })
|
40
|
-
|
41
|
-
result = webrequest.execute(query_description[:timeout])
|
35
|
+
result = request.execute(query_description[:timeout])
|
42
36
|
preformat_response(result.body)
|
43
37
|
end
|
44
38
|
|
@@ -54,13 +48,67 @@ module Grafana
|
|
54
48
|
end
|
55
49
|
|
56
50
|
private
|
51
|
+
def prepare_get_request(hash)
|
52
|
+
url = if hash[:instant]
|
53
|
+
"/api/datasources/proxy/#{id}/api/v1/query?time=#{hash[:query_description][:to]}&query="\
|
54
|
+
"#{CGI.escape(replace_variables(hash[:query], hash[:query_description][:variables]))}"
|
55
|
+
else
|
56
|
+
"/api/datasources/proxy/#{id}/api/v1/query_range?start=#{hash[:query_description][:from]}"\
|
57
|
+
"&end=#{hash[:query_description][:to]}"\
|
58
|
+
"&query=#{CGI.escape(replace_variables(hash[:query], hash[:query_description][:variables]))}"\
|
59
|
+
"&step=#{hash[:interval]}"
|
60
|
+
end
|
61
|
+
|
62
|
+
webrequest = hash[:query_description][:prepared_request]
|
63
|
+
webrequest.relative_url = url
|
64
|
+
webrequest.options.merge!({ request: Net::HTTP::Get })
|
65
|
+
|
66
|
+
webrequest
|
67
|
+
end
|
68
|
+
|
69
|
+
def prepare_post_request(hash)
|
70
|
+
webrequest = hash[:query_description][:prepared_request]
|
71
|
+
webrequest.relative_url = '/api/ds/query'
|
72
|
+
|
73
|
+
params = {
|
74
|
+
from: hash[:query_description][:from],
|
75
|
+
to: hash[:query_description][:to],
|
76
|
+
queries: [{
|
77
|
+
datasource: { type: type, uid: uid },
|
78
|
+
datasourceId: id,
|
79
|
+
exemplar: false,
|
80
|
+
expr: hash[:query],
|
81
|
+
format: 'time_series',
|
82
|
+
interval: '',
|
83
|
+
# intervalFactor: ### 2,
|
84
|
+
# intervalMs: ### 15000,
|
85
|
+
# legendFormat: '', ### {{job}}
|
86
|
+
# maxDataPoints: 999,
|
87
|
+
metric: '',
|
88
|
+
queryType: 'timeSeriesQuery',
|
89
|
+
refId: 'A',
|
90
|
+
# requestId: '14A',
|
91
|
+
# utcOffsetSec: 7200,
|
92
|
+
step: hash[:interval]
|
93
|
+
}],
|
94
|
+
range: {
|
95
|
+
#from: ### "2022-07-31T16:19:26.198Z",
|
96
|
+
#to: ### "2022-07-31T16:19:26.198Z",
|
97
|
+
raw: { from: hash[:query_description][:variables]['from'].raw_value, to: hash[:query_description][:variables]['to'].raw_value }
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
webrequest.options.merge!({ request: Net::HTTP::Post, body: params.to_json })
|
102
|
+
|
103
|
+
webrequest
|
104
|
+
end
|
57
105
|
|
58
106
|
def preformat_response(response_body)
|
59
107
|
# TODO: show raw response body to debug case https://github.com/divinity666/ruby-grafana-reporter/issues/24
|
60
108
|
begin
|
61
109
|
return preformat_dataframe_response(response_body)
|
62
110
|
rescue
|
63
|
-
# TODO: show an info, that the response
|
111
|
+
# TODO: show an info, that the response is not a dataframe
|
64
112
|
end
|
65
113
|
|
66
114
|
json = JSON.parse(response_body)
|
data/lib/grafana/variable.rb
CHANGED
@@ -240,7 +240,7 @@ module Grafana
|
|
240
240
|
if !@config['current'].nil?
|
241
241
|
self.raw_value = @config['current']['value']
|
242
242
|
else
|
243
|
-
raise GrafanaError.new("Grafana variable with type '#{@config['type']}' and name '#{@config['name']}'
|
243
|
+
raise GrafanaError.new("Grafana variable with type '#{@config['type']}' and name '#{@config['name']}' cannot be handled properly by the reporter. Check your results and raise a ticket on github.")
|
244
244
|
end
|
245
245
|
end
|
246
246
|
end
|
@@ -13,7 +13,6 @@ module GrafanaReporter
|
|
13
13
|
attr_reader :variables, :result, :panel, :dashboard
|
14
14
|
|
15
15
|
def timeout
|
16
|
-
# TODO: PRIO check where value priorities should be evaluated
|
17
16
|
return @variables['timeout'].raw_value if @variables['timeout']
|
18
17
|
return @variables['grafana_default_timeout'].raw_value if @variables['grafana_default_timeout']
|
19
18
|
|
@@ -81,7 +80,8 @@ module GrafanaReporter
|
|
81
80
|
|
82
81
|
begin
|
83
82
|
@result = @datasource.request(from: from, to: to, raw_query: raw_query, variables: @variables,
|
84
|
-
prepared_request: @grafana.prepare_request, timeout: timeout
|
83
|
+
prepared_request: @grafana.prepare_request, timeout: timeout,
|
84
|
+
grafana_version: @grafana.version)
|
85
85
|
rescue ::Grafana::GrafanaError
|
86
86
|
# grafana errors will be directly passed through
|
87
87
|
raise
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-grafana-reporter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Kohlmeyer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rubyzip
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,7 +178,7 @@ licenses:
|
|
178
178
|
metadata:
|
179
179
|
source_code_uri: https://github.com/divinity666/ruby-grafana-reporter
|
180
180
|
bug_tracker_uri: https://github.com/divinity666/ruby-grafana-reporter/issues
|
181
|
-
post_install_message:
|
181
|
+
post_install_message:
|
182
182
|
rdoc_options: []
|
183
183
|
require_paths:
|
184
184
|
- lib
|
@@ -186,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
186
|
requirements:
|
187
187
|
- - ">="
|
188
188
|
- !ruby/object:Gem::Version
|
189
|
-
version: '2.
|
189
|
+
version: '2.7'
|
190
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - ">="
|
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
196
|
rubygems_version: 3.2.5
|
197
|
-
signing_key:
|
197
|
+
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Reporter Service for Grafana
|
200
200
|
test_files: []
|