logstash-output-graphite 0.1.1 → 0.1.2

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: 0d81ae345bb7111180cfe98d22c1888a77a4e29d
4
- data.tar.gz: 890db2c2367b1a3df8adf07a6a756bd137c37427
3
+ metadata.gz: 43878fb6306207fac8b8dc188489cbabbe6ec7ff
4
+ data.tar.gz: f3a78ec1f7647830bf35e708853165f9a2c5719a
5
5
  SHA512:
6
- metadata.gz: ff17bb29767131ca8730b6a2f20b759e9ba4ea783d581adb4dac990c765d92313be448661b0df9b845ba6e08b97c904e7cbf741f68f31d5e15b81b0a4309a23b
7
- data.tar.gz: 6f020b96aa814bffaa7980fd27dc95ab8241998de255ab1dc6acb81825ebe4a4f47cd5c2603e91da4f638fdd026015c6d9fc600d23f63d900154911b90c5fd76
6
+ metadata.gz: 829ddb59da8be6fc592b90d8b67856520adaeb214a61fe4af86b17a03f79325b4d3911522c71a2b94c15a385734008a0917b3bd6ee795e76f4fe447fce9a0ca5
7
+ data.tar.gz: 26ee32f6ec304f17622f646c72c05ef924acbaf3dff76dde7363267bff9df035f5c37cc670eb7fb5ab2f0948a04808f6bf0866a90ea5fb6172a0781bf228626a
@@ -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.1'
4
+ s.version = '0.1.2'
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"
@@ -23,5 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_runtime_dependency 'logstash', '>= 1.4.0', '< 2.0.0'
24
24
 
25
25
  s.add_development_dependency 'logstash-devutils'
26
+ s.add_development_dependency 'logstash-input-generator'
27
+ s.add_development_dependency 'logstash-filter-kv'
26
28
  end
27
29
 
@@ -1,14 +1,10 @@
1
- require "logstash/devutils/rspec/spec_helper"
2
- require "logstash/outputs/graphite"
3
- require "mocha/api"
1
+ require_relative '../spec_helper'
4
2
 
5
- describe LogStash::Outputs::Graphite, :socket => true do
6
-
3
+ describe LogStash::Outputs::Graphite do
7
4
 
