Class: GrafanaReporter::QueryValueQuery

Inherits:
AbstractQuery show all
Defined in:
lib/grafana_reporter/query_value_query.rb

Overview

This class provides a general query implementation for any kind of single value and table queries.

Instance Attribute Summary

Attributes inherited from AbstractQuery

#dashboard, #datasource, #panel, #result, #variables

Instance Method Summary collapse

Methods inherited from AbstractQuery

#execute, #filter_columns, #format_columns, #format_table_output, #initialize, #replace_values, #timeout, #translate_date, #transpose

Constructor Details

This class inherits a constructor from GrafanaReporter::AbstractQuery

Instance Method Details

#post_processObject

Executes AbstractQuery#format_columns, AbstractQuery#replace_values and AbstractQuery#filter_columns on the query results.

Finally the results are formatted as a asciidoctor table.

See Also:

  • Grafana::AbstractQuery#post_process


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/grafana_reporter/query_value_query.rb', line 21

def post_process
  modify_results

  case @variables['result_type'].raw_value
  when 'object'

  when /(?:panel_table|sql_table)/
    @result = format_table_output(@result, row_divider: @variables['row_divider'],
                                           column_divider: @variables['column_divider'],
                                           table_formatter: @variables['table_formatter'],
                                           include_headline: @variables['include_headline'],
                                           transpose: @variables['transpose'])

  when /(?:panel_value|sql_value)/
    tmp = @result[:content] || []
    @result = tmp.flatten.first

  else
    raise StandardError, "Unsupported 'result_type' received: '#{@variables['result_type'].raw_value}'"

  end
end

#pre_processObject

See Also:

  • Grafana::AbstractQuery#pre_process


7
8
9
10
11
12
13
14
# File 'lib/grafana_reporter/query_value_query.rb', line 7

def pre_process
  if @panel
    @panel.resolve_variable_datasource(@variables)
    @datasource = @panel.datasource
  end

  @variables['result_type'] ||= Variable.new('')
end

#raw_queryObject

See Also:

  • Grafana::AbstractQuery#raw_query


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/grafana_reporter/query_value_query.rb', line 45

def raw_query
  return @raw_query if @raw_query

  case @variables['result_type'].raw_value
  when /(?:panel_table|panel_value)/
    @variables['query'] ? @panel.query(@variables['query'].raw_value) : @panel.query(nil)

  when /(?:sql_table|sql_value)/
    nil

  else
    raise StandardError, "Unsupported 'result_type' received: '#{@variables['result_type'].raw_value}'"

  end
end