fluent-plugin-cloudwatch-logs-foxtrot9 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e9860853e72bd8d07d2a4a7be45ab161a899169a
4
+ data.tar.gz: 2e6db8c84e8adff718b7d264e84b2237b48b1db0
5
+ SHA512:
6
+ metadata.gz: 360bc882fffe5ba04ad3c2536cd23182cbd02a1a4b954962ecfe4ddf9b74512cdba59fe3b05848c4cacaac3121ace5a3d4fff5c7cd8a46697a4862f7d9469fc0
7
+ data.tar.gz: 4993d8ee1e20ae9050f96bd696e4cca64c9f8eca8832c21f614f83fe67acdef5651aa90cb206f3f321c415eda68f40290b8991aa6dd9d2799378707d8032f39a
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+
4
+ rvm:
5
+ - 2.6
6
+ - 2.5
7
+ - 2.4
8
+ - 2.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-cloudwatch-logs.gemspec
4
+ gemspec
data/ISSUE_TEMPLATE.md ADDED
@@ -0,0 +1,21 @@
1
+ #### Problem
2
+
3
+ ...
4
+
5
+ #### Steps to replicate
6
+
7
+ Provide example config and message
8
+
9
+ #### Expected Behavior or What you need to ask
10
+
11
+ ...
12
+
13
+ #### Using Fluentd and CloudWatchLogs plugin versions
14
+
15
+ * OS version
16
+ * Bare Metal or within Docker or Kubernetes or others?
17
+ * Fluentd v0.12 or v0.14/v1.0
18
+ * paste result of ``fluentd --version`` or ``td-agent --version``
19
+ * Dependent gem versions
20
+ * paste boot log of fluentd or td-agent
21
+ * paste result of ``fluent-gem list``, ``td-agent-gem list`` or your Gemfile.lock
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryota Arai
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,368 @@
1
+ # This is fork of https://github.com/fluent-plugins-nursery/fluent-plugin-cloudwatch-logs
2
+
3
+ ## Changes:
4
+ 1. https://github.com/fluent-plugins-nursery/fluent-plugin-cloudwatch-logs/pull/159/files
5
+
6
+ # fluent-plugin-cloudwatch-logs
7
+
8
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-cloudwatch-logs.svg)](http://badge.fury.io/rb/fluent-plugin-cloudwatch-logs)
9
+
10
+ [CloudWatch Logs](http://aws.amazon.com/blogs/aws/cloudwatch-log-service/) Plugin for Fluentd
11
+
12
+ ## Requirements
13
+
14
+ |fluent-plugin-cloudwatch-logs| fluentd | ruby |
15
+ |-----------------------------|------------------|--------|
16
+ | >= 0.5.0 | >= 0.14.15 | >= 2.1 |
17
+ | <= 0.4.5 | ~> 0.12.0 * | >= 1.9 |
18
+
19
+ * May not support all future fluentd features
20
+
21
+ ## Installation
22
+
23
+ ```sh
24
+ gem install fluent-plugin-cloudwatch-logs-foxtrot9
25
+ ```
26
+
27
+ ## Preparation
28
+
29
+ Create IAM user with a policy like the following:
30
+
31
+ ```json
32
+ {
33
+ "Version": "2012-10-17",
34
+ "Statement": [
35
+ {
36
+ "Effect": "Allow",
37
+ "Action": [
38
+ "logs:*",
39
+ "s3:GetObject"
40
+ ],
41
+ "Resource": [
42
+ "arn:aws:logs:us-east-1:*:*",
43
+ "arn:aws:s3:::*"
44
+ ]
45
+ }
46
+ ]
47
+ }
48
+ ```
49
+
50
+ ## Authentication
51
+
52
+ There are several methods to provide authentication credentials. Be aware that there are various tradeoffs for these methods,
53
+ although most of these tradeoffs are highly dependent on the specific environment.
54
+
55
+ ### Environment
56
+
57
+ Set region and credentials via the environment:
58
+
59
+ ```sh
60
+ export AWS_REGION=us-east-1
61
+ export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY"
62
+ export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY"
63
+ ```
64
+
65
+ Note: For this to work persistently the enviornment will need to be set in the startup scripts or docker variables.
66
+
67
+ ### AWS Configuration
68
+
69
+ The plugin will look for the `$HOME/.aws/config` and `$HOME/.aws/credentials` for configuration information. To setup, as the
70
+ fluentd user, run:
71
+
72
+ ```sh
73
+ aws configure
74
+ ```
75
+
76
+ ### Configuration Parameters
77
+
78
+ The authentication information can also be set
79
+
80
+ ## Example
81
+
82
+ Start fluentd:
83
+
84
+ ```sh
85
+ fluentd -c example/fluentd.conf
86
+ ```
87
+
88
+ Send sample log to CloudWatch Logs:
89
+
90
+ ```sh
91
+ echo '{"hello":"world"}' | fluent-cat test.cloudwatch_logs.out
92
+ ```
93
+
94
+ Fetch sample log from CloudWatch Logs:
95
+
96
+ ```sh
97
+ # stdout
98
+ 2014-07-17 00:28:02 +0900 test.cloudwatch_logs.in: {"hello":"world"}
99
+ ```
100
+
101
+ ## Configuration
102
+
103
+ ### out_cloudwatch_logs
104
+
105
+ ```aconf
106
+ <match tag>
107
+ @type cloudwatch_logs
108
+ log_group_name log-group-name
109
+ log_stream_name log-stream-name
110
+ auto_create_stream true
111
+ #message_keys key1,key2,key3,...
112
+ #max_message_length 32768
113
+ #use_tag_as_group false
114
+ #use_tag_as_stream false
115
+ #include_time_key true
116
+ #localtime true
117
+ #log_group_name_key group_name_key
118
+ #log_stream_name_key stream_name_key
119
+ #remove_log_group_name_key true
120
+ #remove_log_stream_name_key true
121
+ #put_log_events_retry_wait 1s
122
+ #put_log_events_retry_limit 17
123
+ #put_log_events_disable_retry_limit false
124
+ #endpoint http://localhost:5000/
125
+ #json_handler json
126
+ #log_rejected_request true
127
+ </match>
128
+ ```
129
+
130
+ * `auto_create_stream`: to create log group and stream automatically. (defaults to false)
131
+ * `aws_key_id`: AWS Access Key. See [Authentication](#authentication) for more information.
132
+ * `aws_sec_key`: AWS Secret Access Key. See [Authentication](#authentication) for more information.
133
+ * `concurrency`: use to set the number of threads pushing data to CloudWatch. (default: 1)
134
+ * `endpoint`: use this parameter to connect to the local API endpoint (for testing)
135
+ * `http_proxy`: use to set an optional HTTP proxy
136
+ * `include_time_key`: include time key as part of the log entry (defaults to UTC)
137
+ * `json_handler`: name of the library to be used to handle JSON data. For now, supported libraries are `json` (default) and `yajl`.
138
+ * `localtime`: use localtime timezone for `include_time_key` output (overrides UTC default)
139
+ * `log_group_aws_tags`: set a hash with keys and values to tag the log group resource
140
+ * `log_group_aws_tags_key`: use specified field of records as AWS tags for the log group
141
+ * `log_group_name`: name of log group to store logs
142
+ * `log_group_name_key`: use specified field of records as log group name
143
+ * `log_rejected_request`: output `rejected_log_events_info` request log. (defaults to false)
144
+ * `log_stream_name`: name of log stream to store logs
145
+ * `log_stream_name_key`: use specified field of records as log stream name
146
+ * `max_events_per_batch`: maximum number of events to send at once (default 10000)
147
+ * `max_message_length`: maximum length of the message
148
+ * `message_keys`: keys to send messages as events
149
+ * `put_log_events_disable_retry_limit`: if true, `put_log_events_retry_limit` will be ignored
150
+ * `put_log_events_retry_limit`: maximum count of retry (if exceeding this, the events will be discarded)
151
+ * `put_log_events_retry_wait`: time before retrying PutLogEvents (retry interval increases exponentially like `put_log_events_retry_wait * (2 ^ retry_count)`)
152
+ * `region`: AWS Region. See [Authentication](#authentication) for more information.
153
+ * `remove_log_group_aws_tags_key`: remove field specified by `log_group_aws_tags_key`
154
+ * `remove_log_group_name_key`: remove field specified by `log_group_name_key`
155
+ * `remove_log_stream_name_key`: remove field specified by `log_stream_name_key`
156
+ * `remove_retention_in_days`: remove field specified by `retention_in_days`
157
+ * `retention_in_days`: use to set the expiry time for log group when created with `auto_create_stream`. (default to no expiry)
158
+ * `retention_in_days_key`: use specified field of records as retention period
159
+ * `use_tag_as_group`: to use tag as a group name
160
+ * `use_tag_as_stream`: to use tag as a stream name
161
+
162
+ **NOTE:** `retention_in_days` requests additional IAM permission `logs:PutRetentionPolicy` for log_group.
163
+ Please refer to [the PutRetentionPolicy column in documentation](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/permissions-reference-cwl.html) for details.
164
+
165
+ ### in_cloudwatch_logs
166
+
167
+ ```aconf
168
+ <source>
169
+ @type cloudwatch_logs
170
+ tag cloudwatch.in
171
+ log_group_name group
172
+ log_stream_name stream
173
+ #use_log_stream_name_prefix true
174
+ state_file /var/lib/fluent/group_stream.in.state
175
+ #endpoint http://localhost:5000/
176
+ #json_handler json
177
+ </source>
178
+ ```
179
+
180
+ * `aws_key_id`: AWS Access Key. See [Authentication](#authentication) for more information.
181
+ * `aws_sec_key`: AWS Secret Access Key. See [Authentication](#authentication) for more information.
182
+ * `aws_sts_role_arn`: the role ARN to assume when using cross-account sts authentication
183
+ * `aws_sts_session_name`: the session name to use with sts authentication (default: `fluentd`)
184
+ * `aws_use_sts`: use [AssumeRoleCredentials](http://docs.aws.amazon.com/sdkforruby/api/Aws/AssumeRoleCredentials.html) to authenticate, rather than the [default credential hierarchy](http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudWatchLogs/Client.html#initialize-instance_method). See 'Cross-Account Operation' below for more detail.
185
+ * `endpoint`: use this parameter to connect to the local API endpoint (for testing)
186
+ * `fetch_interval`: time period in seconds between checking CloudWatch for new logs. (default: 60)
187
+ * `http_proxy`: use to set an optional HTTP proxy
188
+ * `json_handler`: name of the library to be used to handle JSON data. For now, supported libraries are `json` (default) and `yajl`.
189
+ * `log_group_name`: name of log group to fetch logs
190
+ * `log_stream_name`: name of log stream to fetch logs
191
+ * `region`: AWS Region. See [Authentication](#authentication) for more information.
192
+ * `state_file`: file to store current state (e.g. next\_forward\_token)
193
+ * `tag`: fluentd tag
194
+ * `use_log_stream_name_prefix`: to use `log_stream_name` as log stream name prefix (default false)
195
+ * `use_todays_log_stream`: use todays and yesterdays date as log stream name prefix (formatted YYYY/MM/DD). (default: `false`)
196
+ * `use_aws_timestamp`: get timestamp from Cloudwatch event for non json logs, otherwise fluentd will parse the log to get the timestamp (default `false`)
197
+
198
+ ## Test
199
+
200
+ Set credentials:
201
+
202
+ ```aconf
203
+ $ export AWS_REGION=us-east-1
204
+ $ export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY"
205
+ $ export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_KEY"
206
+ ```
207
+
208
+ Run tests:
209
+
210
+ ```sh
211
+ rake test
212
+ ```
213
+
214
+ Or, If you do not want to use IAM roll or ENV(this is just like writing to configuration file) :
215
+
216
+ ```sh
217
+ rake aws_key_id=YOUR_ACCESS_KEY aws_sec_key=YOUR_SECRET_KEY region=us-east-1 test
218
+ ```
219
+
220
+ If you want to run the test suite against a mock server, set `endpoint` as below:
221
+
222
+ ```sh
223
+ export endpoint='http://localhost:5000/'
224
+ rake test
225
+ ```
226
+
227
+
228
+ ## Caution
229
+
230
+ If an event message exceeds API limit (256KB), the event will be discarded.
231
+
232
+ ## Cross-Account Operation
233
+
234
+ In order to have an instance of this plugin running in one AWS account to fetch logs from another account cross-account IAM authentication is required. Whilst this can be accomplished by configuring specific instances of the plugin manually with credentials for the source account in question this is not desirable for a number of reasons.
235
+
236
+ In this case IAM can be used to allow the fluentd instance in one account ("A") to ingest Cloudwatch logs from another ("B") via the following mechanic:
237
+
238
+ * plugin instance running in account "A" has an IAM instance role assigned to the underlying EC2 instance
239
+ * The IAM instance role and associated policies permit the EC2 instance to assume a role in another account
240
+ * An IAM role in account "B" and associated policies allow read access to the Cloudwatch Logs service, as appropriate.
241
+
242
+ ### IAM Detail: Consuming Account "A"
243
+
244
+ * Create an IAM role `cloudwatch`
245
+ * Attach a policy to allow the role holder to assume another role (where `ACCOUNT-B` is substituted for the appropriate account number):
246
+
247
+ ```json
248
+ {
249
+ "Version": "2012-10-17",
250
+ "Statement": [
251
+ {
252
+ "Effect": "Allow",
253
+ "Action": [
254
+ "sts:*"
255
+ ],
256
+ "Resource": [
257
+ "arn:aws:iam::ACCOUNT-B:role/fluentd"
258
+ ]
259
+ }
260
+ ]
261
+ }
262
+ ```
263
+
264
+ * Ensure the EC2 instance on which this plugin is executing as role `cloudwatch` as its assigned IAM instance role.
265
+
266
+ ### IAM Detail: Log Source Account "B"
267
+
268
+ * Create an IAM role `fluentd`
269
+ * Ensure the `fluentd` role as account "A" as a trusted entity:
270
+
271
+ ```json
272
+ {
273
+ "Version": "2012-10-17",
274
+ "Statement": [
275
+ {
276
+ "Effect": "Allow",
277
+ "Principal": {
278
+ "AWS": "arn:aws:iam::ACCOUNT-A:root"
279
+ },
280
+ "Action": "sts:AssumeRole"
281
+ }
282
+ ]
283
+ }
284
+ ```
285
+
286
+ * Attach a policy:
287
+
288
+ ```json
289
+ {
290
+ "Version": "2012-10-17",
291
+ "Statement": [
292
+ {
293
+ "Effect": "Allow",
294
+ "Action": [
295
+ "logs:DescribeDestinations",
296
+ "logs:DescribeExportTasks",
297
+ "logs:DescribeLogGroups",
298
+ "logs:DescribeLogStreams",
299
+ "logs:DescribeMetricFilters",
300
+ "logs:DescribeSubscriptionFilters",
301
+ "logs:FilterLogEvents",
302
+ "logs:GetLogEvents"
303
+ ],
304
+ "Resource": [
305
+ "arn:aws:logs:eu-west-1:ACCOUNT-B:log-group:LOG_GROUP_NAME_FOR_CONSUMPTION:*"
306
+ ]
307
+ }
308
+ ]
309
+ }
310
+ ```
311
+
312
+ ### Configuring the plugin for STS authentication
313
+
314
+ ```aconf
315
+ <source>
316
+ @type cloudwatch_logs
317
+ region us-east-1 # You must supply a region
318
+ aws_use_sts true
319
+ aws_sts_role_arn arn:aws:iam::ACCOUNT-B:role/fluentd
320
+ log_group_name LOG_GROUP_NAME_FOR_CONSUMPTION
321
+ log_stream_name SOME_PREFIX
322
+ use_log_stream_name_prefix true
323
+ state_file /path/to/state_file
324
+ format /(?<message>.+)/
325
+ </source>
326
+ ```
327
+
328
+ ### Using build-in placeholders, but they don't replace placeholders with actual values, why?
329
+
330
+ Built-in placeholders use buffer metadata when replacing placeholders with actual values.
331
+ So, you should specify buffer attributes what you want to replace placeholders with.
332
+
333
+ Using `${tag}` placeholders, you should specify `tag` attributes in buffer:
334
+
335
+ ```aconf
336
+ <buffer tag>
337
+ @type memory
338
+ </buffer>
339
+ ```
340
+
341
+ Using `%Y%m%d` placeholders, you should specify `time` attributes in buffer:
342
+
343
+ ```aconf
344
+ <buffer time>
345
+ @type memory
346
+ timekey 3600
347
+ </buffer>
348
+ ```
349
+
350
+ In more detail, please refer to [the officilal document for built-in placeholders](https://docs.fluentd.org/v1.0/articles/buffer-section#placeholders).
351
+
352
+ ## TODO
353
+
354
+ * out_cloudwatch_logs
355
+ * if the data is too big for API, split into multiple requests
356
+ * format
357
+ * check data size
358
+ * in_cloudwatch_logs
359
+ * format
360
+ * fallback to start_time because next_token expires after 24 hours
361
+
362
+ ## Contributing
363
+
364
+ 1. Fork it ( https://github.com/[my-github-username]/fluent-plugin-cloudwatch-logs/fork )
365
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
366
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
367
+ 4. Push to the branch (`git push origin my-new-feature`)
368
+ 5. Create a new Pull Request