8
- describe "defaults should include all metrics" do
9
- port = 4939
10
- config <<-CONFIG
11
- input {
5
+ let(:port) { 4939 }
6
+ let(:config) do <<-CONFIG
7
+ input {
12
8
  generator {
13
9
  message => "foo=fancy bar=42"
14
10
  count => 1
@@ -27,36 +23,39 @@ describe LogStash::Outputs::Graphite, :socket => true do
27
23
  metrics => [ "hurray.%{foo}", "%{bar}" ]
28
24
  }
29
25
  }
30
- CONFIG
31
-
32
- let(:queue) { Queue.new }
33
- before :each do
34
- server = TCPServer.new("127.0.0.1", port)
35
- Thread.new do
36
- client = server.accept
37
- p client
38
- while true
39
- p :read
40
- line = client.readline
41
- p :done
42
- queue << line
43
- p line
44
- end
45
- end
46
- end
26
+ CONFIG
27
+ end
28
+
29
+ let(:pipeline) { LogStash::Pipeline.new(config) }
30
+ let(:server) { Mocks::Server.new(port) }
31
+
32
+ before do
33
+ server.start
34
+ pipeline.run
35
+ end
36
+
37
+ after do
38
+ server.stop
39
+ end
47
40
 
48
- agent do
49
- lines = queue.pop
41
+ context "with a default run" do
50
42
 
51
- insist { lines.size } == 1
52
- insist { lines }.any? { |l| l =~ /^hurray.fancy 42.0 \d{10,}\n$/ }
43
+ it "generate one element" do
44
+ expect(server.size).to eq(1)
53
45
  end
46
+
47
+ it "include all metrics" do
48
+ lines = server.pop
49
+ expect(lines).to match(/^hurray.fancy 42.0 \d{10,}\n$/)
50
+ end
51
+
54
52
  end
55
53
 
56
- describe "fields_are_metrics => true" do
57
- describe "metrics_format => ..." do
58
- describe "match one key" do
59
- config <<-CONFIG
54
+ context "if fields_are_metrics => true" do
55
+ context "when metrics_format => ..." do
56
+
57
+ context "match one key" do
58
+ let(:config) do <<-CONFIG
60
59
  input {
61
60
  generator {
62
61
  message => "foo=123"
@@ -72,7 +71,7 @@ describe LogStash::Outputs::Graphite, :socket => true do
72
71
  output {
73
72
  graphite {
74
73
  host => "localhost"
75
- port => 2003
74
+ port => #{port}
76
75
  fields_are_metrics => true
77
76
  include_metrics => ["foo"]
78
77
  metrics_format => "foo.bar.sys.data.*"
@@ -80,17 +79,22 @@ describe LogStash::Outputs::Graphite, :socket => true do
80
79
  }
81
80
  }
82
81
  CONFIG
82
+ end
83
+
84
+ it "generate one element" do
85
+ expect(server.size).to eq(1)
86
+ end
83
87
 
84
- agent do
85
- @mock.rewind
86
- lines = @mock.readlines
87
- insist { lines.size } == 1
88
- insist { lines[0] } =~ /^foo.bar.sys.data.foo 123.0 \d{10,}\n$/
88
+ 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$/)
89
91
  end
92
+
90
93
  end
91
94
 
92
- describe "match all keys" do
93
- config <<-CONFIG
95
+ context "match all keys" do
96
+
97
+ let(:config) do <<-CONFIG
94
98
  input {
95
99
  generator {
96
100
  message => "foo=123 bar=42"
@@ -106,7 +110,7 @@ describe LogStash::Outputs::Graphite, :socket => true do
106
110
  output {
107
111
  graphite {
108
112
  host => "localhost"
109
- port => 2003
113
+ port => #{port}
110
114
  fields_are_metrics => true
111
115
  include_metrics => [".*"]
112
116
  metrics_format => "foo.bar.sys.data.*"
@@ -114,19 +118,31 @@ describe LogStash::Outputs::Graphite, :socket => true do
114
118
  }
115
119
  }
116
120
  CONFIG
121
+ end
122
+
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
117
132
 
118
- agent do
119
- @mock.rewind
120
- lines = @mock.readlines.delete_if { |l| l =~ /\.sequence \d+/ }
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
121
136
 
122
- insist { lines.size } == 2
123
- insist { lines }.any? { |l| l =~ /^foo.bar.sys.data.foo 123.0 \d{10,}\n$/ }
124
- insist { lines }.any? { |l| l =~ /^foo.bar.sys.data.bar 42.0 \d{10,}\n$/ }
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$/)
125
139
  end
140
+
126
141
  end
127
142
 
128
- describe "no match" do
129
- config <<-CONFIG
143
+ context "no match" do
144
+
145
+ let(:config) do <<-CONFIG
130
146
  input {
131
147
  generator {
132
148
  message => "foo=123 bar=42"
@@ -142,7 +158,7 @@ describe LogStash::Outputs::Graphite, :socket => true do
142
158
  output {
143
159
  graphite {
144
160
  host => "localhost"
145
- port => 2003
161
+ port => #{port}
146
162
  fields_are_metrics => true
147
163
  include_metrics => ["notmatchinganything"]
148
164
  metrics_format => "foo.bar.sys.data.*"
@@ -150,16 +166,16 @@ describe LogStash::Outputs::Graphite, :socket => true do
150
166
  }
151
167
  }
152
168
  CONFIG
169
+ end
153
170
 
154
- agent do
155
- @mock.rewind
156
- lines = @mock.readlines
157
- insist { lines.size } == 0
171
+ it "generate no event" do
172
+ expect(server.empty?).to be_true
158
173
  end
159
174
  end
160
175
 
161
- describe "match one key with invalid metric_format" do
162
- config <<-CONFIG
176
+ context "match a key with invalid metric_format" do
177
+
178
+ let(:config) do <<-CONFIG
163
179
  input {
164
180
  generator {
165
181
  message => "foo=123"
@@ -175,7 +191,7 @@ describe LogStash::Outputs::Graphite, :socket => true do
175
191
  output {
176
192
  graphite {
177
193
  host => "localhost"
178
- port => 2003
194
+ port => #{port}
179
195
  fields_are_metrics => true
180
196
  include_metrics => ["foo"]
181
197
  metrics_format => "invalidformat"
@@ -183,21 +199,21 @@ describe LogStash::Outputs::Graphite, :socket => true do
183
199
  }
184
200
  }
185
201
  CONFIG
202
+ end
186
203
 
187
- agent do
188
- @mock.rewind
189
- lines = @mock.readlines
190
- insist { lines.size } == 1
191
- insist { lines[0] } =~ /^foo 123.0 \d{10,}\n$/
204
+ it "match the foo key" do
205
+ lines = server.pop
206
+ expect(lines).to match(/^foo 123.0 \d{10,}\n$/)
192
207
  end
193
208
  end
194
209
  end
195
210
  end
196
211
 
197
- describe "fields are metrics = false" do
198
- describe "metrics_format not set" do
199
- describe "match one key with metrics list" do
200
- config <<-CONFIG
212
+ context "fields are metrics = false" do
213
+ context "metrics_format not set" do
214
+ context "match one key with metrics list" do
215
+
216
+ let(:config) do <<-CONFIG
201
217
  input {
202
218
  generator {
203
219
  message => "foo=123"
@@ -213,7 +229,7 @@ describe LogStash::Outputs::Graphite, :socket => true do
213
229
  output {
214
230
  graphite {
215
231
  host => "localhost"
216
- port => 2003
232
+ port => #{port}
217
233
  fields_are_metrics => false
218
234
  include_metrics => ["foo"]
219
235
  metrics => [ "custom.foo", "%{foo}" ]
@@ -221,16 +237,15 @@ describe LogStash::Outputs::Graphite, :socket => true do
221
237
  }
222
238
  }
223
239
  CONFIG
240
+ end
224
241
 
225
- agent do
226
- @mock.rewind
227
- lines = @mock.readlines
228
-
229
- insist { lines.size } == 1
230
- insist { lines[0] } =~ /^custom.foo 123.0 \d{10,}\n$/
242
+ it "match the custom.foo key" do
243
+ lines = server.pop
244
+ expect(lines).to match(/^custom.foo 123.0 \d{10,}\n$/)
231
245
  end
232
- end
233
246
 
247
+ end
234
248
  end
235
249
  end
250
+
236
251
  end
@@ -0,0 +1,39 @@
1
+ module Mocks
2
+ class Server
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
+ line = client.readline
16
+ @queue << line
17
+ end
18
+ end
19
+ self
20
+ end
21
+
22
+ def size
23
+ @queue.length
24
+ end
25
+
26
+ def pop
27
+ @queue.pop
28
+ end
29
+
30
+ def stop
31
+ @server.close
32
+ end
33
+
34
+ def empty?
35
+ @queue.empty?
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ require "logstash/devutils/rspec/spec_helper"
2
+ require "logstash/outputs/graphite"
3
+ require_relative "server"
metadata CHANGED
@@ -1,16 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-graphite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elasticsearch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: logstash
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
14
23
  requirement: !ruby/object:Gem::Requirement
15
24
  requirements:
16
25
  - - '>='
@@ -19,31 +28,50 @@ dependencies:
19
28
  - - <
20
29
  - !ruby/object:Gem::Version
21
30
  version: 2.0.0
22
- name: logstash
23
31
  prerelease: false
24
32
  type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-devutils
25
35
  version_requirements: !ruby/object:Gem::Requirement
26
36
  requirements:
27
37
  - - '>='
28
38
  - !ruby/object:Gem::Version
29
- version: 1.4.0
30
- - - <
39
+ version: '0'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - '>='
31
43
  - !ruby/object:Gem::Version
32
- version: 2.0.0
44
+ version: '0'
45
+ prerelease: false
46
+ type: :development
33
47
  - !ruby/object:Gem::Dependency
48
+ name: logstash-input-generator
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
34
54
  requirement: !ruby/object:Gem::Requirement
35
55
  requirements:
36
56
  - - '>='
37
57
  - !ruby/object:Gem::Version
38
58
  version: '0'
39
- name: logstash-devutils
40
59
  prerelease: false
41
60
  type: :development
61
+ - !ruby/object:Gem::Dependency
62
+ name: logstash-filter-kv
42
63
  version_requirements: !ruby/object:Gem::Requirement
43
64
  requirements:
44
65
  - - '>='
45
66
  - !ruby/object:Gem::Version
46
67
  version: '0'
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ prerelease: false
74
+ type: :development
47
75
  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
48
76
  email: info@elasticsearch.com
49
77
  executables: []
@@ -57,6 +85,8 @@ files:
57
85
  - lib/logstash/outputs/graphite.rb
58
86
  - logstash-output-graphite.gemspec
59
87
  - spec/outputs/graphite_spec.rb
88
+ - spec/server.rb
89
+ - spec/spec_helper.rb
60
90
  homepage: http://www.elasticsearch.org/guide/en/logstash/current/index.html
61
91
  licenses:
62
92
  - Apache License (2.0)
@@ -85,3 +115,5 @@ specification_version: 4
85
115
  summary: This output allows you to pull metrics from your logs and ship them to Graphite
86
116
  test_files:
87
117
  - spec/outputs/graphite_spec.rb
118
+ - spec/server.rb
119
+ - spec/spec_helper.rb