hallmonitor 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7417d6498baf7f73a8d717ed8497503ab3ffc22
4
- data.tar.gz: 3e5887d9e7bf1220f1fc12e02479cff211c9cbed
3
+ metadata.gz: 515e56a7cec5188387c88051f7ef6be3ab963b48
4
+ data.tar.gz: be30442a4e44804fbf679630fd4c67893907fa89
5
5
  SHA512:
6
- metadata.gz: 13952cb19e2809073797e2a2c99b2b540b0d192090442de5b406ca424075b0be32bd4cf4c257897803e636af0cb5ced054f840b64f297d716593010d3a97255c
7
- data.tar.gz: a23cf1b369e6713251b0f34c2920862b0bf18697f22536a97da80bb73205a48df64da4f7960fa74916caa4a36bcb2af4563c7174e33027f4844ba3e1ec340e0d
6
+ metadata.gz: 58e504bc5324180efb1af75aae1d73274b43b135fab2eff72788d7f296599454cb908b1c185ccd4560b535cd45aec5daee1fbb11582102b0f3ddc87a88ce33f6
7
+ data.tar.gz: 5bb63718cefb76199d649f4b066d05f67d63d738682758f2dc00c3d976d1a3ec4c640f850dd7cb2fd771849da329aadc5e96f1a53a70e4b5dd9169d22cad22e4
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Version 3.0.0
2
+ - Refactored the Transformer concept in the InfluxDB outputter so that
3
+ it is more flexible. This was in response to the InfluxDB client gem
4
+ "fixing" a bug where numerical values were previously always sent as
5
+ floats, now numbers are marked as "integer" type if they are ruby
6
+ Integers which can lead to some field-type conflicts if you update
7
+ your InfluxDB gem version and were previously sending integers at
8
+ floats. Using the Transformer now allows you to modify the values
9
+ that will be sent to InfluxDB immediately before they're sent out.x
@@ -7,82 +7,70 @@ module Hallmonitor
7
7
  module Outputters
8
8
  # An outputter for InfluxDB
9
9
  class Influxdb < Outputter
10
+ # Simple EventData struct, used to communicate with an optional Transformer
11
+ EventData = Struct.new(:name, :tags, :fields)
12
+
10
13
  # Builds a new Influxdb outputter
11
14
  # @param influxdb_client [InfluxDB::Client] client instance to use
12
15
  # @param tags [Hash] Set of default tags applied to all events output to
13
16
  # InfluxDB, will be overridden by tags set by events if they conflict
14
- # @param transformer [#transform(String)] An object that responds
15
- # to #transform(String). If supplied it will be passed each event name
16
- # and should return a hash with keys :name and :tags. This is to allow
17
- # for transition from a statsd/graphite style event naming convention to
18
- # an InfluxDb style name+tags convention. Any tags returned by the
19
- # transformer will defer to tags specified in the event itself, in
20
- # other words if the event has tags already they will take precedence
21
- # over tags built by the transformer
17
+ # @param transformer [#transform(Event, EventData)] An object
18
+ # that responds to #transform(Event, EventData). If supplied
19
+ # it will be passed the {EventData} struct that has been built
20
+ # so far and it should return an {EventData} struct that will
21
+ # be written out to InfluxDB. This allows a hook to modify data
22
+ # before it is written out to InfluxDB
22
23
  # @raise if influxdb_client does not respond to :write_point
23
24
  # (InfluxDB::Client contract)
24
25
  def initialize(influxdb_client, tags = {}, transformer = nil)
25
26
  unless influxdb_client.respond_to?(:write_point)
26
- fail 'Supplied InfluxDB Client was not as expected'
27
+ raise 'Supplied InfluxDB Client was not as expected'
27
28
  end
28
29
 
29
30
  if transformer && !transformer.respond_to?(:transform)
30
- fail 'Supplied transformer does not respond to :transform'
31
+ raise 'Supplied transformer does not respond to :transform'
31
32
  end
32
33
 
33
34
  super('influxdb')
34
35
  @tags = {}.merge(tags)
35
- @client = influxdb_client || fail('Must supply an InfluxDb client')
36
+ @client = influxdb_client || raise('Must supply an InfluxDb client')
36
37
  @transformer = transformer
37
38
  end
38
39
 
39
40
  # Sends events to InfluxDB instance
40
- # @param evvent []
41
+ # @param event [Hallmonitor::Event]
41
42
  def process(event)
42
- data =
43
- if event.is_a?(Hallmonitor::TimedEvent)
44
- build_timer_data(event)
45
- elsif event.is_a?(Hallmonitor::GaugeEvent)
46
- build_gauge_data(event)
47
- else
48
- build_counter_data(event)
49
- end
50
- transform_and_write(event, data)
43
+ event_data = build_event_data(event)
44
+ transform_and_write(event, event_data)
51
45
  end
52
46
 
53
47
  private
54
48
 
55
- def transform_and_write(event, data)
56
- to_write = transform(event, data)
57
- @client.write_point(to_write[:name], to_write[:data])
49
+ # @param event [Event] The original event we're working with
50
+ # @param data [EventData] Struct of data we're building for InfluxDB
51
+ def transform_and_write(event, event_data)
52
+ event_data = @transformer.transform(event, event_data) if @transformer
53
+ data = { tags: event_data.tags, values: event_data.fields }
54
+ @client.write_point(event_data.name, data)
58
55
  end
59
56
 
60
- # If @transformer exists, use it to transform the event name
61
- # and possibly build tags from it.
62
- # @param event [Event] The event we're working with
63
- # @param data [Hash] Hash of data we're building for InfluxDB,
64
- # Will be modified directly if the transformer is specified.
65
- # @see {#build_data} for information on the structure of `data`
66
- def transform(event, data)
67
- if @transformer
68
- t = @transformer.transform(event.name)
69
- data[:tags] = (t[:tags] || {}).merge(data[:tags])
70
- { name: t[:name], data: data }
57
+ # Builds an {EventData} from the Hallmonitor::Event
58
+ def build_event_data(event)
59
+ if event.is_a?(Hallmonitor::TimedEvent)
60
+ build_timer_data(event)
61
+ elsif event.is_a?(Hallmonitor::GaugeEvent)
62
+ build_gauge_data(event)
71
63
  else
72
- { name: event.name, data: data }
64
+ build_counter_data(event)
73
65
  end
74
66
  end
75
67
 
68
+ # Builds an EventData struct for the event
76
69
  def build_data(event, type, value)
77
- data = {
78
- tags: @tags.merge(event.tags.merge(type: type))
79
- }
80
-
81
- if value.is_a?(Hash)
82
- data[:values] = value
83
- else
84
- data[:values] = { value: value }
85
- end
70
+ data = EventData.new
71
+ data.name = event.name
72
+ data.tags = @tags.merge(event.tags.merge(type: type))
73
+ data.fields = value.is_a?(Hash) ? value : { value: value }
86
74
  data
87
75
  end
88
76
 
@@ -1,6 +1,6 @@
1
1
  module Hallmonitor
2
2
  module Version
3
- MAJOR = 2
3
+ MAJOR = 3
4
4
  MINOR = 0
5
5
  PATCH = 0
6
6
  BUILD = nil
@@ -11,7 +11,7 @@ module Hallmonitor
11
11
  context '#initialize' do
12
12
  context 'with a bad influxdb client' do
13
13
  it 'raises an error' do
14
- expect { outputter }.to raise_error(String)
14
+ expect { outputter }.to raise_error
15
15
  end
16
16
  end
17
17
 
@@ -70,22 +70,31 @@ module Hallmonitor
70
70
  end
71
71
  end
72
72
 
73
- context 'with a name transformer' do
74
- let(:transformer) { double('name_transformer') }
73
+ context 'with a transformer' do
74
+ let(:transformer) { double('transformer') }
75
75
  let(:outputter) do
76
76
  described_class.new(influxdb_client, default_tags, transformer)
77
77
  end
78
78
 
79
+ let(:expected_data) do
80
+ {
81
+ values: { value: expected_value },
82
+ tags: { additional: 'foo' }
83
+ }
84
+ end
85
+
79
86
  it 'builds event information using the transformer' do
80
87
  expect(transformer).to(
81
88
  receive(:transform)
82
- .with(event.name)
83
- .and_return(
84
- name: 'foo',
85
- tags: { additional: 'foo' }
86
- )
89
+ .with(event, anything)
90
+ .and_return(
91
+ Influxdb::EventData.new(
92
+ 'foo',
93
+ { additional: 'foo' },
94
+ value: 1
95
+ )
96
+ )
87
97
  )
88
- expected_data[:tags][:additional] = 'foo'
89
98
  expect(influxdb_client).to(
90
99
  receive(:write_point).with('foo', expected_data))
91
100
  outputter.process(event)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hallmonitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris TenHarmsel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-11 00:00:00.000000000 Z
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -145,6 +145,7 @@ extra_rdoc_files: []
145
145
  files:
146
146
  - ".document"
147
147
  - ".gitignore"
148
+ - CHANGELOG.md
148
149
  - Gemfile
149
150
  - LICENSE.txt
150
151
  - README.md