logstash-output-graphite 0.1.7 → 0.1.8

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: 2e9fa433c20de3668a25403281f5cbb3ae7952d6
4
- data.tar.gz: 6391b1f0137f1f637ecd656f3f04f5898c298f31
3
+ metadata.gz: b6d50a691df186d1f6b3c9a19c496308afe70d39
4
+ data.tar.gz: 8e734363fe5ecca3ab719235691b2a1d0e6c3bd7
5
5
  SHA512:
6
- metadata.gz: da65eb4c3edf08e6b327e771204817a877f619713c4fba06d3611cb9235636ca5b2436ac027fc3ca32aa4ccf4e08a332929ac0e94a73e8f158efe29a6533dc7a
7
- data.tar.gz: 564c8b7cc09740c14baf91f4626d6d8b9f85b38b51951274c8ed85cd2f51c2ef284e44d5b00b04934ebe3b4447abb7e82e7b2e083f3e937d2a0ac6b35368f431
6
+ metadata.gz: b83527c9bc1003809fd2e99a942a24e3317c336bec19a8e4a9ca178fa5fac84ebb45474f10b9c25a3c1dc5985c554e9f32789f845ec3e400cc8f939c92365515
7
+ data.tar.gz: 76b8223c213425a7ca8628f2ae1c77f2652841b463392b12f25392cdf1250bf4de3f2105065333ae1e66f84fa996fa21487fe4bb2e8c620bf04466b33bcc740d
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-graphite'
4
- s.version = '0.1.7'
4
+ s.version = '0.1.8'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "This output allows you to pull metrics from your logs and ship them to Graphite"
7
7
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
@@ -3,208 +3,107 @@ require_relative '../spec_helper'
3
3
  describe LogStash::Outputs::Graphite do
4
4
 
5
5
  let(:port) { 4939 }
6
- let(:config) do <<-CONFIG
7
- input {
8
- generator {
9
- message => "foo=fancy bar=42"
10
- count => 1
11
- type => "generator"
12
- }
13
- }
14
-
15
- filter {
16
- kv { }
17
- }
18
-
19
- output {
20
- graphite {
21
- host => "localhost"
22
- port => #{port}
23
- metrics => [ "hurray.%{foo}", "%{bar}" ]
24
- }
25
- }
26
- CONFIG
27
- end
28
-
29
- let(:pipeline) { LogStash::Pipeline.new(config) }
30
- let(:server) { Mocks::Server.new(port) }
6
+ let(:server) { subject.socket }
31
7
 
32
- before do
33
- server.start
34
- pipeline.run
35
- end
36
-
37
- after do
38
- server.stop
8
+ before :each do
9
+ subject.register
10
+ subject.receive(event)
39
11
  end
40
12
 
41
13
  context "with a default run" do
42
14
 
15
+ subject { LogStash::Outputs::Graphite.new("host" => "localhost", "port" => port, "metrics" => [ "hurray.%{foo}", "%{bar}" ]) }
16
+ let(:event) { LogStash::Event.new("foo" => "fancy", "bar" => 42) }
17
+
43
18
  it "generate one element" do
44
19
  expect(server.size).to eq(1)
45
20
  end
46
21
 
47
22
  it "include all metrics" do
48
- lines = server.pop
49
- expect(lines).to match(/^hurray.fancy 42.0 \d{10,}\n$/)
23
+ line = server.pop
24
+ expect(line).to match(/^hurray.fancy 42.0 \d{10,}\n$/)
50
25
  end
51
-
52
26
  end
53
27
 
54
28
  context "if fields_are_metrics => true" do
55
29
  context "when metrics_format => ..." do
30
+ subject { LogStash::Outputs::Graphite.new("host" => "localhost",
31
+ "port" => port,
32
+ "fields_are_metrics" => true,
33
+ "include_metrics" => ["foo"],
34
+ "metrics_format" => "foo.bar.sys.data.*") }
56
35
 
57
- context "match one key" do
58
- let(:config) do <<-CONFIG
59
- input {
60
- generator {
61
- message => "foo=123"
62
- count => 1
63
- type => "generator"
64
- }
65
- }
66
-
67
- filter {
68
- kv { }
69
- }
70
-
71
- output {
72
- graphite {
73
- host => "localhost"
74
- port => #{port}
75
- fields_are_metrics => true
76
- include_metrics => ["foo"]
77
- metrics_format => "foo.bar.sys.data.*"
78
- debug => true
79
- }
80
- }
81
- CONFIG
82
- end
36
+ let(:event) { LogStash::Event.new("foo" => "123") }
83
37
 
38
+ context "match one key" do
84
39
  it "generate one element" do
85
40
  expect(server.size).to eq(1)
86
41
  end
87
42
 
88
43
  it "match the generated key" do
89
- lines = server.pop
90
- expect(lines).to match(/^foo.bar.sys.data.foo 123.0 \d{10,}\n$/)
44
+ line = server.pop
45
+ expect(line).to match(/^foo.bar.sys.data.foo 123.0 \d{10,}\n$/)
91
46
  end
92
-
93
47
  end
48
+ end
94
49
 
95
- context "match all keys" do
96
-
97
- let(:config) do <<-CONFIG
98
- input {
99
- generator {
100
- message => "foo=123 bar=42"
101
- count => 1
102
- type => "generator"
103
- }
104
- }
105
-
106
- filter {
107
- kv { }
108
- }
109
-
110
- output {
111
- graphite {
112
- host => "localhost"
113
- port => #{port}
114
- fields_are_metrics => true
115
- include_metrics => [".*"]
116
- metrics_format => "foo.bar.sys.data.*"
117
- debug => true
118
- }
119
- }
120
- CONFIG
121
- end
50
+ context "match all keys" do
122
51
 
123
- let(:lines) do
124
- dict = {}
125
- while(!server.empty?)
126
- line = server.pop
127
- key = line.split(' ')[0]
128
- dict[key] = line
129
- end
130
- dict
131
- end
52
+ subject { LogStash::Outputs::Graphite.new("host" => "localhost",
53
+ "port" => port,
54
+ "fields_are_metrics" => true,
55
+ "include_metrics" => [".*"],
56
+ "metrics_format" => "foo.bar.sys.data.*") }
132
57
 
133
- it "match the generated foo key" do
134
- expect(lines['foo.bar.sys.data.foo']).to match(/^foo.bar.sys.data.foo 123.0 \d{10,}\n$/)
135
- end
58
+ let(:event) { LogStash::Event.new("foo" => "123", "bar" => "42") }
136
59
 
137
- it "match the generated bar key" do
138
- expect(lines['foo.bar.sys.data.bar']).to match(/^foo.bar.sys.data.bar 42.0 \d{10,}\n$/)
60
+ let(:lines) do
61
+ dict = {}
62
+ while(!server.empty?)
63
+ line = server.pop
64
+ key = line.split(' ')[0]
65
+ dict[key] = line
139
66
  end
67
+ dict
68
+ end
140
69
 
70
+ it "match the generated foo key" do
71
+ expect(lines['foo.bar.sys.data.foo']).to match(/^foo.bar.sys.data.foo 123.0 \d{10,}\n$/)
141
72
  end
142
73
 
143
- context "no match" do
144
-
145
- let(:config) do <<-CONFIG
146
- input {
147
- generator {
148
- message => "foo=123 bar=42"
149
- count => 1
150
- type => "generator"
151
- }
152
- }
153
-
154
- filter {
155
- kv { }
156
- }
157
-
158
- output {
159
- graphite {
160
- host => "localhost"
161
- port => #{port}
162
- fields_are_metrics => true
163
- include_metrics => ["notmatchinganything"]
164
- metrics_format => "foo.bar.sys.data.*"
165
- debug => true
166
- }
167
- }
168
- CONFIG
169
- end
74
+ it "match the generated bar key" do
75
+ expect(lines['foo.bar.sys.data.bar']).to match(/^foo.bar.sys.data.bar 42.0 \d{10,}\n$/)
76
+ end
77
+ end
170
78
 
171
- it "generate no event" do
172
- expect(server.empty?).to eq(true)
173
- end
79
+ context "no match" do
80
+
81
+ subject { LogStash::Outputs::Graphite.new("host" => "localhost",
82
+ "port" => port,
83
+ "fields_are_metrics" => true,
84
+ "include_metrics" => ["notmatchinganything"],
85
+ "metrics_format" => "foo.bar.sys.data.*") }
86
+
87
+ let(:event) { LogStash::Event.new("foo" => "123", "bar" => "42") }
88
+
89
+ it "generate no event" do
90
+ expect(server.empty?).to eq(true)
174
91
  end
92
+ end
175
93
 
176
- context "match a key with invalid metric_format" do
177
-
178
- let(:config) do <<-CONFIG
179
- input {
180
- generator {
181
- message => "foo=123"
182
- count => 1
183
- type => "generator"
184
- }
185
- }
186
-
187
- filter {
188
- kv { }
189
- }
190
-
191
- output {
192
- graphite {
193
- host => "localhost"
194
- port => #{port}
195
- fields_are_metrics => true
196
- include_metrics => ["foo"]
197
- metrics_format => "invalidformat"
198
- debug => true
199
- }
200
- }
201
- CONFIG
202
- end
94
+ context "match a key with invalid metric_format" do
203
95
 
204
- it "match the foo key" do
205
- lines = server.pop
206
- expect(lines).to match(/^foo 123.0 \d{10,}\n$/)
207
- end
96
+ subject { LogStash::Outputs::Graphite.new("host" => "localhost",
97
+ "port" => port,
98
+ "fields_are_metrics" => true,
99
+ "include_metrics" => ["foo"],
100
+ "metrics_format" => "invalidformat") }
101
+
102
+ let(:event) { LogStash::Event.new("foo" => "123") }
103
+
104
+ it "match the foo key" do
105
+ line = server.pop
106
+ expect(line).to match(/^foo 123.0 \d{10,}\n$/)
208
107
  end
