ffwd 0.4.2 → 0.4.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5591842352846196e113c69a21e957ce75f07d4
4
- data.tar.gz: a7859f0d2b76c5bbdf3f92f59dda2dd41e88948e
3
+ metadata.gz: 0eaf467d00c75edea35139ab207a456cbd37b78d
4
+ data.tar.gz: 4e8a5de41839bfc8f5460b8d70f085f969082635
5
5
  SHA512:
6
- metadata.gz: d0818d1cfae4e1404fe0b7cd82e5e9e96c5e4e4bfaadea618be42aa825bf44a755564288c845f36fd7b51a4b4fa73cc29f6a04240e7e73c7f090c10210a6e8ea
7
- data.tar.gz: 86c86f31f7044cb38f82f45af351f329759cd015de5b3054169812f8bdf5136e809a5f7646f42d0d8593e2f9f11863da3babb203350bba3762311e6d4f2d0f0d
6
+ metadata.gz: b44d46575fcedd217b4ebdd76ffef9a40eabf272edf393eb92a646e4e89764f03f1147b7087462f3a4e9df0784347e7f611aeb64166d2740dd8c42cd3830ffdb
7
+ data.tar.gz: 14b0775875d1b1d658cccbe021832291755c09273a9fa8bae4b4f34e5ee563042a3bcff69b3fc80a9c58ee0c0296f48f01e0b26a3adff728a47c8f3017e57016
@@ -13,6 +13,8 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
+ require_relative 'utils'
17
+
16
18
  module FFWD
17
19
  # Struct used to define all fields related to an event.
18
20
  EventStruct = Struct.new(
@@ -33,17 +35,32 @@ module FFWD
33
35
  # A time to live associated with the event.
34
36
  :ttl,
35
37
  # Tags associated with the event.
36
- :tags,
38
+ :external_tags,
39
+ # Tags which are statically provided by the internal implementation.
40
+ :fixed_tags,
37
41
  # Attributes (extra fields) associated with the event.
38
- :attributes
42
+ :external_attr,
43
+ # Attributes which are statically provided by the internal implementation.
44
+ :fixed_attr
39
45
  )
40
46
 
41
47
  # A convenience class for each individual event.
42
48
  class Event < EventStruct
43
49
  def self.make opts = {}
44
50
  new(opts[:time], opts[:key], opts[:value], opts[:host], opts[:source],
45
- opts[:state], opts[:description], opts[:ttl], opts[:tags],
46
- opts[:attributes])
51
+ opts[:state], opts[:description], opts[:ttl],
52
+ opts[:tags], opts[:fixed_tags],
53
+ opts[:attributes], opts[:fixed_attr])
54
+ end
55
+
56
+ # maintained for backwards compatibility, but implementors are encouraged
57
+ # to use internal/external attributes directly.
58
+ def attributes
59
+ FFWD.merge_hashes fixed_attr, external_attr
60
+ end
61
+
62
+ def tags
63
+ FFWD.merge_sets fixed_tags, external_tags
47
64
  end
48
65
 
49
66
  # Convert event to a sparse hash.
@@ -57,8 +74,15 @@ module FFWD
57
74
  d[:state] = state if state
58
75
  d[:description] = description if description
59
76
  d[:ttl] = ttl if ttl
60
- d[:tags] = tags.to_a if tags
61
- d[:attributes] = attributes if attributes
77
+
78
+ if t = tags and not t.empty?
79
+ d[:tags] = t
80
+ end
81
+
82
+ if a = attributes and not a.empty?
83
+ d[:attributes] = a
84
+ end
85
+
62
86
  d
63
87
  end
64
88
  end
@@ -42,15 +42,15 @@ module FFWD
42
42
  @attributes = attributes
43
43
  end
44
44
 
45
- def emit e
46
- e[:time] ||= Time.now
47
- e[:host] ||= @host if @host
48
- e[:ttl] ||= @ttl if @ttl
49
- e[:tags] = FFWD.merge_sets @tags, e[:tags]
50
- e[:attributes] = FFWD.merge_hashes @attributes, e[:attributes]
51
- e[:value] = nil if (v = e[:value] and v.is_a?(Float) and v.nan?)
45
+ def emit d
46
+ d[:time] ||= Time.now
47
+ d[:host] ||= @host if @host
48
+ d[:ttl] ||= @ttl if @ttl
49
+ d[:value] = nil if (v = d[:value] and v.is_a?(Float) and v.nan?)
50
+ d[:fixed_tags] = @tags
51
+ d[:fixed_attr] = @attributes
52
52
 
53
- @output.event Event.make(e)
53
+ @output.event Event.make(d)
54
54
  rescue => e
55
55
  log.error "Failed to emit event", e
56
56
  end
@@ -13,6 +13,8 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
+ require_relative 'utils'
17
+
16
18
  module FFWD
17
19
  # Struct used to define all fields related to a metric.
18
20
  MetricStruct = Struct.new(
@@ -26,17 +28,32 @@ module FFWD
26
28
  :host,
27
29
  # The source metric this metric was derived from (if any).
28
30
  :source,
29
- # Tags associated to the metric.
30
- :tags,
31
+ # Tags associated with the event.
32
+ :external_tags,
33
+ # Tags which are statically provided by the internal implementation.
34
+ :fixed_tags,
31
35
  # Attributes (extra fields) associated to the metric.
32
- :attributes
36
+ :external_attr,
37
+ # Attributes which are statically provided by the internal implementation.
38
+ :fixed_attr
33
39
  )
34
40
 
35
41
  # A convenience class for each individual metric.
36
42
  class Metric < MetricStruct
37
43
  def self.make opts={}
38
44
  new(opts[:time], opts[:key], opts[:value], opts[:host], opts[:source],
39
- opts[:tags], opts[:attributes])
45
+ opts[:tags], opts[:fixed_tags],
46
+ opts[:attributes], opts[:fixed_attr])
47
+ end
48
+
49
+ # maintained for backwards compatibility, but implementors are encouraged
50
+ # to use internal/external attributes directly.
51
+ def attributes
52
+ FFWD.merge_hashes fixed_attr, external_attr
53
+ end
54
+
55
+ def tags
56
+ FFWD.merge_sets fixed_tags, external_tags
40
57
  end
41
58
 
42
59
  # Convert metric to a sparse hash.
@@ -47,8 +64,15 @@ module FFWD
47
64
  d[:value] = value if value
48
65
  d[:host] = host if host
49
66
  d[:source] = source if source
50
- d[:tags] = tags.to_a if tags
51
- d[:attributes] = attributes if attributes
67
+
68
+ if t = tags and not t.empty?
69
+ d[:tags] = t
70
+ end
71
+
72
+ if a = attributes and not a.empty?
73
+ d[:attributes] = a
74
+ end
75
+
52
76
  d
53
77
  end
54
78
  end
@@ -36,14 +36,14 @@ module FFWD
36
36
  @attributes = attributes
37
37
  end
38
38
 
39
- def emit m
40
- m[:time] ||= Time.now
41
- m[:host] ||= @host if @host
42
- m[:tags] = FFWD.merge_sets @tags, m[:tags]
43
- m[:attributes] = FFWD.merge_hashes @attributes, m[:attributes]
44
- m[:value] = nil if (v = m[:value] and v.is_a?(Float) and v.nan?)
39
+ def emit d
40
+ d[:time] ||= Time.now
41
+ d[:host] ||= @host if @host
42
+ d[:fixed_tags] = @tags
43
+ d[:fixed_attr] = @attributes
44
+ d[:value] = nil if (v = d[:value] and v.is_a?(Float) and v.nan?)
45
45
 
46
- @output.metric Metric.make(m)
46
+ @output.metric Metric.make(d)
47
47
  rescue => e
48
48
  log.error "Failed to emit metric", e
49
49
  end
@@ -14,5 +14,5 @@
14
14
  # the License.
15
15
 
16
16
  module FFWD
17
- VERSION = "0.4.2"
17
+ VERSION = "0.4.3"
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffwd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John-John Tedro
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-11 00:00:00.000000000 Z
12
+ date: 2015-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine