Class: WavefrontDisplay::Query

Inherits:
Base
  • Object
show all
Defined in:
lib/wavefront-cli/display/query.rb

Overview

Format human-readable output for queries.

Constant Summary

Constants included from WavefrontCli::Constants

WavefrontCli::Constants::ALL_PAGE_SIZE, WavefrontCli::Constants::DEFAULT_CONFIG, WavefrontCli::Constants::DEFAULT_OPTS, WavefrontCli::Constants::EVENT_STATE_DIR, WavefrontCli::Constants::HUMAN_TIME_FORMAT, WavefrontCli::Constants::HUMAN_TIME_FORMAT_MS, WavefrontCli::Constants::SEARCH_SPLIT

Instance Attribute Summary

Attributes inherited from Base

#data, #options, #raw

Instance Method Summary collapse

Methods inherited from Base

#_prioritize_keys, #display_brief_freetext_results, #do_delete, #do_import, #do_list, #do_list_brief, #do_list_fields, #do_queries, #do_search, #do_search_brief, #do_search_fields, #do_tag_add, #do_tag_clear, #do_tag_delete, #do_tag_pathsearch, #do_tag_set, #do_tags, #do_undelete, #drop_fields, #filter_data, #filter_fields_as_arr, #freetext_keys, #friendly_name, #human_time, #index_of_final_item, #initialize, #key_width, #long_output, #multicolumn, #pagination_line, #priority_keys, #quoted, #readable_time, #readable_time_arr, #run, #run_error, #run_list, #run_search, #search_display_keys, #search_identifier_key, #time_formats

Constructor Details

This class inherits a constructor from WavefrontDisplay::Base

Instance Method Details

#default_data_objectObject

rubocop:disable Metrics/AbcSize



20
21
22
23
24
25
26
27
28
29
# File 'lib/wavefront-cli/display/query.rb', line 20

def default_data_object
  { name: data.name,
    query: data.query,
    timeseries: mk_timeseries(data),
    traces: mk_traces(data),
    spans: mk_spans(data),
    events: mk_events(data) }.tap do |d|
      d[:warnings] = data[:warnings] if show_warnings?
    end
end

#do_aliasesObject



85
86
87
88
89
90
91
# File 'lib/wavefront-cli/display/query.rb', line 85

def do_aliases
  if data.empty?
    puts 'No aliases defined.'
  else
    data.each_key { |k| puts k.to_s[2..] }
  end
end

#do_defaultObject



11
12
13
14
15
16
17
# File 'lib/wavefront-cli/display/query.rb', line 11

def do_default
  @data = default_data_object
  long_output
rescue StandardError
  raise(WavefrontCli::Exception::InvalidQuery,
        data[:errorMessage].split("\n").first)
end

#do_rawObject



77
78
79
# File 'lib/wavefront-cli/display/query.rb', line 77

def do_raw
  data.each { |ts| puts humanize_series(ts[:points]).join("\n") }
end

#do_raw_404Object



81
82
83
# File 'lib/wavefront-cli/display/query.rb', line 81

def do_raw_404
  puts 'API 404: metric does not exist.'
end

#do_runObject



73
74
75
# File 'lib/wavefront-cli/display/query.rb', line 73

def do_run
  do_default
end

#mk_events(data) ⇒ Object



55
56
57
58
59
# File 'lib/wavefront-cli/display/query.rb', line 55

def mk_events(data)
  return [] unless data.key?(:events)

  data[:events].map { |s| humanize_event(s) }
end

#mk_spans(data) ⇒ Object



67
68
69
70
71
# File 'lib/wavefront-cli/display/query.rb', line 67

def mk_spans(data)
  return [] unless data.key?(:spans)

  data[:spans].map { |t| humanize_span(t) }
end

#mk_timeseries(data) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/wavefront-cli/display/query.rb', line 42

def mk_timeseries(data)
  return [] unless data.key?(:timeseries)

  data[:timeseries].each do |s|
    unless options[:nospark]
      s[:sparkline] = WavefrontSparkline.new(s[:data]).sparkline
      s.reorder!(label: nil, sparkline: nil)
    end

    s[:data] = humanize_series(s[:data])
  end
end

#mk_traces(data) ⇒ Object



61
62
63
64
65
# File 'lib/wavefront-cli/display/query.rb', line 61

def mk_traces(data)
  return [] unless data.key?(:traces)

  data[:traces].map { |t| humanize_trace(t) }
end

#prioritize_keys(data, _keys) ⇒ Object

Prioritizing keys does not make sense in this context



38
39
40
# File 'lib/wavefront-cli/display/query.rb', line 38

def prioritize_keys(data, _keys)
  data
end

#show_warnings?Boolean

rubocop:enable Metrics/AbcSize

Returns:

  • (Boolean)


32
33
34
# File 'lib/wavefront-cli/display/query.rb', line 32

def show_warnings?
  data.key?(:warnings) && !options[:nowarn]
end