fluent-plugin-cloudwatch-logs 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aff209d6a27c958aa30c96374bae93a17e533296
4
- data.tar.gz: 002ed627b666fa502cf81b0042e30d2bd904ba32
3
+ metadata.gz: 26d61c290a6fd56f27524732758ea6e4f8cacd96
4
+ data.tar.gz: 678b4500dc46217e141328d3cd915470a691a2ad
5
5
  SHA512:
6
- metadata.gz: 5dfc3b01f9f885d6885015e878803f7426ac8fabadef0f41a23c70916d1d73b72b65139ffe3455bff2015d3a66f497d464a09d564077914f3aae0bbd92824606
7
- data.tar.gz: 20635343fe05b015f03cb6b81bd06f5145fe779b1ce8eb16e2d313402ba1ecf2e68cc620d6c3ca52b5a3ae83f4d3e775e8a633f00b1eac11abc46a14672854a2
6
+ metadata.gz: 7b6d98c07e99f57022f041d1d4c60738bf847aea9512f8bed75c47de7f25fd5dca7ca3b867289784eb08901e6312f98fe3b929edb7022ed9b2032ca7b52796a9
7
+ data.tar.gz: 8e86a20a0f129546c5300af5811d8f0d0d7d50907bc5622fe44fa03e8115669d8eb5411339533be5f39f0eb4b9733df4a8ced4235e6ca7ffe29c22f6f544bc90
@@ -2,7 +2,7 @@ module Fluent
2
2
  module Plugin
3
3
  module Cloudwatch
4
4
  module Logs
5
- VERSION = "0.0.6"
5
+ VERSION = "0.0.7"
6
6
  end
7
7
  end
8
8
  end
@@ -12,6 +12,8 @@ module Fluent
12
12
  config_param :max_message_length, :integer, :default => nil
13
13
  config_param :use_tag_as_group, :bool, :default => false
14
14
 
15
+ MAX_EVENTS_SIZE = 30720
16
+
15
17
  unless method_defined?(:log)
16
18
  define_method(:log) { $log }
17
19
  end
@@ -70,8 +72,9 @@ module Fluent
70
72
  message = record.to_json
71
73
  end
72
74
 
75
+ message.force_encoding('ASCII-8BIT')
76
+
73
77
  if @max_message_length
74
- message.force_encoding('ASCII-8BIT')
75
78
  message = message.slice(0, @max_message_length)
76
79
  end
77
80
 
@@ -80,7 +83,7 @@ module Fluent
80
83
  # The log events in the batch must be in chronological ordered by their timestamp.
81
84
  # http://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html
82
85
  events = events.sort_by {|e| e[:timestamp] }
83
- put_events(group_name, events)
86
+ put_events_by_chunk(group_name, events)
84
87
  }
85
88
  end
86
89
 
@@ -93,6 +96,25 @@ module Fluent
93
96
  @sequence_tokens[group_name][stream_name] = token
94
97
  end
95
98
 
99
+ def put_events_by_chunk(group_name, events)
100
+ chunk = []
101
+
102
+ # The maximum batch size is 32,768 bytes, and this size is calculated as the sum of all event messages in UTF-8, plus 26 bytes for each log event.
103
+ # http://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html
104
+ while event = events.shift
105
+ if (chunk + [event]).inject(0) {|sum, e| sum + e[:message].length } > MAX_EVENTS_SIZE
106
+ put_events(group_name, chunk)
107
+ chunk = [event]
108
+ else
109
+ chunk << event
110
+ end
111
+ end
112
+
113
+ unless chunk.empty?
114
+ put_events(group_name, chunk)
115
+ end
116
+ end
117
+
96
118
  def put_events(group_name, events)
97
119
  args = {
98
120
  log_events: events,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-cloudwatch-logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai