fluent-plugin-elasticsearch 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in fluent-plugin-elasticsearch.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
data/History.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 0.2.0
5
+ =====
6
+
7
+ - fix encoding issues with JSON conversion and again when sending to elasticsearch (#19, #21)
8
+ - add logstash_dateformat option (#20)
9
+
4
10
  0.1.4
5
11
  =====
6
12
 
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Fluent::Plugin::Elasticsearch
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-elasticsearch.png)](http://badge.fury.io/rb/fluent-plugin-elasticsearch)
4
+ [![Dependency Status](https://gemnasium.com/uken/guard-sidekiq.png)](https://gemnasium.com/uken/fluent-plugin-elasticsearch)
5
+ [![Build Status](https://travis-ci.org/uken/fluent-plugin-elasticsearch.png?branch=master)](https://travis-ci.org/uken/fluent-plugin-elasticsearch)
6
+ [![Coverage Status](https://coveralls.io/repos/uken/fluent-plugin-elasticsearch/badge.png)](https://coveralls.io/r/uken/fluent-plugin-elasticsearch)
7
+ [![Code Climate](https://codeclimate.com/github/uken/fluent-plugin-elasticsearch.png)](https://codeclimate.com/github/uken/fluent-plugin-elasticsearch)
8
+
3
9
  I wrote this so you can search logs routed through Fluentd.
4
10
 
5
11
  ## Installation
@@ -32,6 +38,12 @@ logstash_prefix mylogs # defaults to "logstash"
32
38
 
33
39
  By default, the records inserted into index `logstash-YYMMDD`. This option allows to insert into specified index like `mylogs-YYMMDD`.
34
40
 
41
+ ```
42
+ logstash_dateformat %Y.%m. # defaults to "%Y.%m.%d"
43
+ ```
44
+
45
+ By default, the records inserted into index `logstash-YYMMDD`. This option allows to insert into specified index like `logstash-YYYYMM` for a monthly index.
46
+
35
47
  ---
36
48
 
37
49
  ```
@@ -82,7 +94,21 @@ retry_wait 1.0
82
94
  num_threads 1
83
95
  ```
84
96
 
97
+ ---
98
+
99
+ Please consider using [fluent-plugin-forest](https://github.com/tagomoris/fluent-plugin-forest) to send multiple logs to multiple ElasticSearch indices:
85
100
 
101
+ ```
102
+ <match my.logs.*>
103
+ type forest
104
+ subtype elasticsearch
105
+ remove_prefix my.logs
106
+ <template>
107
+ logstash_prefix ${tag}
108
+ # ...
109
+ </template>
110
+ </match>
111
+ ```
86
112
 
87
113
  ## Contributing
88
114
 
@@ -3,12 +3,13 @@ $:.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.4'
6
+ s.version = '0.2.0'
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}
10
10
  s.summary = s.description
11
11
  s.homepage = "https://github.com/uken/fluent-plugin-elasticsearch"
12
+ s.license = 'MIT'
12
13
 
13
14
  s.files = `git ls-files`.split($/)
14
15
  s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -9,6 +9,7 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
9
9
  config_param :port, :integer, :default => 9200
10
10
  config_param :logstash_format, :bool, :default => false
11
11
  config_param :logstash_prefix, :string, :default => "logstash"
12
+ config_param :logstash_dateformat, :string, :default => "%Y.%m.%d"
12
13
  config_param :type_name, :string, :default => "fluentd"
13
14
  config_param :index_name, :string, :default => "fluentd"
14
15
  config_param :id_key, :string, :default => nil
@@ -42,7 +43,7 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
42
43
  chunk.msgpack_each do |tag, time, record|
43
44
  if @logstash_format
44
45
  record.merge!({"@timestamp" => Time.at(time).to_datetime.to_s})
45
- target_index = "#{@logstash_prefix}-#{Time.at(time).getutc.strftime("%Y.%m.%d")}"
46
+ target_index = "#{@logstash_prefix}-#{Time.at(time).getutc.strftime("#{@logstash_dateformat}")}"
46
47
  else
47
48
  target_index = @index_name
48
49
  end
@@ -55,13 +56,13 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
55
56
  if @id_key && record[@id_key]
56
57
  meta['index']['_id'] = record[@id_key]
57
58
  end
58
- bulk_message << meta.to_json
59
- bulk_message << record.to_json
59
+ bulk_message << Yajl::Encoder.encode(meta)
60
+ bulk_message << Yajl::Encoder.encode(record)
60
61
  end
61
62
  bulk_message << ""
62
63
 
63
64
  http = Net::HTTP.new(@host, @port.to_i)
64
- request = Net::HTTP::Post.new("/_bulk")
65
+ request = Net::HTTP::Post.new('/_bulk', {'content-type' => 'application/json; charset=utf-8'})
65
66
  request.body = bulk_message.join("\n")
66
67
  http.request(request).value
67
68
  end
@@ -14,7 +14,7 @@ $:.push File.dirname(__FILE__)
14
14
  WebMock.disable_net_connect!
15
15
 
16
16
  class ElasticsearchOutput < Test::Unit::TestCase
17
- attr_accessor :index_cmds
17
+ attr_accessor :index_cmds, :content_type
18
18
 
19
19
  def setup
20
20
  Fluent::Test.setup
@@ -31,6 +31,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
31
31
 
32
32
  def stub_elastic(url="http://localhost:9200/_bulk")
33
33
  stub_request(:post, url).with do |req|
34
+ @content_type = req.headers["Content-Type"]
34
35
  @index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
35
36
  end
36
37
  end
@@ -46,6 +47,13 @@ class ElasticsearchOutput < Test::Unit::TestCase
46
47
  assert_equal('fluentd', index_cmds.first['index']['_index'])
47
48
  end
48
49
 
50
+ def test_wrties_with_proper_content_type
51
+ stub_elastic
52
+ driver.emit(sample_record)
53
+ driver.run
54
+ assert_equal("application/json; charset=utf-8", @content_type)
55
+ end
56
+
49
57
  def test_writes_to_default_type
50
58
  stub_elastic
51
59
  driver.emit(sample_record)
@@ -123,6 +131,29 @@ class ElasticsearchOutput < Test::Unit::TestCase
123
131
  assert_equal(logstash_index, index_cmds.first['index']['_index'])
124
132
  end
125
133
 
134
+ def test_writes_to_logstash_index_with_specified_dateformat
135
+ driver.configure("logstash_format true\n")
136
+ driver.configure("logstash_dateformat %Y.%m\n")
137
+ time = Time.parse Date.today.to_s
138
+ logstash_index = "logstash-#{time.getutc.strftime("%Y.%m")}"
139
+ stub_elastic
140
+ driver.emit(sample_record, time)
141
+ driver.run
142
+ assert_equal(logstash_index, index_cmds.first['index']['_index'])
143
+ end
144
+
145
+ def test_writes_to_logstash_index_with_specified_prefix_and_dateformat
146
+ driver.configure("logstash_format true\n")
147
+ driver.configure("logstash_prefix myprefix\n")
148
+ driver.configure("logstash_dateformat %Y.%m\n")
149
+ time = Time.parse Date.today.to_s
150
+ logstash_index = "myprefix-#{time.getutc.strftime("%Y.%m")}"
151
+ stub_elastic
152
+ driver.emit(sample_record, time)
153
+ driver.run
154
+ assert_equal(logstash_index, index_cmds.first['index']['_index'])
155
+ end
156
+
126
157
  def test_doesnt_add_logstash_timestamp_by_default
127
158
  stub_elastic
128
159
  driver.emit(sample_record)
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
4
+ version: 0.2.0
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-08-28 00:00:00.000000000 Z
13
+ date: 2013-12-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fluentd
@@ -78,7 +78,8 @@ files:
78
78
  - test/helper.rb
79
79
  - test/plugin/test_out_elasticsearch.rb
80
80
  homepage: https://github.com/uken/fluent-plugin-elasticsearch
81
- licenses: []
81
+ licenses:
82
+ - MIT
82
83
  post_install_message:
83
84
  rdoc_options: []
84
85
  require_paths:
@@ -89,12 +90,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
90
  - - ! '>='
90
91
  - !ruby/object:Gem::Version
91
92
  version: '0'
93
+ segments:
94
+ - 0
95
+ hash: -1091394761449257025
92
96
  required_rubygems_version: !ruby/object:Gem::Requirement
93
97
  none: false
94
98
  requirements:
95
99
  - - ! '>='
96
100
  - !ruby/object:Gem::Version
97
101
  version: '0'
102
+ segments:
103
+ - 0
104
+ hash: -1091394761449257025
98
105
  requirements: []
99
106
  rubyforge_project:
100
107
  rubygems_version: 1.8.23
@@ -104,4 +111,3 @@ summary: ElasticSearch output plugin for Fluent event collector
104
111
  test_files:
105
112
  - test/helper.rb
106
113
  - test/plugin/test_out_elasticsearch.rb
107
- has_rdoc: