fluent-plugin-elasticsearch 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.md +18 -0
- data/README.md +15 -0
- data/fluent-plugin-elasticsearch.gemspec +2 -2
- data/lib/fluent/plugin/out_elasticsearch.rb +6 -1
- data/test/plugin/test_out_elasticsearch.rb +24 -1
- metadata +6 -4
data/History.md
ADDED
data/README.md
CHANGED
@@ -51,6 +51,21 @@ The record inserted into elasticsearch would be
|
|
51
51
|
|
52
52
|
---
|
53
53
|
|
54
|
+
```
|
55
|
+
id_key request_id # use "request_id" field as a record id in ES
|
56
|
+
```
|
57
|
+
|
58
|
+
By default, all records inserted into elasticsearch get a random _id. This option allows to use a field in the record as an identifier.
|
59
|
+
|
60
|
+
This following record `{"name":"Johnny","request_id":"87d89af7daffad6"}` will trigger the following ElasticSearch command
|
61
|
+
|
62
|
+
```
|
63
|
+
{ "index" : { "_index" : "logstash-2013.01.01, "_type" : "fluentd", "_id" : "87d89af7daffad6" } }
|
64
|
+
{ "name": "Johnny", "request_id": "87d89af7daffad6" }
|
65
|
+
```
|
66
|
+
|
67
|
+
---
|
68
|
+
|
54
69
|
fluentd-plugin-elasticsearch is a buffered output that uses elasticseach's bulk API. So additional buffer configuration would be (with default values):
|
55
70
|
|
56
71
|
```
|
@@ -3,8 +3,8 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-elasticsearch"
|
6
|
-
s.version = '0.1.
|
7
|
-
s.authors = ["diogo"]
|
6
|
+
s.version = '0.1.2'
|
7
|
+
s.authors = ["diogo", 'pitr']
|
8
8
|
s.email = ["team@uken.com"]
|
9
9
|
s.description = %q{ElasticSearch output plugin for Fluent event collector}
|
10
10
|
s.summary = s.description
|
@@ -10,6 +10,7 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
|
|
10
10
|
config_param :logstash_format, :bool, :default => false
|
11
11
|
config_param :type_name, :string, :default => "fluentd"
|
12
12
|
config_param :index_name, :string, :default => "fluentd"
|
13
|
+
config_param :id_key, :string, :default => nil
|
13
14
|
|
14
15
|
include Fluent::SetTagKeyMixin
|
15
16
|
config_set_default :include_tag_key, false
|
@@ -49,7 +50,11 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
|
|
49
50
|
record.merge!(@tag_key => tag)
|
50
51
|
end
|
51
52
|
|
52
|
-
|
53
|
+
meta = { "index" => {"_index" => target_index, "_type" => type_name} }
|
54
|
+
if @id_key && record[@id_key]
|
55
|
+
meta['index']['_id'] = record[@id_key]
|
56
|
+
end
|
57
|
+
bulk_message << meta.to_json
|
53
58
|
bulk_message << record.to_json
|
54
59
|
end
|
55
60
|
bulk_message << ""
|
@@ -26,7 +26,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def sample_record
|
29
|
-
{'age' => 26}
|
29
|
+
{'age' => 26, 'request_id' => '42'}
|
30
30
|
end
|
31
31
|
|
32
32
|
def stub_elastic(url="http://localhost:9200/_bulk")
|
@@ -140,4 +140,27 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
140
140
|
assert(index_cmds[1].has_key?('tag'))
|
141
141
|
assert_equal(index_cmds[1]['tag'], 'mytag')
|
142
142
|
end
|
143
|
+
|
144
|
+
def test_adds_id_key_when_configured
|
145
|
+
driver.configure("id_key request_id\n")
|
146
|
+
stub_elastic
|
147
|
+
driver.emit(sample_record)
|
148
|
+
driver.run
|
149
|
+
assert_equal(index_cmds[0]['index']['_id'], '42')
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_doesnt_add_id_key_if_missing_when_configured
|
153
|
+
driver.configure("id_key another_request_id\n")
|
154
|
+
stub_elastic
|
155
|
+
driver.emit(sample_record)
|
156
|
+
driver.run
|
157
|
+
assert(!index_cmds[0]['index'].has_key?('_id'))
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_adds_id_key_when_not_configured
|
161
|
+
stub_elastic
|
162
|
+
driver.emit(sample_record)
|
163
|
+
driver.run
|
164
|
+
assert(!index_cmds[0]['index'].has_key?('_id'))
|
165
|
+
end
|
143
166
|
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- diogo
|
9
|
+
- pitr
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
+
date: 2013-05-22 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: fluentd
|
@@ -68,6 +69,7 @@ extra_rdoc_files: []
|
|
68
69
|
files:
|
69
70
|
- .gitignore
|
70
71
|
- Gemfile
|
72
|
+
- History.md
|
71
73
|
- LICENSE.txt
|
72
74
|
- README.md
|
73
75
|
- Rakefile
|
@@ -89,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
91
|
version: '0'
|
90
92
|
segments:
|
91
93
|
- 0
|
92
|
-
hash:
|
94
|
+
hash: 3762640390142768539
|
93
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
96
|
none: false
|
95
97
|
requirements:
|
@@ -98,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
100
|
version: '0'
|
99
101
|
segments:
|
100
102
|
- 0
|
101
|
-
hash:
|
103
|
+
hash: 3762640390142768539
|
102
104
|
requirements: []
|
103
105
|
rubyforge_project:
|
104
106
|
rubygems_version: 1.8.23
|