rb-fluent-plugin-cloudwatch-logs 0.7.1.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/ISSUE_TEMPLATE.md +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +314 -0
- data/Rakefile +9 -0
- data/example/fluentd.conf +23 -0
- data/fluent-plugin-cloudwatch-logs.gemspec +28 -0
- data/lib/fluent/plugin/cloudwatch/logs.rb +11 -0
- data/lib/fluent/plugin/cloudwatch/logs/version.rb +9 -0
- data/lib/fluent/plugin/in_cloudwatch_logs.rb +194 -0
- data/lib/fluent/plugin/out_cloudwatch_logs.rb +468 -0
- data/test/plugin/test_in_cloudwatch_logs.rb +241 -0
- data/test/plugin/test_out_cloudwatch_logs.rb +749 -0
- data/test/test_helper.rb +105 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cc1f0f04c8474e79922dc8a8ed0536d0d36ef9c039a281e6eb98cb35770ce736
|
4
|
+
data.tar.gz: 9f67a5fe54c8c0b788c742ffd6867920585a99643a335fb19b78305df825fd48
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 20c89a6c3e89ce26dccffd4bfc7096af60c4ec601ad975b5153784c51739bd6ef450b61e6af27747347b86a9290074551c4eae671c99d6365a32c72fe86f87f1
|
7
|
+
data.tar.gz: 6f31d33d83fe96d66dbf8d63cb563a6cdfdc6a93896ab2db865672a925d7ebfb2f12949c2044ee26de8d011427be944595a5a3645edc4bd2c22ff860951470c8
|
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/Gemfile
ADDED
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,314 @@
|
|
1
|
+
# fluent-plugin-cloudwatch-logs
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/fluent-plugin-cloudwatch-logs.svg)](http://badge.fury.io/rb/fluent-plugin-cloudwatch-logs)
|
4
|
+
|
5
|
+
[CloudWatch Logs](http://aws.amazon.com/blogs/aws/cloudwatch-log-service/) Plugin for Fluentd
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
|fluent-plugin-cloudwatch-logs| fluentd | ruby |
|
10
|
+
|-----------------------------|------------------|--------|
|
11
|
+
| >= 0.5.0 | >= 0.14.15 | >= 2.1 |
|
12
|
+
| <= 0.4.5 | ~> 0.12.0 * | >= 1.9 |
|
13
|
+
|
14
|
+
* May not support all future fluentd features
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
$ gem install fluent-plugin-cloudwatch-logs
|
19
|
+
|
20
|
+
## Preparation
|
21
|
+
|
22
|
+
Create IAM user with a policy like the following:
|
23
|
+
|
24
|
+
```json
|
25
|
+
{
|
26
|
+
"Version": "2012-10-17",
|
27
|
+
"Statement": [
|
28
|
+
{
|
29
|
+
"Effect": "Allow",
|
30
|
+
"Action": [
|
31
|
+
"logs:*",
|
32
|
+
"s3:GetObject"
|
33
|
+
],
|
34
|
+
"Resource": [
|
35
|
+
"arn:aws:logs:us-east-1:*:*",
|
36
|
+
"arn:aws:s3:::*"
|
37
|
+
]
|
38
|
+
}
|
39
|
+
]
|
40
|
+
}
|
41
|
+
```
|
42
|
+
|
43
|
+
Set region and credentials:
|
44
|
+
|
45
|
+
```
|
46
|
+
$ export AWS_REGION=us-east-1
|
47
|
+
$ export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY"
|
48
|
+
$ export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY"
|
49
|
+
```
|
50
|
+
|
51
|
+
## Example
|
52
|
+
|
53
|
+
Start fluentd:
|
54
|
+
|
55
|
+
```
|
56
|
+
$ fluentd -c example/fluentd.conf
|
57
|
+
```
|
58
|
+
|
59
|
+
Send sample log to CloudWatch Logs:
|
60
|
+
|
61
|
+
```
|
62
|
+
$ echo '{"hello":"world"}' | fluent-cat test.cloudwatch_logs.out
|
63
|
+
```
|
64
|
+
|
65
|
+
Fetch sample log from CloudWatch Logs:
|
66
|
+
|
67
|
+
```
|
68
|
+
# stdout
|
69
|
+
2014-07-17 00:28:02 +0900 test.cloudwatch_logs.in: {"hello":"world"}
|
70
|
+
```
|
71
|
+
|
72
|
+
## Configuration
|
73
|
+
### out_cloudwatch_logs
|
74
|
+
|
75
|
+
```
|
76
|
+
<match tag>
|
77
|
+
@type cloudwatch_logs
|
78
|
+
log_group_name log-group-name
|
79
|
+
log_stream_name log-stream-name
|
80
|
+
auto_create_stream true
|
81
|
+
#message_keys key1,key2,key3,...
|
82
|
+
#max_message_length 32768
|
83
|
+
#use_tag_as_group false
|
84
|
+
#use_tag_as_stream false
|
85
|
+
#include_time_key true
|
86
|
+
#localtime true
|
87
|
+
#log_group_name_key group_name_key
|
88
|
+
#log_stream_name_key stream_name_key
|
89
|
+
#remove_log_group_name_key true
|
90
|
+
#remove_log_stream_name_key true
|
91
|
+
#put_log_events_retry_wait 1s
|
92
|
+
#put_log_events_retry_limit 17
|
93
|
+
#put_log_events_disable_retry_limit false
|
94
|
+
#endpoint http://localhost:5000/
|
95
|
+
#json_handler json
|
96
|
+
</match>
|
97
|
+
```
|
98
|
+
|
99
|
+
* `log_group_name`: name of log group to store logs
|
100
|
+
* `log_stream_name`: name of log stream to store logs
|
101
|
+
* `auto_create_stream`: to create log group and stream automatically
|
102
|
+
* `message_keys`: keys to send messages as events
|
103
|
+
* `max_message_length`: maximum length of the message
|
104
|
+
* `max_events_per_batch`: maximum number of events to send at once (default 10000)
|
105
|
+
* `use_tag_as_group`: to use tag as a group name
|
106
|
+
* `use_tag_as_stream`: to use tag as a stream name
|
107
|
+
* `include_time_key`: include time key as part of the log entry (defaults to UTC)
|
108
|
+
* `localtime`: use localtime timezone for `include_time_key` output (overrides UTC default)
|
109
|
+
* `log_group_name_key`: use specified field of records as log group name
|
110
|
+
* `log_stream_name_key`: use specified field of records as log stream name
|
111
|
+
* `remove_log_group_name_key`: remove field specified by `log_group_name_key`
|
112
|
+
* `remove_log_stream_name_key`: remove field specified by `log_stream_name_key`
|
113
|
+
* `put_log_events_retry_wait`: time before retrying PutLogEvents (retry interval increases exponentially like `put_log_events_retry_wait * (2 ^ retry_count)`)
|
114
|
+
* `put_log_events_retry_limit`: maximum count of retry (if exceeding this, the events will be discarded)
|
115
|
+
* `put_log_events_disable_retry_limit`: if true, `put_log_events_retry_limit` will be ignored
|
116
|
+
* `endpoint`: use this parameter to connect to the local API endpoint (for testing)
|
117
|
+
* `json_handler`: name of the library to be used to handle JSON data. For now, supported libraries are `json` (default) and `yajl`.
|
118
|
+
|
119
|
+
### in_cloudwatch_logs
|
120
|
+
|
121
|
+
```
|
122
|
+
<source>
|
123
|
+
@type cloudwatch_logs
|
124
|
+
tag cloudwatch.in
|
125
|
+
log_group_name group
|
126
|
+
log_stream_name stream
|
127
|
+
#use_log_stream_name_prefix true
|
128
|
+
state_file /var/lib/fluent/group_stream.in.state
|
129
|
+
#endpoint http://localhost:5000/
|
130
|
+
#json_handler json
|
131
|
+
</source>
|
132
|
+
```
|
133
|
+
|
134
|
+
* `tag`: fluentd tag
|
135
|
+
* `log_group_name`: name of log group to fetch logs
|
136
|
+
* `log_stream_name`: name of log stream to fetch logs
|
137
|
+
* `use_log_stream_name_prefix`: to use `log_stream_name` as log stream name prefix (default false)
|
138
|
+
* `state_file`: file to store current state (e.g. next\_forward\_token)
|
139
|
+
* `endpoint`: use this parameter to connect to the local API endpoint (for testing)
|
140
|
+
* `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.
|
141
|
+
* `aws_sts_role_arn`: the role ARN to assume when using cross-account sts authentication
|
142
|
+
* `aws_sts_session_name`: the session name to use with sts authentication (default: `fluentd`)
|
143
|
+
* `json_handler`: name of the library to be used to handle JSON data. For now, supported libraries are `json` (default) and `yajl`.
|
144
|
+
* `use_todays_log_stream`: use todays and yesterdays date as log stream name prefix (formatted YYYY/MM/DD). (default: `false`)
|
145
|
+
|
146
|
+
## Test
|
147
|
+
|
148
|
+
Set credentials:
|
149
|
+
|
150
|
+
```
|
151
|
+
$ export AWS_REGION=us-east-1
|
152
|
+
$ export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY"
|
153
|
+
$ export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_KEY"
|
154
|
+
```
|
155
|
+
|
156
|
+
Run tests:
|
157
|
+
|
158
|
+
```
|
159
|
+
$ rake test
|
160
|
+
```
|
161
|
+
|
162
|
+
Or, If you do not want to use IAM roll or ENV(this is just like writing to configuration file) :
|
163
|
+
|
164
|
+
```
|
165
|
+
$ rake aws_key_id=YOUR_ACCESS_KEY aws_sec_key=YOUR_SECRET_KEY region=us-east-1 test
|
166
|
+
```
|
167
|
+
|
168
|
+
If you want to run the test suite against a mock server, set `endpoint` as below:
|
169
|
+
|
170
|
+
```
|
171
|
+
$ export endpoint='http://localhost:5000/'
|
172
|
+
$ rake test
|
173
|
+
```
|
174
|
+
|
175
|
+
|
176
|
+
## Caution
|
177
|
+
|
178
|
+
- If an event message exceeds API limit (256KB), the event will be discarded.
|
179
|
+
|
180
|
+
## Cross-Account Operation
|
181
|
+
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.
|
182
|
+
|
183
|
+
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:
|
184
|
+
|
185
|
+
* plugin instance running in account "A" has an IAM instance role assigned to the underlying EC2 instance
|
186
|
+
* The IAM instance role and associated policies permit the EC2 instance to assume a role in another account
|
187
|
+
* An IAM role in account "B" and associated policies allow read access to the Cloudwatch Logs service, as appropriate.
|
188
|
+
|
189
|
+
### IAM Detail: Consuming Account "A"
|
190
|
+
|
191
|
+
* Create an IAM role `cloudwatch`
|
192
|
+
* Attach a policy to allow the role holder to assume another role (where `ACCOUNT-B` is substituted for the appropriate account number):
|
193
|
+
|
194
|
+
```
|
195
|
+
{
|
196
|
+
"Version": "2012-10-17",
|
197
|
+
"Statement": [
|
198
|
+
{
|
199
|
+
"Effect": "Allow",
|
200
|
+
"Action": [
|
201
|
+
"sts:*"
|
202
|
+
],
|
203
|
+
"Resource": [
|
204
|
+
"arn:aws:iam::ACCOUNT-B:role/fluentd"
|
205
|
+
]
|
206
|
+
}
|
207
|
+
]
|
208
|
+
}
|
209
|
+
```
|
210
|
+
|
211
|
+
* Ensure the EC2 instance on which this plugin is executing as role `cloudwatch` as its assigned IAM instance role.
|
212
|
+
|
213
|
+
### IAM Detail: Log Source Account "B"
|
214
|
+
|
215
|
+
* Create an IAM role `fluentd`
|
216
|
+
* Ensure the `fluentd` role as account "A" as a trusted entity:
|
217
|
+
|
218
|
+
```
|
219
|
+
{
|
220
|
+
"Version": "2012-10-17",
|
221
|
+
"Statement": [
|
222
|
+
{
|
223
|
+
"Effect": "Allow",
|
224
|
+
"Principal": {
|
225
|
+
"AWS": "arn:aws:iam::ACCOUNT-A:root"
|
226
|
+
},
|
227
|
+
"Action": "sts:AssumeRole"
|
228
|
+
}
|
229
|
+
]
|
230
|
+
}
|
231
|
+
```
|
232
|
+
|
233
|
+
* Attach a policy:
|
234
|
+
|
235
|
+
```
|
236
|
+
{
|
237
|
+
"Version": "2012-10-17",
|
238
|
+
"Statement": [
|
239
|
+
{
|
240
|
+
"Effect": "Allow",
|
241
|
+
"Action": [
|
242
|
+
"logs:DescribeDestinations",
|
243
|
+
"logs:DescribeExportTasks",
|
244
|
+
"logs:DescribeLogGroups",
|
245
|
+
"logs:DescribeLogStreams",
|
246
|
+
"logs:DescribeMetricFilters",
|
247
|
+
"logs:DescribeSubscriptionFilters",
|
248
|
+
"logs:FilterLogEvents",
|
249
|
+
"logs:GetLogEvents"
|
250
|
+
],
|
251
|
+
"Resource": [
|
252
|
+
"arn:aws:logs:eu-west-1:ACCOUNT-B:log-group:LOG_GROUP_NAME_FOR_CONSUMPTION:*"
|
253
|
+
]
|
254
|
+
}
|
255
|
+
]
|
256
|
+
}
|
257
|
+
```
|
258
|
+
|
259
|
+
### Configuring the plugin for STS authentication
|
260
|
+
```
|
261
|
+
<source>
|
262
|
+
@type cloudwatch_logs
|
263
|
+
region us-east-1 # You must supply a region
|
264
|
+
aws_use_sts true
|
265
|
+
aws_sts_role_arn arn:aws:iam::ACCOUNT-B:role/fluentd
|
266
|
+
log_group_name LOG_GROUP_NAME_FOR_CONSUMPTION
|
267
|
+
log_stream_name SOME_PREFIX
|
268
|
+
use_log_stream_name_prefix true
|
269
|
+
state_file /path/to/state_file
|
270
|
+
format /(?<message>.+)/
|
271
|
+
</source>
|
272
|
+
```
|
273
|
+
|
274
|
+
### Using build-in placeholders, but they don't replace placeholders with actual values, why?
|
275
|
+
|
276
|
+
Built-in placeholders use buffer metadata when replacing placeholders with actual values.
|
277
|
+
So, you should specify buffer attributes what you want to replace placeholders with.
|
278
|
+
|
279
|
+
Using `${tag}` placeholders, you should specify `tag` attributes in buffer:
|
280
|
+
|
281
|
+
```aconf
|
282
|
+
<buffer tag>
|
283
|
+
@type memory
|
284
|
+
</buffer>
|
285
|
+
```
|
286
|
+
|
287
|
+
Using `%Y%m%d` placeholders, you should specify `time` attributes in buffer:
|
288
|
+
|
289
|
+
```aconf
|
290
|
+
<buffer time>
|
291
|
+
@type memory
|
292
|
+
timekey 3600
|
293
|
+
</buffer>
|
294
|
+
```
|
295
|
+
|
296
|
+
In more detail, please refer to [the officilal document for built-in placeholders](https://docs.fluentd.org/v1.0/articles/buffer-section#placeholders).
|
297
|
+
|
298
|
+
## TODO
|
299
|
+
|
300
|
+
* out_cloudwatch_logs
|
301
|
+
* if the data is too big for API, split into multiple requests
|
302
|
+
* format
|
303
|
+
* check data size
|
304
|
+
* in_cloudwatch_logs
|
305
|
+
* format
|
306
|
+
* fallback to start_time because next_token expires after 24 hours
|
307
|
+
|
308
|
+
## Contributing
|
309
|
+
|
310
|
+
1. Fork it ( https://github.com/[my-github-username]/fluent-plugin-cloudwatch-logs/fork )
|
311
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
312
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
313
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
314
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
<source>
|
2
|
+
@type forward
|
3
|
+
</source>
|
4
|
+
|
5
|
+
<source>
|
6
|
+
@type cloudwatch_logs
|
7
|
+
tag test.cloudwatch_logs.in
|
8
|
+
log_group_name fluent-plugin-cloudwatch-example
|
9
|
+
log_stream_name fluent-plugin-cloudwatch-example
|
10
|
+
state_file /tmp/fluent-plugin-cloudwatch-example.state
|
11
|
+
</source>
|
12
|
+
|
13
|
+
<match test.cloudwatch_logs.out>
|
14
|
+
@type cloudwatch_logs
|
15
|
+
log_group_name fluent-plugin-cloudwatch-example
|
16
|
+
log_stream_name fluent-plugin-cloudwatch-example
|
17
|
+
auto_create_stream true
|
18
|
+
</match>
|
19
|
+
|
20
|
+
<match test.cloudwatch_logs.in>
|
21
|
+
@type stdout
|
22
|
+
</match>
|
23
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fluent/plugin/cloudwatch/logs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rb-fluent-plugin-cloudwatch-logs"
|
8
|
+
spec.version = Fluent::Plugin::Cloudwatch::Logs::VERSION
|
9
|
+
spec.authors = ["Ryota Arai", "Other People"]
|
10
|
+
spec.email = ["ryota.arai@gmail.com"]
|
11
|
+
spec.summary = %q{CloudWatch Logs Plugin for Fluentd with memory profiling}
|
12
|
+
spec.homepage = "https://github.com/redbubble/fluent-plugin-cloudwatch-logs"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency 'fluentd', '>= 0.14.15'
|
21
|
+
spec.add_dependency 'aws-sdk-cloudwatchlogs', '~> 1.0'
|
22
|
+
spec.add_dependency 'memory_profiler'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "test-unit"
|
27
|
+
spec.add_development_dependency "mocha"
|
28
|
+
end
|