logstash-output-timber 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logstash/outputs/timber.rb +3 -1
- data/logstash-output-timber.gemspec +1 -1
- data/spec/outputs/timber_spec.rb +28 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41db80ea8dc6e0c7655f0fcc3c84101be85c8241de366ef07493dedea222b67d
|
4
|
+
data.tar.gz: 1c0c6e41505a4a1b4b090663d29480aee491eceb58dce58c9af5e0c47418817d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49fb12cb9a25669e2d270ce7b315222f9a5a5988aa51c826dfc85821ed6b116bff18dcf1740e49c3acf03e910b897bd31cd6b2d62f645d5a1be65f7006d2b3a5
|
7
|
+
data.tar.gz: 58c94bb43555676e76e7d11bedf0df71277c2f47f6832cfa6ec5b2e7610a15270750d7fec0672a6a661bd5cd0f87fb2a6bf33142d626e504ad66cdf430878b5b
|
@@ -13,7 +13,7 @@ require "logstash/outputs/timber/http_client"
|
|
13
13
|
class LogStash::Outputs::Timber < LogStash::Outputs::Base
|
14
14
|
include HttpClient
|
15
15
|
|
16
|
-
VERSION = "1.0.
|
16
|
+
VERSION = "1.0.2".freeze
|
17
17
|
CONTENT_TYPE = "application/json".freeze
|
18
18
|
MAX_ATTEMPTS = 3
|
19
19
|
METHOD = :post.freeze
|
@@ -130,6 +130,8 @@ class LogStash::Outputs::Timber < LogStash::Outputs::Base
|
|
130
130
|
def event_hash(e)
|
131
131
|
hash = e.to_hash
|
132
132
|
hash.delete("@version")
|
133
|
+
dt = hash.delete("@timestamp")
|
134
|
+
hash["dt"] = dt if !hash.has_key?("dt")
|
133
135
|
hash
|
134
136
|
end
|
135
137
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-output-timber'
|
3
|
-
s.version = "1.0.
|
3
|
+
s.version = "1.0.2"
|
4
4
|
s.licenses = ['Apache License (2.0)']
|
5
5
|
s.summary = "This output send events to the Timber.io logging service"
|
6
6
|
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
|
data/spec/outputs/timber_spec.rb
CHANGED
@@ -113,6 +113,22 @@ describe LogStash::Outputs::Timber do
|
|
113
113
|
expect(requests.length).to eq(3)
|
114
114
|
end
|
115
115
|
|
116
|
+
it "handles fatal request errors" do
|
117
|
+
allow(output.send(:http_client)).to receive(:post).and_raise("boom")
|
118
|
+
|
119
|
+
output.url = "http://localhost:#{port}/good"
|
120
|
+
result = output.send(:send_events, [event], 1)
|
121
|
+
expect(result).to eq(false)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "handles retryable request errors" do
|
125
|
+
expect(output.send(:http_client)).to receive(:post).exactly(3).times.and_raise(::Manticore::Timeout.new)
|
126
|
+
|
127
|
+
output.url = "http://localhost:#{port}/good"
|
128
|
+
result = output.send(:send_events, [event], 1)
|
129
|
+
expect(result).to eq(false)
|
130
|
+
end
|
131
|
+
|
116
132
|
it "returns true when the status is 200" do
|
117
133
|
output.url = "http://localhost:#{port}/good"
|
118
134
|
result = output.send(:send_events, [event], 1)
|
@@ -122,30 +138,30 @@ describe LogStash::Outputs::Timber do
|
|
122
138
|
request = requests.first
|
123
139
|
expect(request.env["CONTENT_TYPE"]).to eq("application/json")
|
124
140
|
expect(request.env["HTTP_AUTHORIZATION"]).to eq("Basic MTIzOmFiY2QxMjM0")
|
125
|
-
expect(request.env["HTTP_USER_AGENT"]).to eq("Timber Logstash/1.0.
|
141
|
+
expect(request.env["HTTP_USER_AGENT"]).to eq("Timber Logstash/1.0.2")
|
126
142
|
|
127
143
|
parsed_body = JSON.parse!(request.body.read)
|
128
144
|
expect(parsed_body.length).to eq(1)
|
129
145
|
|
130
146
|
body_event = parsed_body.first
|
131
147
|
timestamp_iso8601 = event.get("@timestamp").to_iso8601
|
132
|
-
expect(body_event).to eq({"
|
148
|
+
expect(body_event).to eq({"dt"=>timestamp_iso8601, "message"=>"hi"})
|
133
149
|
end
|
134
150
|
|
135
|
-
it "
|
136
|
-
allow(output.send(:http_client)).to receive(:post).and_raise("boom")
|
137
|
-
|
151
|
+
it "allows payloads conformed to the timber JSON schema" do
|
138
152
|
output.url = "http://localhost:#{port}/good"
|
153
|
+
event = LogStash::Event.new({"$schema" => "https://raw.githubusercontent.com/timberio/log-event-json-schema/v2.4.2/schema.json", "message" => "my message", "context" => {"http" => {"path" => "/path"}}})
|
139
154
|
result = output.send(:send_events, [event], 1)
|
140
|
-
expect(result).to eq(
|
141
|
-
|
155
|
+
expect(result).to eq(true)
|
156
|
+
expect(requests.length).to eq(1)
|
142
157
|
|
143
|
-
|
144
|
-
|
158
|
+
request = requests.first
|
159
|
+
parsed_body = JSON.parse!(request.body.read)
|
160
|
+
expect(parsed_body.length).to eq(1)
|
145
161
|
|
146
|
-
|
147
|
-
|
148
|
-
expect(
|
162
|
+
body_event = parsed_body.first
|
163
|
+
timestamp_iso8601 = event.get("@timestamp").to_iso8601
|
164
|
+
expect(body_event).to eq({"$schema"=>"https://raw.githubusercontent.com/timberio/log-event-json-schema/v2.4.2/schema.json", "context"=>{"http"=>{"path"=>"/path"}}, "message"=>"my message", "dt"=>timestamp_iso8601})
|
149
165
|
end
|
150
166
|
end
|
151
167
|
end
|