209
108
  end
210
109
  end
@@ -213,75 +112,36 @@ describe LogStash::Outputs::Graphite do
213
112
  context "metrics_format not set" do
214
113
  context "match one key with metrics list" do
215
114
 
216
- let(:config) do <<-CONFIG
217
- input {
218
- generator {
219
- message => "foo=123"
220
- count => 1
221
- type => "generator"
222
- }
223
- }
224
-
225
- filter {
226
- kv { }
227
- }
228
-
229
- output {
230
- graphite {
231
- host => "localhost"
232
- port => #{port}
233
- fields_are_metrics => false
234
- include_metrics => ["foo"]
235
- metrics => [ "custom.foo", "%{foo}" ]
236
- debug => true
237
- }
238
- }
239
- CONFIG
240
- end
115
+ subject { LogStash::Outputs::Graphite.new("host" => "localhost",
116
+ "port" => port,
117
+ "fields_are_metrics" => false,
118
+ "include_metrics" => ["foo"],
119
+ "metrics" => [ "custom.foo", "%{foo}" ]) }
120
+
121
+ let(:event) { LogStash::Event.new("foo" => "123") }
241
122
 
242
123
  it "match the custom.foo key" do
243
- lines = server.pop
244
- expect(lines).to match(/^custom.foo 123.0 \d{10,}\n$/)
124
+ line = server.pop
125
+ expect(line).to match(/^custom.foo 123.0 \d{10,}\n$/)
245
126
  end
246
-
247
127
  end
248
128
  end
249
129
  end
250
130
 
251
131
  context "timestamp_field used is timestamp_new" do
252
- timestamp_new = (Time.now + 3).to_i
253
- let(:config) do <<-CONFIG
254
- input {
255
- generator {
256
- message => "foo=123"
257
- count => 1
258
- type => "generator"
259
- }
260
- }
261
-
262
- filter {
263
- ruby {
264
- code => "event['timestamp_new'] = Time.at(#{timestamp_new})"
265
- }
266
- }
267
-
268
- output {
269
- graphite {
270
- host => "localhost"
271
- port => #{port}
272
- timestamp_field => "timestamp_new"
273
- metrics => ["foo", "1"]
274
- debug => true
275
- }
276
- }
277
- CONFIG
278
- end
132
+
133
+ let(:timestamp_new) { (Time.now + 3).to_i }
134
+
135
+ subject { LogStash::Outputs::Graphite.new("host" => "localhost",
136
+ "port" => port,
137
+ "timestamp_field" => "timestamp_new",
138
+ "metrics" => ["foo", "1"]) }
139
+
140
+ let(:event) { LogStash::Event.new("foo" => "123", "timestamp_new" => timestamp_new) }
279
141
 
280
142
  it "timestamp matches timestamp_new" do
281
- lines = server.pop
282
- expect(lines).to match(/^foo 1.0 #{timestamp_new}\n$/)
143
+ line = server.pop
144
+ expect(line).to match(/^foo 1.0 #{timestamp_new}\n$/)
283
145
  end
284
-
285
146
  end
286
-
287
147
  end
@@ -1,3 +1,11 @@
1
1
  require "logstash/devutils/rspec/spec_helper"
2
2
  require "logstash/outputs/graphite"
3
3
  require_relative "support/server"
4
+
5
+ class LogStash::Outputs::Graphite
6
+ attr_reader :socket
7
+
8
+ def connect
9
+ @socket = Mocks::Server.new
10
+ end
11
+ end
@@ -1,24 +1,8 @@
1
1
  module Mocks
2
2
  class Server
3
3
 
4
- def initialize(port)
5
- @queue = Queue.new
6
- @port = port
7
- end
8
-
9
- def start
10
- @server = TCPServer.new("127.0.0.1", @port)
11
- @queue.clear
12
- Thread.new do
13
- client = @server.accept
14
- while true
15
- if !client.eof?
16
- line = client.readline
17
- @queue << line
18
- end
19
- end
20
- end
21
- self
4
+ def initialize
5
+ @queue = Array.new
22
6
  end
23
7
 
24
8
  def size
@@ -30,12 +14,16 @@ module Mocks
30
14
  end
31
15
 
32
16
  def stop
33
- @server.close
34
17
  end
35
18
 
36
19
  def empty?
37
20
  @queue.empty?
38
21
  end
39
22
 
23
+ def puts(data)
24
+ data.split("\n").each do |line|
25
+ @queue << "#{line}\n"
26
+ end
27
+ end
40
28
  end
41
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-graphite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.1.9
128
+ rubygems_version: 2.4.5
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: This output allows you to pull metrics from your logs and ship them to Graphite