fluent-plugin-ecs-filter 0.1.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 +15 -0
- data/.gitignore +20 -0
- data/.ruby-version +1 -0
- data/.travis.yml +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +201 -0
- data/README.md +111 -0
- data/Rakefile +11 -0
- data/fluent-plugin-ecs-filter.gemspec +36 -0
- data/lib/fluent/plugin/filter_ecs_filter.rb +161 -0
- data/test/containers/ecs.json +192 -0
- data/test/helper.rb +51 -0
- data/test/plugin/test_mesosphere.rb +128 -0
- metadata +227 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
ZWM4ZTNjMDFjZTg1OTAxNDg0YjQ4MmE3ZDJiYTgyYjUyYWFkYzNlOA==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
YzczZjYwZjNkYjEyYjUzMDM5YzljNThmODNlMjVjOTdjMDhlYTk2ZA==
|
|
7
|
+
SHA512:
|
|
8
|
+
metadata.gz: !binary |-
|
|
9
|
+
NDhiZjVhM2NhMGQwZjljNzFhNzA3YTE2YjllYTdiYmNiZTIyMTU5MGFlY2I5
|
|
10
|
+
MjkzZjM2NTgwNDk5MWU4MTU3MTIwZDMzNTFhMzIzNDVjOGY0NDRjMjAzNGM1
|
|
11
|
+
NWQ1NzE1ZTQ1N2M0ZGIyNTlhZTM1MTdmZmYxZTBlMDAyYjVlM2U=
|
|
12
|
+
data.tar.gz: !binary |-
|
|
13
|
+
OWVhMWM3MDJiNWIzZWYzYmJkNzFmM2VlYTUxYzliNmVkYzk3MGIwM2IyMzVj
|
|
14
|
+
ZjU5ODMyY2VjMGRjMGI4N2FmYTJhMTlmMjcwOWI3OWRiNjg2ODI1ZDdhODU1
|
|
15
|
+
NmNhMjIyY2M2NDk3NzE2MmMwMzVjNTE1NTI5ZDc4YjcxYTg5ZWQ=
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.9.3-p551
|
data/.travis.yml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
language: ruby
|
|
2
|
+
rvm:
|
|
3
|
+
- 2.1.7
|
|
4
|
+
- 1.9.3-p551
|
|
5
|
+
addons:
|
|
6
|
+
code_climate:
|
|
7
|
+
repo_token:
|
|
8
|
+
secure: "TTJV+tkPbGVjCQDZNH5NEVr9HbVheUk0BZjAvJbYRtdIwAHzvVwbe5H24E8V1hq0E/5ECvZPN/mwRDXq5wJ9bT7vx3OasLVIDhlTcDExirgfFCeVQGd0lVyQYjSFMgK9j6iKr4LkHBj2uxBz26Q1UrT0KwXZ4zQ1RWFu8T2VAoqhO8UzDiR5j7ho34rTSqVFJgF7zFz3YPOr8jgK1vynrcNBFe82ElA8bjH+UkVB8p2bG5ib4i+vUqMSXPOBCo+qZ9OGEzmm2dNjRp8VNUBd0JwWrs/1HhGKeQQ7kbpiS8H6mYNJQtiGFgJWrGFjGFlUny09bWT1JRSuBtEZNotGHtZDidxkXHK3yys6ZOyrnAm6DWlYzK2mNzyp/FY+5aSKMnwB+eZ6YrKPPK0CjwXfoAUiOjK2VMJUXWrF5atjiXFrTVEnurDZW7h4vxJb7EDkvb+tuT9aPtxQoS6BrWUKTkl9rT1Xsp+NfBHuTHZMYyv05HsS7RgqXb7bOrPTAGwdam9xCafFOOrwQRF5OkJovZ13UobWzmgqscu4o39HmLXwWnKyC1QQ7FJ8NYLDQEQjQi7FjdCdmmYHhh/Y28brhSW8ar1EaZ1iPTuqsjdYzDqusjtRP5svpoV5RJ5Fes1pdoeXFv2YMaZVFc5RvmlRp8nlwyC9F9PhyjJWwK9f18w="
|
|
9
|
+
deploy:
|
|
10
|
+
provider: rubygems
|
|
11
|
+
api_key:
|
|
12
|
+
secure: "BbwV2W8hxxLaYM1luukejgmgm0ODHFw3CNgQbK15D9tK1VoQqNxCxQzmCYgi2FG1MYYAQcTcVj7W+cd76REmKDEhxEyZUVmIQF+N16Zl2vR/UegsbXVd2Gpel2tyykO9ebSlkXHkwzcCMksIhwCdELJORbxGSqVxTl6FaNPS3bfylev5Cumk8SCKXEvg2BMH0BPFpXZSpijdVv5xTuzM0qQUx/thvEHcm9o9q1JEhM4XbEdffBSOM3BWM9yCoSshKO2GmCBNJOOp8JsDmRR3F+ynuTdV5b8AGSHd7oubh6OxZ26jusJXzIgxZ99hi4FTDRuvvyOcmKn6Of7DN6K3rBNoDmxf4E3OdujSJSRuDG2wbQz/1R7isBniabqxogeCgMEHabXP2QRN+SOkpLQthaFhr+ISMuH5ZRKRYcRBTJ6J/QGDPOxYe0JWJpwVhvE4jDK/UaGph6kt/DLrWR/SLXa2kPDlrWl2xe4z3SwuJRPhkfwHGVLIZSZR21bJ4ONnBYkXbFI8lTsLno7JA6SXPfTODRnJrlUWqV0xIwyWTsoxcgssMVUH2RgqiBHWxGIOJShVwoX5JEx3M5SRC7xvnwW5xF5+KHCxMKB5wXEfQRpZUBX+KKCBn5PP0U21QjHhUbYhy8k85QEaL+LWOX6BqZikBw/5QaZijNYvhCtZbQs="
|
|
13
|
+
gem: fluent-plugin-ecs-filter
|
|
14
|
+
on:
|
|
15
|
+
repo: joshughes/fluent-plugin-ecs-filter
|
|
16
|
+
branch: master
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#Mesosphere Fluentd Filter
|
|
2
|
+
[](https://codeclimate.com/github/joshughes/fluent-plugin-ecs-filter)
|
|
3
|
+
[](https://codeclimate.com/github/joshughes/fluent-plugin-ecs-filter/coverage)
|
|
4
|
+
[](https://badge.fury.io/rb/fluent-plugin-ecs-filter)
|
|
5
|
+
[](http://inch-ci.org/github/joshughes/fluent-plugin-ecs-filter)
|
|
6
|
+
[](https://www.versioneye.com/user/projects/5658d10aaef3b5003e000000)
|
|
7
|
+
|
|
8
|
+
Marathon, Chronos and Mesos combined can allow for teams to build a great solution for deploying and scaling containers. The issue is when you have a system like Kibana it can be hard to identify what container or task a log is coming from.
|
|
9
|
+
|
|
10
|
+
This filter aims to solve that issue by inspecting containers to inject Mesosphere metatdata into the Fluentd event stream.
|
|
11
|
+
|
|
12
|
+
##What gets injected?
|
|
13
|
+
###Marathon
|
|
14
|
+
|
|
15
|
+
|`key`| Description |
|
|
16
|
+
|---|---|
|
|
17
|
+
|`app`| The application name in marathon |
|
|
18
|
+
| `mesos_framework` | marathon |
|
|
19
|
+
| `mesos_task_id` | The unique Mesos task id running the docker container |
|
|
20
|
+
|
|
21
|
+
###Chronos
|
|
22
|
+
Chronos does not have the idea of an 'application'. Just jobs. We run a lot of jobs that relate to our applications so we use a naming scheme that allows us to extract the marathon application that is running the Chronos task.
|
|
23
|
+
|
|
24
|
+
An example of a Chronos Job name is the following.
|
|
25
|
+
|
|
26
|
+
`some-task-app2-11182015-1718-deployTasks-1-144786721`
|
|
27
|
+
|
|
28
|
+
With the default regex in the plugin we extract the following data and inject it into the event stream.
|
|
29
|
+
|
|
30
|
+
|`key`| Description | Value |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
|`app`| The application name running the task | some-task-app2 |
|
|
33
|
+
| `mesos_framework` | chronos | chronos |
|
|
34
|
+
| `mesos_task_id` | The unique Mesos task id running the docker container | |
|
|
35
|
+
| `chronos_task_type` | The task type our application is running. We run deployment and scheduled tasks. | deployTasks |
|
|
36
|
+
|
|
37
|
+
##Configuration
|
|
38
|
+
|
|
39
|
+
If your using the docker fluentd logging plugin your configuration should look something like this.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
<source>
|
|
45
|
+
type forward
|
|
46
|
+
port 24224
|
|
47
|
+
bind 0.0.0.0
|
|
48
|
+
</source>
|
|
49
|
+
|
|
50
|
+
<filter docker.*>
|
|
51
|
+
type mesosphere_filter
|
|
52
|
+
cache_size 1000
|
|
53
|
+
cache_ttl 3600
|
|
54
|
+
merge_json_log true
|
|
55
|
+
cronos_task_regex (?<app>[a-z0-9]([-a-z0-9]*[a-z0-9]))-(?<date>[^-]+)-(?<time>[^-]+)-(?<task_type>[^-]+)-(?<run>[^-]+)-(?<epoc>[^-]+)
|
|
56
|
+
</filter>
|
|
57
|
+
|
|
58
|
+
<match docker.*>
|
|
59
|
+
type stdout
|
|
60
|
+
</match>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
|`key`| Description | Default |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
|`cache_size`| This plugin will cache information from the docker daemon. This configuration determine how large that cache is. | 1000 |
|
|
66
|
+
| `cache_ttl ` | How long to keep items in the cache. | 3600 |
|
|
67
|
+
| `merge_json_log ` | If your application logs in a valid json format, this will merge that into the event stream. | true |
|
|
68
|
+
| `cronos_task_regex ` | If you don't provide a valid regex here then you will only get the mesos_task id from until you create a standard chronos job name that is parseable by a ruby regex. | **See example above** |
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
##Example
|
|
72
|
+
We have an application called `hello-world`. That application is deployed via marathon and has the following environment variables.
|
|
73
|
+
|
|
74
|
+
|`key`| value |
|
|
75
|
+
|---|---|
|
|
76
|
+
| `MESOS_TASK_ID` | `hello-world.14b0596d-93ea-11e5-a134-124eefe69197`|
|
|
77
|
+
| `MARATHON_APP_ID` | `/hello-world`|
|
|
78
|
+
|
|
79
|
+
Like all great hello world applications. This docker container just execute:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
echo '{"say":"Hello World"}'
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Without this filter fluentd would process the docker log and output the following.
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"container_id": "ce327cb0de115f7dbfcd2c6055ba945436dada26035a62587b951332a028a530",
|
|
90
|
+
"container_name": "/some_random_meaningless_name",
|
|
91
|
+
"source": "stdout",
|
|
92
|
+
"log": "{\"say\":\"Hello World\"}\r"
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
With the filter in place that log will become the following.
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"container_id": "ce327cb0de115f7dbfcd2c6055ba945436dada26035a62587b951332a028a530",
|
|
101
|
+
"container_name": "/some_random_meaningless_name",
|
|
102
|
+
"say": "Hello World",
|
|
103
|
+
"mesos_framework": "marathon",
|
|
104
|
+
"app": "hello-world",
|
|
105
|
+
"mesos_task_id": "unquie_task_id",
|
|
106
|
+
"source": "stdout",
|
|
107
|
+
"log": "{\"say\":\"Hello World\"}\r"
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
So now in Kibana you can filter on many more fields and more easily track down issues when `hello-world` may be running in multiple containers that are associated with different Mesos tasks.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |gem|
|
|
6
|
+
gem.name = 'fluent-plugin-ecs-filter'
|
|
7
|
+
gem.version = '0.1.0'
|
|
8
|
+
gem.authors = ['Joseph Hughes']
|
|
9
|
+
gem.email = ['jjhughes57@gmail.com']
|
|
10
|
+
gem.description = 'Filter plugin to add AWS ECS metadata'
|
|
11
|
+
gem.summary = 'Filter plugin to add AWS ECS metadata to fluentd'
|
|
12
|
+
gem.homepage = 'https://github.com/joshughes/fluent-plugin-ecs-filter'
|
|
13
|
+
gem.license = 'ASL2'
|
|
14
|
+
|
|
15
|
+
gem.files = `git ls-files`.split($RS)
|
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
18
|
+
gem.require_paths = ['lib']
|
|
19
|
+
gem.has_rdoc = false
|
|
20
|
+
|
|
21
|
+
gem.required_ruby_version = '>= 2.0.0'
|
|
22
|
+
|
|
23
|
+
gem.add_runtime_dependency 'fluentd', '>= 0.10.43'
|
|
24
|
+
gem.add_runtime_dependency 'lru_redux', '~> 1.1'
|
|
25
|
+
gem.add_runtime_dependency 'docker-api', '~> 1.28'
|
|
26
|
+
gem.add_runtime_dependency 'oj', '>= 2.15.1'
|
|
27
|
+
|
|
28
|
+
gem.add_development_dependency 'bundler'
|
|
29
|
+
gem.add_development_dependency 'codeclimate-test-reporter'
|
|
30
|
+
gem.add_development_dependency 'rake'
|
|
31
|
+
gem.add_development_dependency 'webmock'
|
|
32
|
+
gem.add_development_dependency 'pry'
|
|
33
|
+
gem.add_development_dependency 'timecop'
|
|
34
|
+
gem.add_development_dependency 'simplecov'
|
|
35
|
+
gem.add_development_dependency 'minitest', '~> 4.0'
|
|
36
|
+
end
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Fluentd ECS Metadata Filter Plugin
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2015 Red Hat, Inc.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
module Fluent
|
|
19
|
+
# Parses ECS data from docker to make fluentd logs more
|
|
20
|
+
# useful.
|
|
21
|
+
class ECSFilter < Filter
|
|
22
|
+
Fluent::Plugin.register_filter('ecs_filter', self)
|
|
23
|
+
|
|
24
|
+
config_param :cache_size, :integer, default: 1000
|
|
25
|
+
config_param :cache_ttl, :integer, default: 60 * 60
|
|
26
|
+
config_param :container_id_attr, :string, default: 'container_id'
|
|
27
|
+
|
|
28
|
+
config_param :merge_json_log, :bool, default: true
|
|
29
|
+
|
|
30
|
+
# Get the configuration for the plugin
|
|
31
|
+
def configure(conf)
|
|
32
|
+
super
|
|
33
|
+
|
|
34
|
+
require 'docker-api'
|
|
35
|
+
require 'lru_redux'
|
|
36
|
+
require 'oj'
|
|
37
|
+
require 'time'
|
|
38
|
+
|
|
39
|
+
@cache_ttl = :none if @cache_ttl < 0
|
|
40
|
+
|
|
41
|
+
@cache = LruRedux::TTL::ThreadSafeCache.new(@cache_size, @cache_ttl)
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Gets the log event stream and moifies it. This is where the plugin hooks
|
|
46
|
+
# into the fluentd envent stream.
|
|
47
|
+
def filter_stream(tag, es)
|
|
48
|
+
new_es = MultiEventStream.new
|
|
49
|
+
|
|
50
|
+
container_id = get_container_id_from_tag(tag)
|
|
51
|
+
|
|
52
|
+
es.each do |time, record|
|
|
53
|
+
container_id =
|
|
54
|
+
get_container_id_from_record(record) if container_id.empty?
|
|
55
|
+
next unless container_id
|
|
56
|
+
new_es.add(time, modify_record(record, get_ecs_data(container_id)))
|
|
57
|
+
end
|
|
58
|
+
new_es
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Injects the ecs data into the record and also merges
|
|
62
|
+
# the json log if that configuration is enabled.
|
|
63
|
+
#
|
|
64
|
+
# ==== Attributes:
|
|
65
|
+
# * +record+ - The log record being processed
|
|
66
|
+
# * +ecs_data+ - The ecs data retrived from the docker container
|
|
67
|
+
#
|
|
68
|
+
# ==== Returns:
|
|
69
|
+
# * A record hash that has ecs data and optinally log data added
|
|
70
|
+
def modify_record(record, ecs_data)
|
|
71
|
+
modified_record = record.merge(ecs_data)
|
|
72
|
+
modified_record = merge_json_log(modified_record) if @merge_json_log
|
|
73
|
+
modified_record
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Gets the ecs data about a container from the cache or calls the Docker
|
|
77
|
+
# api to retrieve the data about the container and store it in the cache.
|
|
78
|
+
#
|
|
79
|
+
# ==== Attributes:
|
|
80
|
+
# * +container_id+ - The container_id where the log record originated from.
|
|
81
|
+
# ==== Returns:
|
|
82
|
+
# * A hash of data that describes a ecs task
|
|
83
|
+
def get_ecs_data(container_id)
|
|
84
|
+
@cache.getset(container_id) do
|
|
85
|
+
get_container_metadata(container_id)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Goes out to docker container to pull ecs data from labels.
|
|
90
|
+
#
|
|
91
|
+
# ==== Attributes:
|
|
92
|
+
# * +id+ - The id of the container to look at for ecs metadata.
|
|
93
|
+
# ==== Returns:
|
|
94
|
+
# * A hash that describes a ecs task gathered from the Docker API
|
|
95
|
+
def get_container_metadata(id)
|
|
96
|
+
task_data = {}
|
|
97
|
+
container = Docker::Container.get(id)
|
|
98
|
+
if container
|
|
99
|
+
labels = container.json['Config']['Labels']
|
|
100
|
+
task_data['task_family'] = labels['com.amazonaws.ecs.task-definition-family']
|
|
101
|
+
task_data['task_version'] = labels['com.amazonaws.ecs.task-definition-version']
|
|
102
|
+
task_data['task_id'] = labels['com.amazonaws.ecs.task-arn'].split('/').last
|
|
103
|
+
end
|
|
104
|
+
task_data
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Gets the container id from the last element in the tag. If the user has
|
|
108
|
+
# configured container_id_attr the container id can be gathered from the
|
|
109
|
+
# record if it has been inserted there.
|
|
110
|
+
#
|
|
111
|
+
# ==== Attributes:
|
|
112
|
+
# * +tag+ - The tag of the log being processed
|
|
113
|
+
# ==== Returns:
|
|
114
|
+
# * A docker container id
|
|
115
|
+
def get_container_id_from_tag(tag)
|
|
116
|
+
tag.split('.').last
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# If the user has configured container_id_attr the container id can be
|
|
120
|
+
# gathered from the record if it has been inserted there. If no container_id
|
|
121
|
+
# can be found, the record is not processed.
|
|
122
|
+
#
|
|
123
|
+
# ==== Attributes::
|
|
124
|
+
# * +record+ - The record that is being transformed by the filter
|
|
125
|
+
# ==== Returns:
|
|
126
|
+
# * A docker container id
|
|
127
|
+
def get_container_id_from_record(record)
|
|
128
|
+
record[@container_id_attr]
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Look at the log value and if it is valid json then we will parse the json
|
|
132
|
+
# and merge it into the log record. If a namespace is present then the log
|
|
133
|
+
# record is placed under that key.
|
|
134
|
+
# ==== Attributes:
|
|
135
|
+
# * +record+ - The record we are transforming in the fluentd event stream.
|
|
136
|
+
# ==== Examples
|
|
137
|
+
# # Docker captures stdout and passes it in the 'log' record attribute.
|
|
138
|
+
# # We try to discover is the value of 'log' is json, if it is then we
|
|
139
|
+
# # will parse the json and add the keys and values to the record.
|
|
140
|
+
# ==== Returns:
|
|
141
|
+
# * A record hash that has json log data merged into the record
|
|
142
|
+
def merge_json_log(record)
|
|
143
|
+
if record.key?('log')
|
|
144
|
+
log = record['log'].strip
|
|
145
|
+
namespace = record['namespace']
|
|
146
|
+
if log[0].eql?('{') && log[-1].eql?('}')
|
|
147
|
+
begin
|
|
148
|
+
log_json = Oj.load(log)
|
|
149
|
+
if namespace
|
|
150
|
+
record[namespace] = log_json
|
|
151
|
+
else
|
|
152
|
+
record = log_json.merge(record)
|
|
153
|
+
end
|
|
154
|
+
rescue Oj::ParseError
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
record
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Id": "foobar123",
|
|
3
|
+
"Created": "2015-11-26T06:57:56.560006039Z",
|
|
4
|
+
"Path": "/bin/sh",
|
|
5
|
+
"Args": [
|
|
6
|
+
"-c",
|
|
7
|
+
"exec fluentd -c /fluentd/etc/$FLUENTD_CONF -p /fluentd/plugins $FLUENTD_OPT"
|
|
8
|
+
],
|
|
9
|
+
"State": {
|
|
10
|
+
"Status": "running",
|
|
11
|
+
"Running": true,
|
|
12
|
+
"Paused": false,
|
|
13
|
+
"Restarting": false,
|
|
14
|
+
"OOMKilled": false,
|
|
15
|
+
"Dead": false,
|
|
16
|
+
"Pid": 6563,
|
|
17
|
+
"ExitCode": 0,
|
|
18
|
+
"Error": "",
|
|
19
|
+
"StartedAt": "2015-11-26T07:00:45.707356204Z",
|
|
20
|
+
"FinishedAt": "2015-11-26T07:00:43.278299772Z"
|
|
21
|
+
},
|
|
22
|
+
"Image": "7cd5efd43c5097c8e6a9b6bdc050f887e0e1dee49a79b7eb920e2d741c36b3b5",
|
|
23
|
+
"ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/110e3bd749e33e3b55bb55bec44a192457d722607afb1e6423e6a45a1c1e8b45/resolv.conf",
|
|
24
|
+
"HostnamePath": "/mnt/sda1/var/lib/docker/containers/110e3bd749e33e3b55bb55bec44a192457d722607afb1e6423e6a45a1c1e8b45/hostname",
|
|
25
|
+
"HostsPath": "/mnt/sda1/var/lib/docker/containers/110e3bd749e33e3b55bb55bec44a192457d722607afb1e6423e6a45a1c1e8b45/hosts",
|
|
26
|
+
"LogPath": "/mnt/sda1/var/lib/docker/containers/110e3bd749e33e3b55bb55bec44a192457d722607afb1e6423e6a45a1c1e8b45/110e3bd749e33e3b55bb55bec44a192457d722607afb1e6423e6a45a1c1e8b45-json.log",
|
|
27
|
+
"Name": "/fluentddockertest_fluentd_server_1",
|
|
28
|
+
"RestartCount": 0,
|
|
29
|
+
"Driver": "aufs",
|
|
30
|
+
"ExecDriver": "native-0.2",
|
|
31
|
+
"MountLabel": "",
|
|
32
|
+
"ProcessLabel": "",
|
|
33
|
+
"AppArmorProfile": "",
|
|
34
|
+
"ExecIDs": null,
|
|
35
|
+
"HostConfig": {
|
|
36
|
+
"Binds": [
|
|
37
|
+
"/Users/A658307/fluentd_docker_test/fluentd/etc:/fluentd/etc:rw",
|
|
38
|
+
"/Users/A658307/fluentd_docker_test/fluentd/logs:/fluentd/log:rw",
|
|
39
|
+
"/Users/A658307/fluentd_docker_test/fluentd/plugins:/fluentd/plugins:rw"
|
|
40
|
+
],
|
|
41
|
+
"ContainerIDFile": "",
|
|
42
|
+
"LxcConf": null,
|
|
43
|
+
"Memory": 0,
|
|
44
|
+
"MemoryReservation": 0,
|
|
45
|
+
"MemorySwap": 0,
|
|
46
|
+
"KernelMemory": 0,
|
|
47
|
+
"CpuShares": 0,
|
|
48
|
+
"CpuPeriod": 0,
|
|
49
|
+
"CpusetCpus": "",
|
|
50
|
+
"CpusetMems": "",
|
|
51
|
+
"CpuQuota": 0,
|
|
52
|
+
"BlkioWeight": 0,
|
|
53
|
+
"OomKillDisable": false,
|
|
54
|
+
"MemorySwappiness": null,
|
|
55
|
+
"Privileged": false,
|
|
56
|
+
"PortBindings": {
|
|
57
|
+
"24224/tcp": [{
|
|
58
|
+
"HostIp": "",
|
|
59
|
+
"HostPort": "24224"
|
|
60
|
+
}]
|
|
61
|
+
},
|
|
62
|
+
"Links": null,
|
|
63
|
+
"PublishAllPorts": false,
|
|
64
|
+
"Dns": null,
|
|
65
|
+
"DnsOptions": null,
|
|
66
|
+
"DnsSearch": null,
|
|
67
|
+
"ExtraHosts": [],
|
|
68
|
+
"VolumesFrom": [],
|
|
69
|
+
"Devices": null,
|
|
70
|
+
"NetworkMode": "default",
|
|
71
|
+
"IpcMode": "",
|
|
72
|
+
"PidMode": "",
|
|
73
|
+
"UTSMode": "",
|
|
74
|
+
"CapAdd": null,
|
|
75
|
+
"CapDrop": null,
|
|
76
|
+
"GroupAdd": null,
|
|
77
|
+
"RestartPolicy": {
|
|
78
|
+
"Name": "",
|
|
79
|
+
"MaximumRetryCount": 0
|
|
80
|
+
},
|
|
81
|
+
"SecurityOpt": null,
|
|
82
|
+
"ReadonlyRootfs": false,
|
|
83
|
+
"Ulimits": null,
|
|
84
|
+
"LogConfig": {
|
|
85
|
+
"Type": "json-file",
|
|
86
|
+
"Config": {}
|
|
87
|
+
},
|
|
88
|
+
"CgroupParent": "",
|
|
89
|
+
"ConsoleSize": [
|
|
90
|
+
0,
|
|
91
|
+
0
|
|
92
|
+
],
|
|
93
|
+
"VolumeDriver": ""
|
|
94
|
+
},
|
|
95
|
+
"GraphDriver": {
|
|
96
|
+
"Name": "aufs",
|
|
97
|
+
"Data": null
|
|
98
|
+
},
|
|
99
|
+
"Volumes": {
|
|
100
|
+
"/fluentd/etc": "/Users/A658307/fluentd_docker_test/fluentd/etc",
|
|
101
|
+
"/fluentd/log": "/Users/A658307/fluentd_docker_test/fluentd/logs",
|
|
102
|
+
"/fluentd/plugins": "/Users/A658307/fluentd_docker_test/fluentd/plugins"
|
|
103
|
+
},
|
|
104
|
+
"VolumesRW": {
|
|
105
|
+
"/fluentd/etc": true,
|
|
106
|
+
"/fluentd/log": true,
|
|
107
|
+
"/fluentd/plugins": true
|
|
108
|
+
},
|
|
109
|
+
"Config": {
|
|
110
|
+
"Hostname": "110e3bd749e3",
|
|
111
|
+
"Domainname": "",
|
|
112
|
+
"User": "ubuntu",
|
|
113
|
+
"AttachStdin": false,
|
|
114
|
+
"AttachStdout": false,
|
|
115
|
+
"AttachStderr": false,
|
|
116
|
+
"Tty": false,
|
|
117
|
+
"OpenStdin": false,
|
|
118
|
+
"StdinOnce": false,
|
|
119
|
+
"Env": [
|
|
120
|
+
"FLUENTD_OPT=-vv",
|
|
121
|
+
"MESOS_TASK_ID=hello-world.14b0596d-93ea-11e5-a134-124eefe69197",
|
|
122
|
+
"MARATHON_APP_ID=/hello-world",
|
|
123
|
+
"FLUENTD_CONF=test.conf",
|
|
124
|
+
"PATH=/home/ubuntu/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
|
125
|
+
"FLUENTD_OPT=",
|
|
126
|
+
"NAMESPACE=ns"
|
|
127
|
+
],
|
|
128
|
+
"Cmd": [
|
|
129
|
+
"/bin/sh",
|
|
130
|
+
"-c",
|
|
131
|
+
"exec fluentd -c /fluentd/etc/$FLUENTD_CONF -p /fluentd/plugins $FLUENTD_OPT"
|
|
132
|
+
],
|
|
133
|
+
"Image": "fluent/fluentd:latest",
|
|
134
|
+
"Volumes": {
|
|
135
|
+
"/fluentd/etc": {},
|
|
136
|
+
"/fluentd/log": {},
|
|
137
|
+
"/fluentd/plugins": {}
|
|
138
|
+
},
|
|
139
|
+
"WorkingDir": "/home/ubuntu",
|
|
140
|
+
"Entrypoint": null,
|
|
141
|
+
"OnBuild": null,
|
|
142
|
+
"Labels": {
|
|
143
|
+
"com.amazonaws.ecs.container-name" :"unifi-video",
|
|
144
|
+
"com.amazonaws.ecs.task-arn" : "arn:aws:ecs:us-west-2:111600242540:task/fdb86b4f-b919-4a65-89eb-4b3761eb8952",
|
|
145
|
+
"com.amazonaws.ecs.task-definition-family" : "unifi-video",
|
|
146
|
+
"com.amazonaws.ecs.task-definition-version" :"9",
|
|
147
|
+
"Description": "Fluentd docker image",
|
|
148
|
+
"Vendor": "Fluent Organization",
|
|
149
|
+
"Version": "1.0",
|
|
150
|
+
"com.docker.compose.config-hash": "7a03ce1e88388255c166fa62dcad89a43d43034ce605265094cf9c9951dcc9f0",
|
|
151
|
+
"com.docker.compose.container-number": "1",
|
|
152
|
+
"com.docker.compose.oneoff": "False",
|
|
153
|
+
"com.docker.compose.project": "fluentddockertest",
|
|
154
|
+
"com.docker.compose.service": "fluentd_server",
|
|
155
|
+
"com.docker.compose.version": "1.5.1"
|
|
156
|
+
},
|
|
157
|
+
"MacAddress": "",
|
|
158
|
+
"NetworkDisabled": false,
|
|
159
|
+
"ExposedPorts": {
|
|
160
|
+
"24224/tcp": {}
|
|
161
|
+
},
|
|
162
|
+
"VolumeDriver": "",
|
|
163
|
+
"Memory": 0,
|
|
164
|
+
"MemorySwap": 0,
|
|
165
|
+
"CpuShares": 0,
|
|
166
|
+
"Cpuset": ""
|
|
167
|
+
},
|
|
168
|
+
"NetworkSettings": {
|
|
169
|
+
"Bridge": "",
|
|
170
|
+
"SandboxID": "f304aa3b0e20fe1e0edb5984aedd03b7d5df999ff5ff9bd3ef8f831923e5f96a",
|
|
171
|
+
"HairpinMode": false,
|
|
172
|
+
"LinkLocalIPv6Address": "",
|
|
173
|
+
"LinkLocalIPv6PrefixLen": 0,
|
|
174
|
+
"Ports": {
|
|
175
|
+
"24224/tcp": [{
|
|
176
|
+
"HostIp": "0.0.0.0",
|
|
177
|
+
"HostPort": "24224"
|
|
178
|
+
}]
|
|
179
|
+
},
|
|
180
|
+
"SandboxKey": "/var/run/docker/netns/f304aa3b0e20",
|
|
181
|
+
"SecondaryIPAddresses": null,
|
|
182
|
+
"SecondaryIPv6Addresses": null,
|
|
183
|
+
"EndpointID": "7c6889977686db7c2b2042798b021a03df61c4273dcfd84fb2a9e5830fcb71a9",
|
|
184
|
+
"Gateway": "172.17.0.1",
|
|
185
|
+
"GlobalIPv6Address": "",
|
|
186
|
+
"GlobalIPv6PrefixLen": 0,
|
|
187
|
+
"IPAddress": "172.17.0.2",
|
|
188
|
+
"IPPrefixLen": 16,
|
|
189
|
+
"IPv6Gateway": "",
|
|
190
|
+
"MacAddress": "02:42:ac:11:00:02"
|
|
191
|
+
}
|
|
192
|
+
}
|
data/test/helper.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require "simplecov"
|
|
2
|
+
SimpleCov.start
|
|
3
|
+
require "codeclimate-test-reporter"
|
|
4
|
+
CodeClimate::TestReporter.start
|
|
5
|
+
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require 'bundler'
|
|
8
|
+
require 'docker'
|
|
9
|
+
require 'timecop'
|
|
10
|
+
begin
|
|
11
|
+
Bundler.setup(:default, :development)
|
|
12
|
+
rescue Bundler::BundlerError => e
|
|
13
|
+
$stderr.puts e.message
|
|
14
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
|
15
|
+
exit e.status_code
|
|
16
|
+
end
|
|
17
|
+
require 'test/unit'
|
|
18
|
+
require 'pry'
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
require "simplecov"
|
|
22
|
+
require "codeclimate-test-reporter"
|
|
23
|
+
if ENV['CIRCLE_ARTIFACTS']
|
|
24
|
+
dir = File.join("..", "..", "..", ENV['CIRCLE_ARTIFACTS'], "coverage")
|
|
25
|
+
SimpleCov.coverage_dir(dir)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
31
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
32
|
+
require 'fluent/test'
|
|
33
|
+
require 'webmock/test_unit'
|
|
34
|
+
WebMock.disable_net_connect!(:allow => "codeclimate.com")
|
|
35
|
+
|
|
36
|
+
if ENV.has_key?('VERBOSE')
|
|
37
|
+
$log = Fluent::Log.new(Fluent::Test::DummyLogDevice.new, Fluent::Log::LEVEL_TRACE)
|
|
38
|
+
else
|
|
39
|
+
nulllogger = Object.new
|
|
40
|
+
nulllogger.instance_eval {|obj|
|
|
41
|
+
def method_missing(method, *args)
|
|
42
|
+
# pass
|
|
43
|
+
end
|
|
44
|
+
}
|
|
45
|
+
$log = nulllogger
|
|
46
|
+
end
|
|
47
|
+
Docker.url = 'tcp://example.com:5422'
|
|
48
|
+
require 'fluent/plugin/filter_ecs_filter'
|
|
49
|
+
|
|
50
|
+
class Test::Unit::TestCase
|
|
51
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
|
|
3
|
+
class ECSFilterTest < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
unless defined?(Fluent::Filter)
|
|
6
|
+
omit('Fluent::Filter is not defined. Use fluentd 0.12 or later.')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
Fluent::Test.setup
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# config_param :ratio, :float
|
|
13
|
+
# config_param :key_names, :string, :default => nil
|
|
14
|
+
# config_param :key_pattern, :string, :default => nil
|
|
15
|
+
# config_param :floor, :bool, :default => false
|
|
16
|
+
# config_param :remove_prefix, :string, :default => nil
|
|
17
|
+
# config_param :add_prefix, :string, :default => nil
|
|
18
|
+
|
|
19
|
+
CONFIG = %[]
|
|
20
|
+
CONFIG2 = %[
|
|
21
|
+
cache_size 2000
|
|
22
|
+
cache_ttl 300
|
|
23
|
+
]
|
|
24
|
+
CONFIG3 = %[
|
|
25
|
+
get_container_id_tag true
|
|
26
|
+
container_id_attr container_id
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
def create_driver(conf = CONFIG, tag = 'test')
|
|
30
|
+
Fluent::Test::FilterTestDriver.new(Fluent::ECSFilter, tag).configure(conf)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def setup_docker_stub(file, docker_api_url)
|
|
34
|
+
stub_request(:get, docker_api_url)
|
|
35
|
+
.to_return(status: 200, body: file, headers: {})
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def setup_ecs_container(container_id, file_name)
|
|
39
|
+
docker_api_url = "http://tcp//example.com:5422/v1.16/containers/#{container_id}/json"
|
|
40
|
+
file = File.open("test/containers/#{file_name}.json", 'rb')
|
|
41
|
+
setup_docker_stub(file, docker_api_url)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_ecs_filter
|
|
46
|
+
setup_ecs_container('foobar123', 'ecs')
|
|
47
|
+
|
|
48
|
+
d1 = create_driver(CONFIG, 'docker.foobar123')
|
|
49
|
+
d1.run do
|
|
50
|
+
d1.filter('log' => 'Hello World 1')
|
|
51
|
+
end
|
|
52
|
+
filtered = d1.filtered_as_array
|
|
53
|
+
|
|
54
|
+
task_id = 'fdb86b4f-b919-4a65-89eb-4b3761eb8952'
|
|
55
|
+
|
|
56
|
+
log_entry = filtered[0][2]
|
|
57
|
+
|
|
58
|
+
assert_equal 'unifi-video', log_entry['task_family']
|
|
59
|
+
assert_equal '9', log_entry['task_version']
|
|
60
|
+
assert_equal task_id, log_entry['task_id']
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_container_cache
|
|
64
|
+
setup_ecs_container('foobar123', 'ecs')
|
|
65
|
+
|
|
66
|
+
d1 = create_driver(CONFIG, 'docker.foobar123')
|
|
67
|
+
d1.run do
|
|
68
|
+
1000.times do
|
|
69
|
+
d1.filter('log' => 'Hello World 4')
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
docker_api_url = 'http://tcp//example.com:5422/v1.16/containers/foobar123/json'
|
|
73
|
+
|
|
74
|
+
assert_equal 1000, d1.filtered_as_array.length
|
|
75
|
+
assert_requested(:get, docker_api_url, times: 2)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_container_cache_expiration
|
|
79
|
+
setup_ecs_container('foobar123', 'ecs')
|
|
80
|
+
|
|
81
|
+
d1 = create_driver(CONFIG2, 'docker.foobar123')
|
|
82
|
+
d1.run do
|
|
83
|
+
d1.filter('log' => 'Hello World 4')
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
Timecop.travel(Time.now + 10 * 60)
|
|
87
|
+
|
|
88
|
+
d1.run do
|
|
89
|
+
d1.filter('log' => 'Hello World 4')
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
Timecop.return
|
|
93
|
+
|
|
94
|
+
docker_api_url = 'http://tcp//example.com:5422/v1.16/containers/foobar123/json'
|
|
95
|
+
|
|
96
|
+
assert_requested(:get, docker_api_url, times: 4)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_merge_json
|
|
100
|
+
setup_ecs_container('foobar123', 'ecs')
|
|
101
|
+
|
|
102
|
+
d1 = create_driver(CONFIG, 'docker.foobar123')
|
|
103
|
+
d1.run do
|
|
104
|
+
d1.filter('log' => '{"test_key":"Hello World"}')
|
|
105
|
+
end
|
|
106
|
+
filtered = d1.filtered_as_array
|
|
107
|
+
log_entry = filtered[0][2]
|
|
108
|
+
|
|
109
|
+
assert_equal 'Hello World', log_entry['test_key']
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def test_bad_merge_json
|
|
113
|
+
setup_ecs_container('foobar123', 'ecs')
|
|
114
|
+
bad_json1 = '{"test_key":"Hello World"'
|
|
115
|
+
bad_json2 = '{"test_key":"Hello World", "badnews"}'
|
|
116
|
+
|
|
117
|
+
d1 = create_driver(CONFIG, 'docker.foobar123')
|
|
118
|
+
d1.run do
|
|
119
|
+
d1.filter('log' => bad_json1)
|
|
120
|
+
d1.filter('log' => bad_json2)
|
|
121
|
+
end
|
|
122
|
+
filtered = d1.filtered_as_array
|
|
123
|
+
|
|
124
|
+
assert_equal bad_json1, filtered[0][2]['log']
|
|
125
|
+
assert_equal bad_json2, filtered[1][2]['log']
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fluent-plugin-ecs-filter
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Joseph Hughes
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-05-27 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: fluentd
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ! '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.10.43
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ! '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.10.43
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: lru_redux
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.1'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ~>
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.1'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: docker-api
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ~>
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.28'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ~>
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.28'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: oj
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 2.15.1
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ! '>='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 2.15.1
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: bundler
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ! '>='
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ! '>='
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: codeclimate-test-reporter
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ! '>='
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ! '>='
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rake
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ! '>='
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ! '>='
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: webmock
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ! '>='
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ! '>='
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: pry
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ! '>='
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ! '>='
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: timecop
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - ! '>='
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '0'
|
|
146
|
+
type: :development
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ! '>='
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: simplecov
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ! '>='
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '0'
|
|
160
|
+
type: :development
|
|
161
|
+
prerelease: false
|
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - ! '>='
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: '0'
|
|
167
|
+
- !ruby/object:Gem::Dependency
|
|
168
|
+
name: minitest
|
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
|
170
|
+
requirements:
|
|
171
|
+
- - ~>
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: '4.0'
|
|
174
|
+
type: :development
|
|
175
|
+
prerelease: false
|
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
177
|
+
requirements:
|
|
178
|
+
- - ~>
|
|
179
|
+
- !ruby/object:Gem::Version
|
|
180
|
+
version: '4.0'
|
|
181
|
+
description: Filter plugin to add AWS ECS metadata
|
|
182
|
+
email:
|
|
183
|
+
- jjhughes57@gmail.com
|
|
184
|
+
executables: []
|
|
185
|
+
extensions: []
|
|
186
|
+
extra_rdoc_files: []
|
|
187
|
+
files:
|
|
188
|
+
- .gitignore
|
|
189
|
+
- .ruby-version
|
|
190
|
+
- .travis.yml
|
|
191
|
+
- Gemfile
|
|
192
|
+
- LICENSE.txt
|
|
193
|
+
- README.md
|
|
194
|
+
- Rakefile
|
|
195
|
+
- fluent-plugin-ecs-filter.gemspec
|
|
196
|
+
- lib/fluent/plugin/filter_ecs_filter.rb
|
|
197
|
+
- test/containers/ecs.json
|
|
198
|
+
- test/helper.rb
|
|
199
|
+
- test/plugin/test_mesosphere.rb
|
|
200
|
+
homepage: https://github.com/joshughes/fluent-plugin-ecs-filter
|
|
201
|
+
licenses:
|
|
202
|
+
- ASL2
|
|
203
|
+
metadata: {}
|
|
204
|
+
post_install_message:
|
|
205
|
+
rdoc_options: []
|
|
206
|
+
require_paths:
|
|
207
|
+
- lib
|
|
208
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
|
+
requirements:
|
|
210
|
+
- - ! '>='
|
|
211
|
+
- !ruby/object:Gem::Version
|
|
212
|
+
version: 2.0.0
|
|
213
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
|
+
requirements:
|
|
215
|
+
- - ! '>='
|
|
216
|
+
- !ruby/object:Gem::Version
|
|
217
|
+
version: '0'
|
|
218
|
+
requirements: []
|
|
219
|
+
rubyforge_project:
|
|
220
|
+
rubygems_version: 2.4.5
|
|
221
|
+
signing_key:
|
|
222
|
+
specification_version: 4
|
|
223
|
+
summary: Filter plugin to add AWS ECS metadata to fluentd
|
|
224
|
+
test_files:
|
|
225
|
+
- test/containers/ecs.json
|
|
226
|
+
- test/helper.rb
|
|
227
|
+
- test/plugin/test_mesosphere.rb
|