ruby-grafana-reporter 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -0
- data/lib/VERSION.rb +2 -2
- data/lib/grafana/abstract_datasource.rb +5 -0
- data/lib/grafana/dashboard.rb +0 -0
- data/lib/grafana/errors.rb +7 -0
- data/lib/grafana/grafana.rb +11 -0
- data/lib/grafana/grafana_environment_datasource.rb +0 -0
- data/lib/grafana/graphite_datasource.rb +3 -0
- data/lib/grafana/image_rendering_datasource.rb +0 -0
- data/lib/grafana/influxdb_datasource.rb +6 -1
- data/lib/grafana/panel.rb +5 -1
- data/lib/grafana/prometheus_datasource.rb +30 -1
- data/lib/grafana/sql_datasource.rb +8 -4
- data/lib/grafana/variable.rb +0 -0
- data/lib/grafana/webrequest.rb +0 -0
- data/lib/grafana_reporter/abstract_query.rb +0 -1
- data/lib/grafana_reporter/abstract_report.rb +0 -0
- data/lib/grafana_reporter/abstract_table_format_strategy.rb +0 -0
- data/lib/grafana_reporter/alerts_table_query.rb +0 -0
- data/lib/grafana_reporter/annotations_table_query.rb +0 -0
- data/lib/grafana_reporter/application/webservice.rb +0 -0
- data/lib/grafana_reporter/asciidoctor/adoc_plain_table_format_strategy.rb +0 -0
- data/lib/grafana_reporter/asciidoctor/panel_image_block_macro.rb +0 -0
- data/lib/grafana_reporter/asciidoctor/panel_image_inline_macro.rb +0 -0
- data/lib/grafana_reporter/asciidoctor/processor_mixin.rb +0 -0
- data/lib/grafana_reporter/asciidoctor/show_environment_include_processor.rb +0 -0
- data/lib/grafana_reporter/asciidoctor/sql_value_inline_macro.rb +0 -0
- data/lib/grafana_reporter/asciidoctor/value_as_variable_include_processor.rb +0 -0
- data/lib/grafana_reporter/console_configuration_wizard.rb +0 -0
- data/lib/grafana_reporter/csv_table_format_strategy.rb +0 -0
- data/lib/grafana_reporter/demo_report_wizard.rb +0 -0
- data/lib/grafana_reporter/errors.rb +0 -0
- data/lib/grafana_reporter/panel_image_query.rb +0 -0
- data/lib/grafana_reporter/query_value_query.rb +0 -0
- data/lib/grafana_reporter/reporter_environment_datasource.rb +0 -0
- data/lib/ruby_grafana_reporter.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de6063d128d57f930e83b17253e34e4e20624ef796e7eb86df2e7d54bee7825c
|
4
|
+
data.tar.gz: a6a5f8b3bfcdcfc557ede19e7d89a25de8dca277806da0f662c4165d0a05b03c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9338b1dbd16a81af0c28feb9e8f4efd576ffb3f879aae7dd5d31b00468b32cc18ee49e7a73f87e952e2781845cd1d54124512aef6112194379d3840322fbff8
|
7
|
+
data.tar.gz: 01bed067acfc6442e62ba17dbda3491e6147778a274c65ccacc7f838e57beda53809e8a8b827fad09266b4b506c2e29d7e8d3b0670c506eb0063eddd40d1aa26
|
data/README.md
CHANGED
File without changes
|
data/lib/VERSION.rb
CHANGED
data/lib/grafana/dashboard.rb
CHANGED
File without changes
|
data/lib/grafana/errors.rb
CHANGED
@@ -71,4 +71,11 @@ module Grafana
|
|
71
71
|
super("The datasource query provided, does not look like a grafana datasource target (received: #{query}).")
|
72
72
|
end
|
73
73
|
end
|
74
|
+
|
75
|
+
# Raised if a datasource query returned with an unsupported result
|
76
|
+
class UnsupportedQueryResponseReceivedError < GrafanaError
|
77
|
+
def initialize(response)
|
78
|
+
super("The datasource request returned with an unsupported response format (received: #{response}).")
|
79
|
+
end
|
80
|
+
end
|
74
81
|
end
|
data/lib/grafana/grafana.rb
CHANGED
@@ -81,6 +81,17 @@ module Grafana
|
|
81
81
|
@datasources[datasource_name]
|
82
82
|
end
|
83
83
|
|
84
|
+
# Returns the datasource, which has been queried by the datasource uid.
|
85
|
+
#
|
86
|
+
# @param datasource_uid [String] unique id of the searched datasource
|
87
|
+
# @return [Datasource] Datasource for the specified datasource unique id
|
88
|
+
def datasource_by_uid(datasource_uid)
|
89
|
+
datasource = @datasources.select { |_name, ds| ds.uid == datasource_uid }.values.first
|
90
|
+
raise DatasourceDoesNotExistError.new('uid', datasource_uid) unless datasource
|
91
|
+
|
92
|
+
datasource
|
93
|
+
end
|
94
|
+
|
84
95
|
# Returns the datasource, which has been queried by the datasource id.
|
85
96
|
#
|
86
97
|
# @param datasource_id [Integer] id of the searched datasource
|
File without changes
|
@@ -47,6 +47,9 @@ module Grafana
|
|
47
47
|
def preformat_response(response_body)
|
48
48
|
json = JSON.parse(response_body)
|
49
49
|
|
50
|
+
raise UnsupportedQueryResponseReceivedError, response_body if json.first['target'].nil?
|
51
|
+
raise UnsupportedQueryResponseReceivedError, response_body if json.first['datapoints'].nil?
|
52
|
+
|
50
53
|
header = ['time']
|
51
54
|
content = {}
|
52
55
|
|
File without changes
|
@@ -130,7 +130,12 @@ module Grafana
|
|
130
130
|
# @see AbstractDatasource#preformat_response
|
131
131
|
def preformat_response(response_body)
|
132
132
|
# TODO: how to handle multiple query results?
|
133
|
-
json = JSON.parse(response_body)
|
133
|
+
json = JSON.parse(response_body)
|
134
|
+
raise UnsupportedQueryResponseReceivedError, response_body if json['results'].nil?
|
135
|
+
raise UnsupportedQueryResponseReceivedError, response_body if json['results'].first.nil?
|
136
|
+
raise UnsupportedQueryResponseReceivedError, response_body if json['results'].first['series'].nil?
|
137
|
+
|
138
|
+
json = json['results'].first['series']
|
134
139
|
return {} if json.nil?
|
135
140
|
|
136
141
|
header = ['time']
|
data/lib/grafana/panel.rb
CHANGED
@@ -28,7 +28,11 @@ module Grafana
|
|
28
28
|
|
29
29
|
# @return [Datasource] datasource object specified for the current panel
|
30
30
|
def datasource
|
31
|
-
|
31
|
+
if @model['datasource'].is_a?(Hash)
|
32
|
+
dashboard.grafana.datasource_by_uid(@model['datasource']['uid'])
|
33
|
+
else
|
34
|
+
dashboard.grafana.datasource_by_name(@model['datasource'])
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
38
|
# @return [String] query string for the requested query letter
|
@@ -57,16 +57,45 @@ module Grafana
|
|
57
57
|
|
58
58
|
# @see AbstractDatasource#preformat_response
|
59
59
|
def preformat_response(response_body)
|
60
|
-
json =
|
60
|
+
json = {}
|
61
|
+
begin
|
62
|
+
json = JSON.parse(response_body)
|
63
|
+
rescue
|
64
|
+
raise UnsupportedQueryResponseReceivedError, response_body
|
65
|
+
end
|
61
66
|
|
62
67
|
# handle response with error result
|
63
68
|
unless json['error'].nil?
|
64
69
|
return { header: ['error'], content: [[ json['error'] ]] }
|
65
70
|
end
|
66
71
|
|
72
|
+
# handle dataframes
|
73
|
+
if json['results']
|
74
|
+
data = json['results'].values.first
|
75
|
+
raise UnsupportedQueryResponseReceivedError, response_body if data.nil?
|
76
|
+
raise UnsupportedQueryResponseReceivedError, response_body if data['frames'].nil?
|
77
|
+
# TODO: check how multiple frames have to be handled
|
78
|
+
|
79
|
+
data = data['frames']
|
80
|
+
headers = []
|
81
|
+
data.first['schema']['fields'].each do |headline|
|
82
|
+
header = headline['config']['displayNameFromDS'].nil? ? headline['name'] : headline['config']['displayNameFromDS']
|
83
|
+
headers << header
|
84
|
+
end
|
85
|
+
content = data.first['data']['values'][0].zip(data.first['data']['values'][1])
|
86
|
+
return { header: headers, content: content }
|
87
|
+
end
|
88
|
+
|
89
|
+
# handle former result formats
|
90
|
+
raise UnsupportedQueryResponseReceivedError, response_body if json['data'].nil?
|
91
|
+
raise UnsupportedQueryResponseReceivedError, response_body if json['data']['resultType'].nil?
|
92
|
+
raise UnsupportedQueryResponseReceivedError, response_body if json['data']['result'].nil?
|
93
|
+
|
67
94
|
result_type = json['data']['resultType']
|
68
95
|
json = json['data']['result']
|
69
96
|
|
97
|
+
raise UnsupportedQueryResponseReceivedError, response_body if not result_type =~ /^(?:scalar|string|vector|matrix)$/
|
98
|
+
|
70
99
|
headers = ['time']
|
71
100
|
content = {}
|
72
101
|
|
@@ -57,12 +57,16 @@ module Grafana
|
|
57
57
|
results[:header] = results[:header] + ['SQL Error']
|
58
58
|
results[:content] = [[query_result['error']]]
|
59
59
|
|
60
|
-
elsif query_result
|
61
|
-
query_result['tables']
|
62
|
-
|
63
|
-
|
60
|
+
elsif query_result.key?('tables')
|
61
|
+
if query_result['tables']
|
62
|
+
query_result['tables'].each do |table|
|
63
|
+
results[:header] = results[:header] + table['columns'].map { |header| header['text'] }
|
64
|
+
results[:content] = table['rows']
|
65
|
+
end
|
64
66
|
end
|
65
67
|
|
68
|
+
else
|
69
|
+
raise UnsupportedQueryResponseReceivedError, response_body
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
data/lib/grafana/variable.rb
CHANGED
File without changes
|
data/lib/grafana/webrequest.rb
CHANGED
File without changes
|
@@ -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
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -18,6 +18,17 @@ require 'asciidoctor-pdf'
|
|
18
18
|
require 'zip'
|
19
19
|
require_relative 'VERSION'
|
20
20
|
|
21
|
+
# TODO: add test for variable replacement for sql
|
22
|
+
# TODO: check why value is All instead of $__all
|
23
|
+
# TODO: check why single sql values are replaced including ticks, whereas grafana does not do so
|
24
|
+
|
25
|
+
# TODO: add FAQ for fixing most common issues with the reporter
|
26
|
+
# TODO: implement an easy function to document a whole dashboard at once with different presentations
|
27
|
+
# TODO: add automated test against grafana playground before building a new release
|
28
|
+
# TODO: allow registration of files to be defined in config file
|
29
|
+
# TODO: append necessary variables on demo report creation for plain SQL queries, as they are lacking the grafana reference
|
30
|
+
# TODO: make demo report more readable
|
31
|
+
|
21
32
|
folders = [
|
22
33
|
%w[grafana],
|
23
34
|
%w[grafana_reporter logger],
|
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.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Kohlmeyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|