logstash-codec-bulk_es 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logstash/codecs/bulk_es.rb +14 -6
- data/logstash-codec-bulk_es.gemspec +3 -3
- data/spec/codecs/bulk_es_spec.rb +72 -2
- metadata +3 -5
- data/spec/spec_helper.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c64ed6ff5ea89415ac54393dbb4d2be66b93382
|
4
|
+
data.tar.gz: 90ed02febaed6611c1b7f10d7385b00d074469be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92e69ca6e9d46f84a3a0d92bdf1be0f721c773825838edcfbd70e0355beca55f7909cd057804bddd311b0ded1154c6388429f3874289e02c28dcbecb911a9220
|
7
|
+
data.tar.gz: 7fdcc6ba178a4d327b1503cfe33b6f3581213e750e412d08a4df468350a2368a8d57921d3e21ee7fa23bc68195497661bedf5713afcad6b83870792a8ca546c8
|
@@ -34,14 +34,22 @@ class LogStash::Codecs::BulkEs < LogStash::Codecs::Base
|
|
34
34
|
case @state
|
35
35
|
when :metadata
|
36
36
|
if @metadata["action"] == 'update'
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
if line.has_key?("doc")
|
38
|
+
event = LogStash::Event.new(line["doc"])
|
39
|
+
if line.has_key?("doc_as_upsert")
|
40
|
+
@metadata["doc_as_upsert"] = line["doc_as_upsert"]
|
41
|
+
end
|
42
|
+
else
|
43
|
+
event = LogStash::Event.new(line)
|
44
|
+
end
|
45
|
+
|
46
|
+
if line.has_key?("upsert")
|
47
|
+
@metadata["upsert"] = LogStash::Json.dump(line["upsert"])
|
48
|
+
end
|
49
|
+
elsif #for action = index or create
|
43
50
|
event = LogStash::Event.new(line)
|
44
51
|
end
|
52
|
+
|
45
53
|
event.set("@metadata", @metadata)
|
46
54
|
yield event
|
47
55
|
@state = :init
|
@@ -1,17 +1,17 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-codec-bulk_es'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.3'
|
4
4
|
s.licenses = ['Apache License (2.0)']
|
5
5
|
s.summary = 'This codec decodes messages received in the Elasticsearch bulk format.'
|
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'
|
7
7
|
s.homepage = 'http://www.elastic.co/guide/en/logstash/current/index.html'
|
8
|
-
s.authors = ['']
|
8
|
+
s.authors = ['saran.ramjeet@gmail.com']
|
9
9
|
s.email = 'saran.ramjeet@gmail.com'
|
10
10
|
s.require_paths = ['lib']
|
11
11
|
|
12
12
|
# Files
|
13
13
|
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
14
|
-
|
14
|
+
# Tests
|
15
15
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
16
|
|
17
17
|
# Special flag to let us know this is actually a logstash plugin
|
data/spec/codecs/bulk_es_spec.rb
CHANGED
@@ -1,3 +1,73 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
require "logstash/codecs/
|
2
|
+
require "logstash/devutils/rspec/spec_helper"
|
3
|
+
require "logstash/codecs/es_bulk"
|
4
|
+
require "logstash/event"
|
5
|
+
require "insist"
|
6
|
+
|
7
|
+
describe LogStash::Codecs::ESBulk do
|
8
|
+
subject do
|
9
|
+
next LogStash::Codecs::ESBulk.new
|
10
|
+
end
|
11
|
+
|
12
|
+
context "#decode" do
|
13
|
+
it "should return 6 events from json data" do
|
14
|
+
data = <<-HERE
|
15
|
+
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
|
16
|
+
{ "field1" : "value1" }
|
17
|
+
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
|
18
|
+
{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
|
19
|
+
{ "field1" : "value3" }
|
20
|
+
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1"} }
|
21
|
+
{ "doc" : {"field2" : "value2"} }
|
22
|
+
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1"} }
|
23
|
+
{ "doc" : {"field2" : "value4"}, "upsert": { "field2": "value4"} }
|
24
|
+
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1"} }
|
25
|
+
{ "doc" : {"field2" : "value5"}, "doc_as_upsert": true }
|
26
|
+
HERE
|
27
|
+
|
28
|
+
count = 1
|
29
|
+
subject.decode(data) do |event|
|
30
|
+
case count
|
31
|
+
when 1
|
32
|
+
insist { event.get("[@metadata][_id]") } == "1"
|
33
|
+
insist { event.get("[@metadata][action]") } == "index"
|
34
|
+
insist { event.get("field1") } == "value1"
|
35
|
+
when 2
|
36
|
+
insist { event.get("[@metadata][_id]") } == "2"
|
37
|
+
insist { event.get("[@metadata][action]") } == "delete"
|
38
|
+
when 3
|
39
|
+
insist { event.get("[@metadata][_id]") } == "3"
|
40
|
+
insist { event.get("[@metadata][action]") } == "create"
|
41
|
+
insist { event.get("field1") } == "value3"
|
42
|
+
when 4
|
43
|
+
insist { event.get("[@metadata][_id]") } == "1"
|
44
|
+
insist { event.get("[@metadata][action]") } == "update"
|
45
|
+
insist { event.get("field2") } == "value2"
|
46
|
+
when 5
|
47
|
+
insist { event.get("[@metadata][_id]") } == "1"
|
48
|
+
insist { event.get("[@metadata][action]") } == "update"
|
49
|
+
insist { event.get("field2") } == "value4"
|
50
|
+
insist { event.get("[@metadata][upsert]") } == "{\"field2\":\"value4\"}"
|
51
|
+
when 6
|
52
|
+
insist { event.get("[@metadata][_id]") } == "1"
|
53
|
+
insist { event.get("[@metadata][action]") } == "update"
|
54
|
+
insist { event.get("field2") } == "value5"
|
55
|
+
insist { event['@metadata']['doc_as_upsert'] } == true
|
56
|
+
end
|
57
|
+
count += 1
|
58
|
+
end
|
59
|
+
insist { count } == 6
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "fail to process non-bulk event then continue" do
|
64
|
+
it "continues after a fail" do
|
65
|
+
decoded = false
|
66
|
+
subject.decode("something that isn't a bulk event\n") do |event|
|
67
|
+
decoded = true
|
68
|
+
end
|
69
|
+
insist { decoded } == false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-codec-bulk_es
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- saran.ramjeet@gmail.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-core-plugin-api
|
@@ -62,7 +62,6 @@ extra_rdoc_files: []
|
|
62
62
|
files:
|
63
63
|
- lib/logstash/codecs/bulk_es.rb
|
64
64
|
- spec/codecs/bulk_es_spec.rb
|
65
|
-
- spec/spec_helper.rb
|
66
65
|
- logstash-codec-bulk_es.gemspec
|
67
66
|
- CHANGELOG.md
|
68
67
|
- DEVELOPER.md
|
@@ -98,4 +97,3 @@ specification_version: 4
|
|
98
97
|
summary: This codec decodes messages received in the Elasticsearch bulk format.
|
99
98
|
test_files:
|
100
99
|
- spec/codecs/bulk_es_spec.rb
|
101
|
-
- spec/spec_helper.rb
|
data/spec/spec_helper.rb
DELETED