fluent-plugin-elasticsearch 0.3.0 → 0.3.1
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.
- data/History.md +4 -0
- data/README.md +7 -1
- data/fluent-plugin-elasticsearch.gemspec +2 -2
- data/lib/fluent/plugin/out_elasticsearch.rb +12 -4
- data/test/plugin/test_out_elasticsearch.rb +22 -11
- metadata +33 -21
- checksums.yaml +0 -7
data/History.md
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,7 @@ I wrote this so you can search logs routed through Fluentd.
|
|
12
12
|
|
13
13
|
$ gem install fluent-plugin-elasticsearch
|
14
14
|
|
15
|
-
* prerequisite : You need to install [libcurl](http://curl.haxx.se/libcurl/) to work with.
|
15
|
+
* prerequisite : You need to install [libcurl (libcurl-devel)](http://curl.haxx.se/libcurl/) to work with.
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
@@ -53,6 +53,12 @@ By default, the records inserted into index `logstash-YYMMDD`. This option allow
|
|
53
53
|
logstash_dateformat %Y.%m. # defaults to "%Y.%m.%d"
|
54
54
|
```
|
55
55
|
|
56
|
+
By default, when inserting records in logstash format, @timestamp is dynamically created with the time at log ingestion. If you'd like to use a custom time. Include an @timestamp with your record.
|
57
|
+
|
58
|
+
```
|
59
|
+
{"@timestamp":"2014-04-07T000:00:00-00:00"}
|
60
|
+
```
|
61
|
+
|
56
62
|
By default, the records inserted into index `logstash-YYMMDD`. This option allows to insert into specified index like `logstash-YYYYMM` for a monthly index.
|
57
63
|
|
58
64
|
```
|
@@ -3,7 +3,7 @@ $:.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.3.
|
6
|
+
s.version = '0.3.1'
|
7
7
|
s.authors = ['diogo', 'pitr']
|
8
8
|
s.email = ['team@uken.com']
|
9
9
|
s.description = %q{ElasticSearch output plugin for Fluent event collector}
|
@@ -21,5 +21,5 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_runtime_dependency 'elasticsearch', '~> 0'
|
22
22
|
|
23
23
|
s.add_development_dependency 'rake', '~> 0'
|
24
|
-
s.add_development_dependency 'webmock', '~>
|
24
|
+
s.add_development_dependency 'webmock', '~> 1'
|
25
25
|
end
|
@@ -34,16 +34,24 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def client
|
37
|
-
@_es ||=
|
37
|
+
@_es ||= begin
|
38
|
+
adapter_conf = lambda {|f| f.adapter :patron }
|
39
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new({ hosts: get_hosts,
|
40
|
+
options: {
|
41
|
+
reload_connections: true,
|
42
|
+
retry_on_failure: 5
|
43
|
+
}}, &adapter_conf)
|
44
|
+
Elasticsearch::Client.new transport: transport
|
45
|
+
end
|
38
46
|
raise "Can not reach Elasticsearch cluster (#{@host}:#{@port})!" unless @_es.ping
|
39
47
|
@_es
|
40
48
|
end
|
41
49
|
|
42
50
|
def get_hosts
|
43
51
|
if @hosts
|
44
|
-
@hosts.split(',').map {|x| x.
|
52
|
+
@hosts.split(',').map {|x| hp = x.split(':'); { host: hp[0], port: hp[1] || @port } }.compact
|
45
53
|
else
|
46
|
-
[
|
54
|
+
[{host: @host, port: @port }]
|
47
55
|
end
|
48
56
|
end
|
49
57
|
|
@@ -60,7 +68,7 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
|
|
60
68
|
|
61
69
|
chunk.msgpack_each do |tag, time, record|
|
62
70
|
if @logstash_format
|
63
|
-
record.merge!({"@timestamp" => Time.at(time).to_datetime.to_s})
|
71
|
+
record.merge!({"@timestamp" => Time.at(time).to_datetime.to_s}) unless record.has_key?("@timestamp")
|
64
72
|
if @utc_index
|
65
73
|
target_index = "#{@logstash_prefix}-#{Time.at(time).getutc.strftime("#{@logstash_dateformat}")}"
|
66
74
|
else
|
@@ -119,7 +119,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
119
119
|
stub_elastic_with_store_index_command_counts("http://#{host}:#{port}/_bulk")
|
120
120
|
end
|
121
121
|
|
122
|
-
1000.times do
|
122
|
+
1000.times do
|
123
123
|
driver.emit(sample_record.merge('age'=>rand(100)))
|
124
124
|
end
|
125
125
|
|
@@ -128,7 +128,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
128
128
|
# @note: we cannot make multi chunks with options (flush_interval, buffer_chunk_limit)
|
129
129
|
# it's Fluentd test driver's constraint
|
130
130
|
# so @index_command_counts.size is always 1
|
131
|
-
|
131
|
+
|
132
132
|
assert(@index_command_counts.size > 0, "not working with hosts options")
|
133
133
|
|
134
134
|
total = 0
|
@@ -169,8 +169,8 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
169
169
|
end
|
170
170
|
|
171
171
|
def test_writes_to_logstash_utc_index
|
172
|
-
driver.configure("logstash_format true
|
173
|
-
|
172
|
+
driver.configure("logstash_format true
|
173
|
+
utc_index false")
|
174
174
|
time = Time.parse Date.today.to_s
|
175
175
|
utc_index = "logstash-#{time.strftime("%Y.%m.%d")}"
|
176
176
|
stub_elastic_ping
|
@@ -181,8 +181,8 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
181
181
|
end
|
182
182
|
|
183
183
|
def test_writes_to_logstash_index_with_specified_prefix
|
184
|
-
driver.configure("logstash_format true
|
185
|
-
|
184
|
+
driver.configure("logstash_format true
|
185
|
+
logstash_prefix myprefix")
|
186
186
|
time = Time.parse Date.today.to_s
|
187
187
|
logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
|
188
188
|
stub_elastic_ping
|
@@ -193,8 +193,8 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
193
193
|
end
|
194
194
|
|
195
195
|
def test_writes_to_logstash_index_with_specified_dateformat
|
196
|
-
driver.configure("logstash_format true
|
197
|
-
|
196
|
+
driver.configure("logstash_format true
|
197
|
+
logstash_dateformat %Y.%m")
|
198
198
|
time = Time.parse Date.today.to_s
|
199
199
|
logstash_index = "logstash-#{time.getutc.strftime("%Y.%m")}"
|
200
200
|
stub_elastic_ping
|
@@ -205,9 +205,9 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
205
205
|
end
|
206
206
|
|
207
207
|
def test_writes_to_logstash_index_with_specified_prefix_and_dateformat
|
208
|
-
driver.configure("logstash_format true
|
209
|
-
|
210
|
-
|
208
|
+
driver.configure("logstash_format true
|
209
|
+
logstash_prefix myprefix
|
210
|
+
logstash_dateformat %Y.%m")
|
211
211
|
time = Time.parse Date.today.to_s
|
212
212
|
logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m")}"
|
213
213
|
stub_elastic_ping
|
@@ -236,6 +236,17 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
236
236
|
assert_equal(index_cmds[1]['@timestamp'], ts)
|
237
237
|
end
|
238
238
|
|
239
|
+
def test_uses_custom_timestamp_when_included_in_record
|
240
|
+
driver.configure("logstash_format true\n")
|
241
|
+
stub_elastic_ping
|
242
|
+
stub_elastic
|
243
|
+
ts = DateTime.new(2001,2,3).to_s
|
244
|
+
driver.emit(sample_record.merge!('@timestamp' => ts))
|
245
|
+
driver.run
|
246
|
+
assert(index_cmds[1].has_key? '@timestamp')
|
247
|
+
assert_equal(index_cmds[1]['@timestamp'], ts)
|
248
|
+
end
|
249
|
+
|
239
250
|
def test_doesnt_add_tag_key_by_default
|
240
251
|
stub_elastic_ping
|
241
252
|
stub_elastic
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- diogo
|
@@ -9,78 +10,88 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2014-
|
13
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: fluentd
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
|
-
- -
|
20
|
+
- - ~>
|
19
21
|
- !ruby/object:Gem::Version
|
20
22
|
version: '0'
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
|
-
- -
|
28
|
+
- - ~>
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: '0'
|
28
31
|
- !ruby/object:Gem::Dependency
|
29
32
|
name: patron
|
30
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
31
35
|
requirements:
|
32
|
-
- -
|
36
|
+
- - ~>
|
33
37
|
- !ruby/object:Gem::Version
|
34
38
|
version: '0'
|
35
39
|
type: :runtime
|
36
40
|
prerelease: false
|
37
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
38
43
|
requirements:
|
39
|
-
- -
|
44
|
+
- - ~>
|
40
45
|
- !ruby/object:Gem::Version
|
41
46
|
version: '0'
|
42
47
|
- !ruby/object:Gem::Dependency
|
43
48
|
name: elasticsearch
|
44
49
|
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
45
51
|
requirements:
|
46
|
-
- -
|
52
|
+
- - ~>
|
47
53
|
- !ruby/object:Gem::Version
|
48
54
|
version: '0'
|
49
55
|
type: :runtime
|
50
56
|
prerelease: false
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
52
59
|
requirements:
|
53
|
-
- -
|
60
|
+
- - ~>
|
54
61
|
- !ruby/object:Gem::Version
|
55
62
|
version: '0'
|
56
63
|
- !ruby/object:Gem::Dependency
|
57
64
|
name: rake
|
58
65
|
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
59
67
|
requirements:
|
60
|
-
- -
|
68
|
+
- - ~>
|
61
69
|
- !ruby/object:Gem::Version
|
62
70
|
version: '0'
|
63
71
|
type: :development
|
64
72
|
prerelease: false
|
65
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
66
75
|
requirements:
|
67
|
-
- -
|
76
|
+
- - ~>
|
68
77
|
- !ruby/object:Gem::Version
|
69
78
|
version: '0'
|
70
79
|
- !ruby/object:Gem::Dependency
|
71
80
|
name: webmock
|
72
81
|
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
73
83
|
requirements:
|
74
|
-
- -
|
84
|
+
- - ~>
|
75
85
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
86
|
+
version: '1'
|
77
87
|
type: :development
|
78
88
|
prerelease: false
|
79
89
|
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
80
91
|
requirements:
|
81
|
-
- -
|
92
|
+
- - ~>
|
82
93
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
94
|
+
version: '1'
|
84
95
|
description: ElasticSearch output plugin for Fluent event collector
|
85
96
|
email:
|
86
97
|
- team@uken.com
|
@@ -88,8 +99,8 @@ executables: []
|
|
88
99
|
extensions: []
|
89
100
|
extra_rdoc_files: []
|
90
101
|
files:
|
91
|
-
-
|
92
|
-
-
|
102
|
+
- .gitignore
|
103
|
+
- .travis.yml
|
93
104
|
- Gemfile
|
94
105
|
- History.md
|
95
106
|
- LICENSE.txt
|
@@ -102,26 +113,27 @@ files:
|
|
102
113
|
homepage: https://github.com/uken/fluent-plugin-elasticsearch
|
103
114
|
licenses:
|
104
115
|
- MIT
|
105
|
-
metadata: {}
|
106
116
|
post_install_message:
|
107
117
|
rdoc_options: []
|
108
118
|
require_paths:
|
109
119
|
- lib
|
110
120
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
111
122
|
requirements:
|
112
|
-
- -
|
123
|
+
- - ! '>='
|
113
124
|
- !ruby/object:Gem::Version
|
114
125
|
version: '0'
|
115
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
116
128
|
requirements:
|
117
|
-
- -
|
129
|
+
- - ! '>='
|
118
130
|
- !ruby/object:Gem::Version
|
119
131
|
version: '0'
|
120
132
|
requirements: []
|
121
133
|
rubyforge_project:
|
122
|
-
rubygems_version:
|
134
|
+
rubygems_version: 1.8.23.2
|
123
135
|
signing_key:
|
124
|
-
specification_version:
|
136
|
+
specification_version: 3
|
125
137
|
summary: ElasticSearch output plugin for Fluent event collector
|
126
138
|
test_files:
|
127
139
|
- test/helper.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: c80790f854f11ab486602bfec4e4f96ab56f2f56
|
4
|
-
data.tar.gz: 06163c0e34e87393e84f9a8a04d906dff2fc985b
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 9344c56bfe39072a37402e7e2343a7ec28a9d3417cb14f899bc57744bf91e224d98d5fbf3df048b10d37b36c7bf3edb77812ecd10407c76dad514d0174c98828
|
7
|
-
data.tar.gz: 102828a3a5df25a3c5dcf8462c9a43c5afd802bbe974f2497b5d2c1e9c53f6cf8462165b1a3bad895ed34915e4fdce286cc6976f980085cfe41411fdf25dd2f1
|