fluent-plugin-cloudwatch-logs 0.6.1 → 0.7.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3809f992ae8d9967a7f1edae7ac40614496d98e38baf2d6aa18bcfbae5c72ff
4
- data.tar.gz: 4eb7d7741fb3ef6e1c3d698f305c36ac49ee94df4d9350f5794a2e887e29984c
3
+ metadata.gz: 0d9202fe11ec14b83d2eaa50fa1797564123dd3dd20363381143955dacf89729
4
+ data.tar.gz: c054f3d52d90d7497f818160ab8421f8b69582884b32b6547f6073d7cff6ea16
5
5
  SHA512:
6
- metadata.gz: 8da9d33a1217cae533af682e950314d5a0bd5dbaac8019f0309ef541f26434027ef4b0133bbf2e3030a87c685ba00839c766a99336b0dd0c9f1304a65698a647
7
- data.tar.gz: a2df61af2a98d7dab6d2fb4b5aecbb904fd582aa80e9ae3dd4b15c00f8d320dface8b3fbfb8ba3b1cdf47641a8d4edce8e2e03eaf2eafc16ba976cf68edf9514
6
+ metadata.gz: 3693fb0907a876f2f0fbaac363e67bfcce42cc2d5b356d0eeb5b2a41fff8e859a2ba3ee3f08977a7f39318a67a220e7489d9d5dce82e7e82bf234fad8e1b9b9f
7
+ data.tar.gz: 3bf4f873cd6104e26356790e5867dfa21d17b4d67e06dc7f02b07864b83c3f302c176995c3884fce587e1a201d9c373b256b874edd99414b08b597532eef2cf0
data/README.md CHANGED
@@ -134,8 +134,6 @@ Fetch sample log from CloudWatch Logs:
134
134
  * `json_handler`: name of the library to be used to handle JSON data. For now, supported libraries are `json` (default) and `yajl`.
135
135
  * `use_todays_log_stream`: use todays and yesterdays date as log stream name prefix (formatted YYYY/MM/DD). (default: `false`)
136
136
 
