Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.

Commit d2c3259

Browse files
authored
Merge pull request #108 from bendrucker/metadata-reduce-namespace
Polish "reduce metadata" feature
2 parents 7402b7c + 00a04f4 commit d2c3259

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ PLATFORMS
6666
ruby
6767

6868
DEPENDENCIES
69-
bundler (~> 1.3)
69+
bundler (~> 2)
7070
codecov
7171
fluent-plugin-kubernetes_sumologic!
7272
rake
@@ -75,4 +75,4 @@ DEPENDENCIES
7575
webmock
7676

7777
BUNDLED WITH
78-
1.16.3
78+
2.0.1

README.md

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Environment | Variable Description
100100
`FLUENTD_USER_CONFIG_DIR`|A directory of user-defined fluentd configuration files, which must be in the `*.conf` directory in the container.
101101
`FLUSH_INTERVAL` |How frequently to push logs to Sumo.<br/><br/>Default: `5s`
102102
`KUBERNETES_META`|Include or exclude Kubernetes metadata such as `namespace` and `pod_name` if using JSON log format. <br/><br/>Default: `true`
103-
`KUBERNETES_META_REDUCE`| Reduces Kubernetes metadata, check [Reducing Kubernetes Metadata](#####reduce-kubernetes-metadata-using-annotations). <br></br>Default: `false`
103+
`KUBERNETES_META_REDUCE`| Reduces redundant Kubernetes metadata, see [_Reducing Kubernetes Metadata_](#reducing-kubernetes-metadata). <br></br>Default: `false`
104104
`LOG_FORMAT`|Format in which to post logs to Sumo. Allowable values:<br/><br/>`text`—Logs will appear in SumoLogic in text format.<br/>`json`—Logs will appear in SumoLogic in json format.<br/>`json_merge`—Same as json but if the container logs in json format to stdout it will merge in the container json log at the root level and remove the log field.<br/><br/>Default: `json`
105105
`MULTILINE_START_REGEXP`|The regular expression for the `concat` plugin to use when merging multi-line messages. Defaults to Julian dates, for example, Jul 29, 2017.
106106
`NUM_THREADS`|Set the number of HTTP threads to Sumo. It might be necessary to do so in heavy-logging clusters. <br/><br/>Default: `1`
@@ -147,10 +147,29 @@ The following table show which environment variables affect which Fluentd sourc
147147
### FluentD stops processing logs
148148
When dealing with large volumes of data (TB's from what we have seen), FluentD may stop processing logs, but continue to run. This issue seems to be caused by the [scalability of the inotify process](https://github.com/fluent/fluentd/issues/1630) that is packaged with the FluentD in_tail plugin. If you encounter this situation, setting the `ENABLE_STAT_WATCHER` to `false` should resolve this issue.
149149

150-
### Override environment variables using annotations
151-
You can override the `LOG_FORMAT`, `KUBERNETES_META_REDUCE`, `SOURCE_CATEGORY` and `SOURCE_NAME` environment variables, per pod, using [Kubernetes annotations](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/). For example:
150+
### Reducing Kubernetes metadata
152151

153-
```
152+
You can use the `KUBERNETES_META_REDUCE` environment variable (global) or the `sumologic.com/kubernetes_meta_reduce` annotation (per pod) to reduce the amount of Kubernetes metadata included with each log line under the `kubernetes` field.
153+
154+
When set, FluentD will remove the following properties:
155+
156+
* `pod_id`
157+
* `container_id`
158+
* `namespace_id`
159+
* `master_url`
160+
* `labels`
161+
* `annotations`
162+
163+
Logs will still include:
164+
165+
* `pod_name`
166+
* `container_name`
167+
* `namespace_name`
168+
* `host`
169+
170+
These fields still allow you to uniquely identify a pod and look up additional details with the Kubernetes API.
171+
172+
```yaml
154173
apiVersion: v1
155174
kind: ReplicationController
156175
metadata:
@@ -165,10 +184,7 @@ spec:
165184
labels:
166185
app: mywebsite
167186
annotations:
168-
sumologic.com/format: "text"
169187
sumologic.com/kubernetes_meta_reduce: "true"
170-
sumologic.com/sourceCategory: "mywebsite/nginx"
171-
sumologic.com/sourceName: "mywebsite_nginx"
172188
spec:
173189
containers:
174190
- name: nginx
@@ -177,9 +193,10 @@ spec:
177193
- containerPort: 80
178194
```
179195
180-
### Reduce Kubernetes Metadata using annotations
181-
You can also use the "sumologic.com/kubernetes_meta_reduce" annotation to exclude `pod_id`,
182-
`container_id`, `namespace_id`, `namespace_name`, `master_url` and `labels` from Kubernetes Metadata.
196+
197+
### Override environment variables using annotations
198+
You can override the `LOG_FORMAT`, `KUBERNETES_META_REDUCE`, `SOURCE_CATEGORY` and `SOURCE_NAME` environment variables, per pod, using [Kubernetes annotations](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/). For example:
199+
183200
```
184201
apiVersion: v1
185202
kind: ReplicationController
@@ -195,7 +212,10 @@ spec:
195212
labels:
196213
app: mywebsite
197214
annotations:
215+
sumologic.com/format: "text"
198216
sumologic.com/kubernetes_meta_reduce: "true"
217+
sumologic.com/sourceCategory: "mywebsite/nginx"
218+
sumologic.com/sourceName: "mywebsite_nginx"
199219
spec:
200220
containers:
201221
- name: nginx

fluent-plugin-kubernetes_sumologic.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
2020

2121
gem.required_ruby_version = '>= 2.0.0'
2222

23-
gem.add_development_dependency "bundler", "~> 1.3"
23+
gem.add_development_dependency "bundler", "~> 2"
2424
gem.add_development_dependency "rake"
2525
gem.add_development_dependency 'test-unit', '~> 3.1.0'
2626
gem.add_development_dependency "codecov", ">= 0.1.10"

lib/fluent/plugin/filter_kubernetes_sumologic.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ def filter(tag, time, record)
183183
record["kubernetes"].delete("namespace_id")
184184
record["kubernetes"].delete("labels")
185185
record["kubernetes"].delete("master_url")
186-
record["kubernetes"].delete("namespace_name")
187186
record["kubernetes"].delete("annotations")
188187
end
189188
if @add_stream == false

test/plugin/test_filter_kubernetes_sumologic.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ def create_driver(conf = CONFIG)
458458
"container_name" => "log-format-labs",
459459
"pod_name" => "log-format-labs-54575ccdb9-9d677",
460460
"host" => "docker-for-desktop",
461+
"namespace_name" => "default",
461462
},
462463
"_sumo_metadata" => {
463464
:category => "kubernetes/default/log/format/labs",
@@ -506,6 +507,7 @@ def create_driver(conf = CONFIG)
506507
"container_name" => "log-format-labs",
507508
"pod_name" => "log-format-labs-54575ccdb9-9d677",
508509
"host" => "docker-for-desktop",
510+
"namespace_name" => "default",
509511
},
510512
"_sumo_metadata" => {
511513
:category => "kubernetes/default/log/format/labs",
@@ -557,6 +559,7 @@ def create_driver(conf = CONFIG)
557559
"container_name" => "log-format-labs",
558560
"pod_name" => "log-format-labs-54575ccdb9-9d677",
559561
"host" => "docker-for-desktop",
562+
"namespace_name" => "default",
560563
},
561564
"_sumo_metadata" => {
562565
:category => "kubernetes/default/log/format/labs",

0 commit comments

Comments
 (0)