fluent-plugin-elasticsearch 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.md +10 -0
- data/README.md +6 -0
- data/fluent-plugin-elasticsearch.gemspec +1 -1
- data/lib/fluent/plugin/out_elasticsearch.rb +3 -2
- data/test/plugin/test_out_elasticsearch.rb +23 -0
- metadata +3 -8
data/History.md
CHANGED
data/README.md
CHANGED
@@ -26,6 +26,12 @@ logstash_format true # defaults to false
|
|
26
26
|
|
27
27
|
This is meant to make writing data into elasticsearch compatible to what logstash writes. By doing this, one could take advantade of [kibana](http://kibana.org/).
|
28
28
|
|
29
|
+
```
|
30
|
+
logstash_prefix mylogs # defaults to "logstash"
|
31
|
+
```
|
32
|
+
|
33
|
+
By default, the records inserted into index `logstash-YYMMDD`. This option allows to insert into specified index like `mylogs-YYMMDD`.
|
34
|
+
|
29
35
|
---
|
30
36
|
|
31
37
|
```
|
@@ -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.1.
|
6
|
+
s.version = '0.1.4'
|
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}
|
@@ -8,6 +8,7 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
|
|
8
8
|
config_param :host, :string, :default => 'localhost'
|
9
9
|
config_param :port, :integer, :default => 9200
|
10
10
|
config_param :logstash_format, :bool, :default => false
|
11
|
+
config_param :logstash_prefix, :string, :default => "logstash"
|
11
12
|
config_param :type_name, :string, :default => "fluentd"
|
12
13
|
config_param :index_name, :string, :default => "fluentd"
|
13
14
|
config_param :id_key, :string, :default => nil
|
@@ -41,7 +42,7 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
|
|
41
42
|
chunk.msgpack_each do |tag, time, record|
|
42
43
|
if @logstash_format
|
43
44
|
record.merge!({"@timestamp" => Time.at(time).to_datetime.to_s})
|
44
|
-
target_index = "
|
45
|
+
target_index = "#{@logstash_prefix}-#{Time.at(time).getutc.strftime("%Y.%m.%d")}"
|
45
46
|
else
|
46
47
|
target_index = @index_name
|
47
48
|
end
|
@@ -62,6 +63,6 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
|
|
62
63
|
http = Net::HTTP.new(@host, @port.to_i)
|
63
64
|
request = Net::HTTP::Post.new("/_bulk")
|
64
65
|
request.body = bulk_message.join("\n")
|
65
|
-
http.request(request)
|
66
|
+
http.request(request).value
|
66
67
|
end
|
67
68
|
end
|
@@ -35,6 +35,10 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def stub_elastic_unavailable(url="http://localhost:9200/_bulk")
|
39
|
+
stub_request(:post, url).to_return(:status => [503, "Service Unavailable"])
|
40
|
+
end
|
41
|
+
|
38
42
|
def test_writes_to_default_index
|
39
43
|
stub_elastic
|
40
44
|
driver.emit(sample_record)
|
@@ -108,6 +112,17 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
108
112
|
assert_equal(logstash_index, index_cmds.first['index']['_index'])
|
109
113
|
end
|
110
114
|
|
115
|
+
def test_writes_to_logstash_index_with_specified_prefix
|
116
|
+
driver.configure("logstash_format true\n")
|
117
|
+
driver.configure("logstash_prefix myprefix\n")
|
118
|
+
time = Time.parse Date.today.to_s
|
119
|
+
logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m.%d")}"
|
120
|
+
stub_elastic
|
121
|
+
driver.emit(sample_record, time)
|
122
|
+
driver.run
|
123
|
+
assert_equal(logstash_index, index_cmds.first['index']['_index'])
|
124
|
+
end
|
125
|
+
|
111
126
|
def test_doesnt_add_logstash_timestamp_by_default
|
112
127
|
stub_elastic
|
113
128
|
driver.emit(sample_record)
|
@@ -163,4 +178,12 @@ class ElasticsearchOutput < Test::Unit::TestCase
|
|
163
178
|
driver.run
|
164
179
|
assert(!index_cmds[0]['index'].has_key?('_id'))
|
165
180
|
end
|
181
|
+
|
182
|
+
def test_request_error
|
183
|
+
stub_elastic_unavailable
|
184
|
+
driver.emit(sample_record)
|
185
|
+
assert_raise(Net::HTTPFatalError) {
|
186
|
+
driver.run
|
187
|
+
}
|
188
|
+
end
|
166
189
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: fluentd
|
@@ -89,18 +89,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
89
|
- - ! '>='
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
|
-
segments:
|
93
|
-
- 0
|
94
|
-
hash: 3762640390142768539
|
95
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
93
|
none: false
|
97
94
|
requirements:
|
98
95
|
- - ! '>='
|
99
96
|
- !ruby/object:Gem::Version
|
100
97
|
version: '0'
|
101
|
-
segments:
|
102
|
-
- 0
|
103
|
-
hash: 3762640390142768539
|
104
98
|
requirements: []
|
105
99
|
rubyforge_project:
|
106
100
|
rubygems_version: 1.8.23
|
@@ -110,3 +104,4 @@ summary: ElasticSearch output plugin for Fluent event collector
|
|
110
104
|
test_files:
|
111
105
|
- test/helper.rb
|
112
106
|
- test/plugin/test_out_elasticsearch.rb
|
107
|
+
has_rdoc:
|