137
- This plugin uses [fluent-mixin-config-placeholders](https://github.com/tagomoris/fluent-mixin-config-placeholders) and you can use addtional variables such as %{hostname}, %{uuid}, etc. These variables are useful to put hostname in `log_stream_name`.
138
-
139
137
  ## Test
140
138
 
141
139
  Set credentials:
@@ -2,7 +2,7 @@ module Fluent
2
2
  module Plugin
3
3
  module Cloudwatch
4
4
  module Logs
5
- VERSION = "0.6.1"
5
+ VERSION = "0.7.0"
6
6
  end
7
7
  end
8
8
  end
@@ -22,7 +22,7 @@ module Fluent::Plugin
22
22
  config_param :log_group_name, :string, :default => nil
23
23
  config_param :log_stream_name, :string, :default => nil
24
24
  config_param :auto_create_stream, :bool, default: false
25
- config_param :message_keys, :string, :default => nil
25
+ config_param :message_keys, :array, :default => [], value_type: :string
26
26
  config_param :max_message_length, :integer, :default => nil
27
27
  config_param :max_events_per_batch, :integer, :default => 10000
28
28
  config_param :use_tag_as_group, :bool, :default => false # TODO: Rename to use_tag_as_group_name ?
@@ -123,6 +123,9 @@ module Fluent::Plugin
123
123
  end
124
124
 
125
125
  def write(chunk)
126
+ log_group_name = extract_placeholders(@log_group_name, chunk) if @log_group_name
127
+ log_stream_name = extract_placeholders(@log_stream_name, chunk) if @log_stream_name
128
+
126
129
  queue = Thread::Queue.new
127
130
 
128
131
  chunk.enum_for(:msgpack_each).select {|tag, time, record|
@@ -143,7 +146,7 @@ module Fluent::Plugin
143
146
  record[@log_group_name_key]
144
147
  end
145
148
  else
146
- @log_group_name
149
+ log_group_name
147
150
  end
148
151
 
149
152
  stream = case
@@ -156,7 +159,7 @@ module Fluent::Plugin
156
159
  record[@log_stream_name_key]
157
160
  end
158
161
  else
159
- @log_stream_name
162
+ log_stream_name
160
163
  end
161
164
 
162
165
  [group, stream]
@@ -214,8 +217,8 @@ module Fluent::Plugin
214
217
  time_ms = (time.to_f * 1000).floor
215
218
 
216
219
  scrub_record!(record)
217
- if @message_keys
218
- message = @message_keys.split(',').map {|k| record[k].to_s }.join(' ')
220
+ unless @message_keys.empty?
221
+ message = @message_keys.map {|k| record[k].to_s }.join(' ')
219
222
  else
220
223
  message = @json_handler.dump(record)
221
224
  end
@@ -29,6 +29,7 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
29
29
  auto_create_stream false
30
30
  log_group_aws_tags { "tagkey": "tagvalue", "tagkey_2": "tagvalue_2"}
31
31
  retention_in_days 5
32
+ message_keys fluentd, aws, cloudwatch
32
33
  EOC
33
34
 
34
35
  assert_equal('test_id', d.instance.aws_key_id)
@@ -41,6 +42,7 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
41
42
  assert_equal("tagvalue_2", d.instance.log_group_aws_tags.fetch("tagkey_2"))
42
43
  assert_equal(5, d.instance.retention_in_days)
43
44
  assert_equal(:yajl, d.instance.json_handler)
45
+ assert_equal(["fluentd","aws","cloudwatch"], d.instance.message_keys)
44
46
  end
45
47
 
46
48
  def test_write
@@ -217,6 +219,44 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
217
219
  assert_equal('message2 logs2', events[1].message)
218
220
  end
219
221
 
222
+ def test_write_use_placeholders
223
+ new_log_stream
224
+
225
+ config = {'@type' => 'cloudwatch_logs',
226
+ 'auto_create_stream' => true,
227
+ 'message_keys' => ["message","cloudwatch"],
228
+ 'log_stream_name' => "${tag}",
229
+ 'log_group_name' => log_group_name}
230
+ config.merge!(config_elementify(aws_key_id)) if aws_key_id
231
+ config.merge!(config_elementify(aws_sec_key)) if aws_sec_key
232
+ config.merge!(config_elementify(region)) if region
233
+ config.merge!(config_elementify(endpoint)) if endpoint
234
+
235
+ d = create_driver(
236
+ Fluent::Config::Element.new('ROOT', '', config,[
237
+ Fluent::Config::Element.new('buffer', 'tag, time', {
238
+ '@type' => 'memory',
239
+ 'timekey' => 3600
240
+ }, [])
241
+ ])
242
+ )
243
+
244
+ time = event_time
245
+ d.run(default_tag: fluentd_tag) do
246
+ d.feed(time, {'cloudwatch' => 'logs1', 'message' => 'message1'})
247
+ d.feed(time + 1, {'cloudwatch' => 'logs2', 'message' => 'message2'})
248
+ end
249
+
250
+ sleep 10
251
+
252
+ events = get_log_events(log_group_name, fluentd_tag)
253
+ assert_equal(2, events.size)
254
+ assert_equal((time.to_f * 1000).floor, events[0].timestamp)
255
+ assert_equal('message1 logs1', events[0].message)
256
+ assert_equal((time.to_i + 1) * 1000, events[1].timestamp)
257
+ assert_equal('message2 logs2', events[1].message)
258
+ end
259
+
220
260
  def test_include_time_key
221
261
  new_log_stream
222
262
 
@@ -36,6 +36,10 @@ module CloudwatchLogsTestHelper
36
36
  "endpoint #{ENV['endpoint']}" if ENV['endpoint']
37
37
  end
38
38
 
39
+ def config_elementify(conf)
40
+ conf.split(' ').each_slice(2).map{|k, v| {k => v}}.first
41
+ end
42
+
39
43
  def log_stream_name(log_stream_name_prefix = nil)
40
44
  if !@log_stream_name
41
45
  new_log_stream(log_stream_name_prefix)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-cloudwatch-logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-22 00:00:00.000000000 Z
11
+ date: 2018-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd