wavefront-cli 2.4.0 → 2.5.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.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +16 -0
  3. data/.travis.yml +5 -5
  4. data/HISTORY.md +91 -0
  5. data/README.md +1 -2
  6. data/lib/wavefront-cli/alert.rb +1 -1
  7. data/lib/wavefront-cli/base.rb +1 -1
  8. data/lib/wavefront-cli/base_write.rb +1 -1
  9. data/lib/wavefront-cli/cloudintegration.rb +1 -1
  10. data/lib/wavefront-cli/commands/alert.rb +1 -1
  11. data/lib/wavefront-cli/commands/cloudintegration.rb +1 -1
  12. data/lib/wavefront-cli/commands/dashboard.rb +3 -3
  13. data/lib/wavefront-cli/commands/derivedmetric.rb +48 -0
  14. data/lib/wavefront-cli/commands/event.rb +1 -1
  15. data/lib/wavefront-cli/commands/integration.rb +1 -1
  16. data/lib/wavefront-cli/commands/link.rb +1 -1
  17. data/lib/wavefront-cli/commands/message.rb +1 -1
  18. data/lib/wavefront-cli/commands/metric.rb +1 -1
  19. data/lib/wavefront-cli/commands/notificant.rb +1 -1
  20. data/lib/wavefront-cli/commands/proxy.rb +1 -1
  21. data/lib/wavefront-cli/commands/query.rb +6 -4
  22. data/lib/wavefront-cli/commands/report.rb +1 -1
  23. data/lib/wavefront-cli/commands/savedsearch.rb +1 -1
  24. data/lib/wavefront-cli/commands/source.rb +1 -1
  25. data/lib/wavefront-cli/commands/user.rb +1 -1
  26. data/lib/wavefront-cli/commands/webhook.rb +1 -1
  27. data/lib/wavefront-cli/commands/window.rb +1 -1
  28. data/lib/wavefront-cli/commands/write.rb +1 -1
  29. data/lib/wavefront-cli/controller.rb +3 -3
  30. data/lib/wavefront-cli/dashboard.rb +1 -1
  31. data/lib/wavefront-cli/derivedmetric.rb +53 -0
  32. data/lib/wavefront-cli/display/alert.rb +1 -1
  33. data/lib/wavefront-cli/display/cloudintegration.rb +1 -1
  34. data/lib/wavefront-cli/display/dashboard.rb +1 -1
  35. data/lib/wavefront-cli/display/derivedmetric.rb +14 -0
  36. data/lib/wavefront-cli/display/event.rb +1 -1
  37. data/lib/wavefront-cli/display/externallink.rb +1 -1
  38. data/lib/wavefront-cli/display/integration.rb +1 -1
  39. data/lib/wavefront-cli/display/maintenancewindow.rb +1 -1
  40. data/lib/wavefront-cli/display/message.rb +1 -1
  41. data/lib/wavefront-cli/display/metric.rb +1 -1
  42. data/lib/wavefront-cli/display/notificant.rb +1 -1
  43. data/lib/wavefront-cli/display/printer/long.rb +1 -1
  44. data/lib/wavefront-cli/display/printer/sparkline.rb +54 -0
  45. data/lib/wavefront-cli/display/printer/terse.rb +1 -1
  46. data/lib/wavefront-cli/display/proxy.rb +1 -1
  47. data/lib/wavefront-cli/display/query.rb +30 -21
  48. data/lib/wavefront-cli/display/report.rb +1 -1
  49. data/lib/wavefront-cli/display/savedsearch.rb +1 -1
  50. data/lib/wavefront-cli/display/source.rb +1 -1
  51. data/lib/wavefront-cli/display/user.rb +1 -1
  52. data/lib/wavefront-cli/display/webhook.rb +1 -1
  53. data/lib/wavefront-cli/display/write.rb +1 -1
  54. data/lib/wavefront-cli/event.rb +1 -1
  55. data/lib/wavefront-cli/externallink.rb +1 -1
  56. data/lib/wavefront-cli/integration.rb +1 -1
  57. data/lib/wavefront-cli/maintenancewindow.rb +1 -1
  58. data/lib/wavefront-cli/message.rb +1 -1
  59. data/lib/wavefront-cli/metric.rb +1 -1
  60. data/lib/wavefront-cli/notificant.rb +1 -1
  61. data/lib/wavefront-cli/opt_handler.rb +1 -1
  62. data/lib/wavefront-cli/proxy.rb +1 -1
  63. data/lib/wavefront-cli/query.rb +1 -1
  64. data/lib/wavefront-cli/savedsearch.rb +1 -1
  65. data/lib/wavefront-cli/source.rb +1 -1
  66. data/lib/wavefront-cli/string.rb +13 -6
  67. data/lib/wavefront-cli/user.rb +1 -1
  68. data/lib/wavefront-cli/version.rb +1 -1
  69. data/lib/wavefront-cli/webhook.rb +1 -1
  70. data/spec/spec_helper.rb +16 -16
  71. data/spec/wavefront-cli/commands/alert_spec.rb +1 -1
  72. data/spec/wavefront-cli/commands/base_spec.rb +1 -1
  73. data/spec/wavefront-cli/commands/cloudintegration_spec.rb +1 -1
  74. data/spec/wavefront-cli/commands/dashboard_spec.rb +1 -1
  75. data/spec/wavefront-cli/commands/derivedmetric_spec.rb +16 -0
  76. data/spec/wavefront-cli/commands/event_spec.rb +1 -1
  77. data/spec/wavefront-cli/commands/link_spec.rb +1 -1
  78. data/spec/wavefront-cli/commands/message_spec.rb +1 -1
  79. data/spec/wavefront-cli/commands/metric_spec.rb +1 -1
  80. data/spec/wavefront-cli/commands/proxy_spec.rb +1 -1
  81. data/spec/wavefront-cli/commands/query_spec.rb +1 -1
  82. data/spec/wavefront-cli/commands/webhook_spec.rb +1 -1
  83. data/spec/wavefront-cli/commands/window_spec.rb +1 -1
  84. data/spec/wavefront-cli/commands/write_spec.rb +1 -1
  85. data/spec/wavefront-cli/derivedmetric_spec.rb +79 -0
  86. data/spec/wavefront-cli/display/base_spec.rb +1 -1
  87. data/spec/wavefront-cli/string_spec.rb +1 -1
  88. data/wavefront-cli.gemspec +1 -1
  89. metadata +17 -8
  90. data/lib/wavefront-cli/output/wavefront.tf +0 -257
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -0,0 +1,14 @@
1
+ require_relative 'base'
2
+
3
+ module WavefrontDisplay
4
+ #
5
+ # Format human-readable output for derived metric definitions.
6
+ #
7
+ class DerivedMetric < Base
8
+ def do_describe
9
+ readable_time(:created, :updated, :createdEpochMillis,
10
+ :updatedEpochMillis)
11
+ long_output
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  require 'date'
2
- require_relative './base'
2
+ require_relative 'base'
3
3
 
4
4
  module WavefrontDisplay
5
5
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
  require_relative '../../string'
3
3
 
4
4
  module WavefrontDisplayPrinter
@@ -0,0 +1,54 @@
1
+ # The Unicode characters which we use to make a sparkline
2
+ #
3
+ BLOCKS = [' ', "\u2581", "\u2582", "\u2583", "\u2585", "\u2586",
4
+ "\u2587", "\u2588"].freeze
5
+
6
+ # How long the sparkline should be
7
+ #
8
+ SPARK_WIDTH = TW - 20
9
+
10
+ # A class to create very simple single-row sparklines of a Wavefront
11
+ # result.
12
+ #
13
+ class WavefrontSparkline
14
+ attr_reader :sparkline
15
+
16
+ def initialize(series)
17
+ @sparkline = '>' + generate_sparkline(series) + '<'
18
+ end
19
+
20
+ # @return [String] the block corresponding to the given value in
21
+ # the given range. The `rescue` clause handles occasions when
22
+ # Wavefront returns NaN as a value, or if the range is zero.
23
+ #
24
+ def sized_block(v, range)
25
+ BLOCKS[(v / range * (BLOCKS.length - 1)).floor]
26
+ rescue StandardError
27
+ BLOCKS.first
28
+ end
29
+
30
+ # A recursive function which repeatedly halves a data series until
31
+ # it fits inside SPARK_WIDTH characters. It does this by merging
32
+ # adjacent pairs and finding the mean. This is crude.
33
+ # @param vals [Array] a series of values to display
34
+ # @return [Array]
35
+ #
36
+ def make_fit(vals)
37
+ return vals if vals.size < SPARK_WIDTH
38
+ vals.<< vals.last if vals.size.odd?
39
+ ret = vals.each_slice(2).with_object([]) { |s, a| a.<< s.inject(:+) / 2 }
40
+ make_fit(ret)
41
+ end
42
+
43
+ # @param data [Array] a series of [time, value] data points
44
+ # @return [String] the sparkline itself
45
+ #
46
+ def generate_sparkline(data)
47
+ values = data.map { |_k, v| v }
48
+ max = values.max || 0
49
+ min = values.min || 0
50
+ v_range = max - min
51
+ values = make_fit(values)
52
+ values.map { |v| sized_block(v - min, v_range) }.join
53
+ end
54
+ end
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplayPrinter
4
4
 
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,5 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
+ require_relative 'printer/sparkline'
2
3
 
3
4
  module WavefrontDisplay
4
5
  #
@@ -6,29 +7,37 @@ module WavefrontDisplay
6
7
  #
7
8
  class Query < Base
8
9
  def do_default
9
- ts = if data.key?(:timeseries)
10
- data[:timeseries].each do |s|
11
- s[:data] = humanize_series(s[:data])
12
- end
13
- else
14
- []
15
- end
16
-
17
- events = if data.key?(:events)
18
- data[:events].map { |s| humanize_event(s) }
19
- else
20
- []
21
- end
22
-
23
- new = { name: data.name,
24
- query: data.query,
25
- timeseries: ts,
26
- events: events }
27
-
28
- @data = new
10
+ d_obj = { name: data.name,
11
+ query: data.query,
12
+ timeseries: mk_timeseries(data),
13
+ events: mk_events(data) }
14
+
15
+ if data.key?(:warnings) && !options[:nowarn]
16
+ d_obj[:warnings] = data[:warnings]
17
+ end
18
+
19
+ @data = d_obj
29
20
  long_output
30
21
  end
31
22
 
23
+ def mk_timeseries(data)
24
+ return [] unless data.key?(:timeseries)
25
+
26
+ data[:timeseries].each do |s|
27
+ unless options[:nospark]
28
+ s[:sparkline] = WavefrontSparkline.new(s[:data]).sparkline
29
+ s.reorder!({label: nil, sparkline: nil})
30
+ end
31
+
32
+ s[:data] = humanize_series(s[:data])
33
+ end
34
+ end
35
+
36
+ def mk_events(data)
37
+ return [] unless data.key?(:events)
38
+ data[:events].map { |s| humanize_event(s) }
39
+ end
40
+
32
41
  def do_run
33
42
  do_default
34
43
  end
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontDisplay
4
4
  # Format human-readable output when writing points.
@@ -1,6 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'wavefront-sdk/mixins'
3
- require_relative './base'
3
+ require_relative 'base'
4
4
  require 'open3'
5
5
 
6
6
  EVENT_STATE_DIR = Pathname.new('/var/tmp/wavefront')
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontCli
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontCli
4
4
  #
@@ -1,5 +1,5 @@
1
1
  require 'wavefront-sdk/mixins'
2
- require_relative './base'
2
+ require_relative 'base'
3
3
 
4
4
  module WavefrontCli
5
5
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontCli
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontCli
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontCli
4
4
  #
@@ -1,7 +1,7 @@
1
1
  require 'inifile'
2
2
  require 'pathname'
3
3
  require 'wavefront-sdk/credentials'
4
- require_relative './constants.rb'
4
+ require_relative 'constants.rb'
5
5
 
6
6
  module WavefrontCli
7
7
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontCli
4
4
  #
@@ -1,5 +1,5 @@
1
1
  require 'wavefront-sdk/mixins'
2
- require_relative './base'
2
+ require_relative 'base'
3
3
 
4
4
  module WavefrontCli
5
5
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontCli
4
4
  #
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontCli
4
4
  #
@@ -9,7 +9,7 @@ class String
9
9
  #
10
10
  def cmd_fold(tw = TW, indent = 10)
11
11
  gsub(/(-\w) /, '\\1^').scan_line(tw - 12).join("\n" + ' ' * indent)
12
- .tr('^', ' ')
12
+ .restored
13
13
  end
14
14
 
15
15
  # Wrapper around #fold()
@@ -24,8 +24,8 @@ class String
24
24
 
25
25
  # Fold long lines with a hanging indent. Originally a special case
26
26
  # for option folding, now addded the prefix parameter to make it
27
- # more general.
28
- #
27
+ # more general. Don't line-break default values, because it also
28
+ # breaks docopt.
29
29
  #
30
30
  # @param tw [Integer] terminal width
31
31
  # @param indent [Integer] size of hanging indent, in chars
@@ -33,16 +33,23 @@ class String
33
33
  # @return [String] the folded line
34
34
  #
35
35
  def fold(tw = TW, indent = 10, prefix = '')
36
- chunks = scan_line(tw - 8)
36
+ chunks = gsub(/default: /, 'default:^').scan_line(tw - 8)
37
37
  first_line = format("%s%s\n", prefix, chunks.shift)
38
38
 
39
- return first_line if chunks.empty?
39
+ return first_line.restored if chunks.empty?
40
40
 
41
41
  rest = chunks.join(' ').scan_line(tw - indent - 5).map do |l|
42
42
  prefix + ' ' * indent + l
43
43
  end
44
44
 
45
- first_line + rest.join("\n") + "\n"
45
+ (first_line + rest.join("\n") + "\n").restored
46
+ end
47
+
48
+ # We use a carat as a temporary whitespace character to avoid
49
+ # undesirable line breaking. This puts it back
50
+ #
51
+ def restored
52
+ tr('^', ' ')
46
53
  end
47
54
 
48
55
  # @param width [Integer] length of longest string (width of
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontCli
4
4
  #
@@ -1 +1 @@
1
- WF_CLI_VERSION = '2.4.0'.freeze
1
+ WF_CLI_VERSION = '2.5.0'.freeze
@@ -1,4 +1,4 @@
1
- require_relative './base'
1
+ require_relative 'base'
2
2
 
3
3
  module WavefrontCli
4
4
  #
data/spec/spec_helper.rb CHANGED
@@ -162,27 +162,27 @@ def list_tests(cmd, pth = nil, k = nil)
162
162
  k)
163
163
  end
164
164
 
165
- def tag_tests(cmd, id, bad_id, pth = nil)
165
+ def tag_tests(cmd, id, bad_id, pth = nil, k = nil)
166
166
  pth ||= cmd
167
- cmd_to_call(cmd, "tags #{id}", path: "/api/v2/#{pth}/#{id}/tag")
167
+ cmd_to_call(cmd, "tags #{id}", { path: "/api/v2/#{pth}/#{id}/tag" }, k)
168
168
  cmd_to_call(cmd, "tag set #{id} mytag",
169
- method: :post,
170
- path: "/api/v2/#{pth}/#{id}/tag",
171
- body: %w[mytag].to_json,
172
- headers: JSON_POST_HEADERS)
169
+ { method: :post,
170
+ path: "/api/v2/#{pth}/#{id}/tag",
171
+ body: %w[mytag].to_json,
172
+ headers: JSON_POST_HEADERS }, k)
173
173
  cmd_to_call(cmd, "tag set #{id} mytag1 mytag2",
174
- method: :post,
175
- path: "/api/v2/#{pth}/#{id}/tag",
176
- body: %w[mytag1 mytag2].to_json,
177
- headers: JSON_POST_HEADERS)
174
+ { method: :post,
175
+ path: "/api/v2/#{pth}/#{id}/tag",
176
+ body: %w[mytag1 mytag2].to_json,
177
+ headers: JSON_POST_HEADERS }, k)
178
178
  cmd_to_call(cmd, "tag add #{id} mytag",
179
- method: :put, path: "/api/v2/#{pth}/#{id}/tag/mytag")
179
+ { method: :put, path: "/api/v2/#{pth}/#{id}/tag/mytag" }, k)
180
180
  cmd_to_call(cmd, "tag delete #{id} mytag",
181
- method: :delete, path: "/api/v2/#{pth}/#{id}/tag/mytag")
182
- cmd_to_call(cmd, "tag clear #{id}", method: :post,
183
- path: "/api/v2/#{pth}/#{id}/tag",
184
- body: [].to_json,
185
- headers: JSON_POST_HEADERS)
181
+ { method: :delete, path: "/api/v2/#{pth}/#{id}/tag/mytag" }, k)
182
+ cmd_to_call(cmd, "tag clear #{id}", { method: :post,
183
+ path: "/api/v2/#{pth}/#{id}/tag",
184
+ body: [].to_json,
185
+ headers: JSON_POST_HEADERS }, k)
186
186
  invalid_ids(cmd, ["tags #{bad_id}", "tag clear #{bad_id}",
187
187
  "tag add #{bad_id} mytag", "tag delete #{bad_id} mytag"])
188
188
  invalid_tags(cmd, ["tag add #{id} #{BAD_TAG}", "tag delete #{id} #{BAD_TAG}"])