Skip to content

Commit

Permalink
Performance and deprecation refactorings (#347)
Browse files Browse the repository at this point in the history
* fix 320. Remove de_dot functionality

* fix #343. Remove deprecated journal functionality

* fix 344. optimize cache lookup to use fluent event time

* fix 345. Remove serialization and deserialization of meta info

* fix #346. Fix dump_stats and allow configuration to disable

* add benchmark results
  • Loading branch information
jcantrill committed Jul 14, 2022
1 parent 4f79187 commit 4171b98
Show file tree
Hide file tree
Showing 27 changed files with 735 additions and 636 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -7,7 +7,6 @@ vendor/
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
Expand Down
55 changes: 3 additions & 52 deletions README.md
Expand Up @@ -7,8 +7,7 @@

The Kubernetes metadata plugin filter enriches container log records with pod and namespace metadata.

This plugin derives basic metadata about the container that emitted a given log record using the source of the log record. Records from journald provide metadata about the
container environment as named fields. Records from JSON files encode metadata about the container in the file name. The initial metadata derived from the source is used
This plugin derives basic metadata about the container that emitted a given log record using the source of the log record. Records from kubernetes containers encode metadata about the container in the file name. The initial metadata derived from the source is used
to lookup additional metadata about the container's associated pod and namespace (e.g. UUIDs, labels, annotations) when the kubernetes_url is configured. If the plugin cannot
authoritatively determine the namespace of the container emitting a log record, it will use an 'orphan' namespace ID in the metadata. This behaviors supports multi-tenant systems
that rely on the authenticity of the namespace for proper log isolation.
Expand Down Expand Up @@ -46,14 +45,6 @@ This must use named capture groups for `container_name`, `pod_name`, `namespace`
* `cache_size` - size of the cache of Kubernetes metadata to reduce requests to the API server (default: `1000`)
* `cache_ttl` - TTL in seconds of each cached element. Set to negative value to disable TTL eviction (default: `3600` - 1 hour)
* `watch` - set up a watch on pods on the API server for updates to metadata (default: `true`)
* *DEPRECATED*`de_dot` - replace dots in labels and annotations with configured `de_dot_separator`, required for Datadog and ElasticSearch 2.x compatibility (default: `true`)
* *DEPRECATED*`de_dot_separator` - separator to use if `de_dot` is enabled (default: `_`)
* *DEPRECATED*`de_slash` - replace slashes in labels and annotations with configured `de_slash_separator`, required for Datadog compatibility (default: `false`)
* *DEPRECATED*`de_slash_separator` - separator to use if `de_slash` is enabled (default: `__`)
* *DEPRECATED* `use_journal` - If false, messages are expected to be formatted and tagged as if read by the fluentd in\_tail plugin with wildcard filename. If true, messages are expected to be formatted as if read from the systemd journal. The `MESSAGE` field has the full message. The `CONTAINER_NAME` field has the encoded k8s metadata (see below). The `CONTAINER_ID_FULL` field has the full container uuid. This requires docker to use the `--log-driver=journald` log driver. If unset (the default), the plugin will use the `CONTAINER_NAME` and `CONTAINER_ID_FULL` fields
if available, otherwise, will use the tag in the `tag_to_kubernetes_name_regexp` format.
* `container_name_to_kubernetes_regexp` - The regular expression used to extract the k8s metadata encoded in the journal `CONTAINER_NAME` field default: See [code](https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter/blob/master/lib/fluent/plugin/filter_kubernetes_metadata.rb#L68)
* This corresponds to the definition [in the source](https://github.com/kubernetes/kubernetes/blob/release-1.6/pkg/kubelet/dockertools/docker.go#L317)
* `annotation_match` - Array of regular expressions matching annotation field names. Matched annotations are added to a log record.
* `allow_orphans` - Modify the namespace and namespace id to the values of `orphaned_namespace_name` and `orphaned_namespace_id`
when true (default: `true`)
Expand All @@ -67,10 +58,11 @@ when true (default: `true`)
* `skip_container_metadata` - Skip some of the container data of the metadata. The metadata will not contain the container_image and container_image_id fields.
* `skip_master_url` - Skip the master_url field from the metadata.
* `skip_namespace_metadata` - Skip the namespace_id field from the metadata. The fetch_namespace_metadata function will be skipped. The plugin will be faster and cpu consumption will be less.
* `stats_interval` - The interval to display cache stats (default: 30s). Set to 0 to disable stats collection and logging
* `watch_retry_interval` - The time interval in seconds for retry backoffs when watch connections fail. (default: `10`)


Reading from the JSON formatted log files with `in_tail` and wildcard filenames while respecting the CRI-o log format with the same config you need the fluent-plugin "multi-format-parser":
Reading from a JSON formatted log files with `in_tail` and wildcard filenames while respecting the CRI-o log format with the same config you need the fluent-plugin "multi-format-parser":

```
fluent-gem install fluent-plugin-multi-format-parser
Expand Down Expand Up @@ -111,35 +103,6 @@ The config block could look like this:
</match>
```

Reading from the systemd journal (requires the fluentd `fluent-plugin-systemd` and `systemd-journal` plugins, and requires docker to use the `--log-driver=journald` log driver):
```
<source>
@type systemd
path /run/log/journal
pos_file journal.pos
tag journal
read_from_head true
</source>
# probably want to use something like fluent-plugin-rewrite-tag-filter to
# retag entries from k8s
<match journal>
@type rewrite_tag_filter
rewriterule1 CONTAINER_NAME ^k8s_ kubernetes.journal.container
...
</match>
<filter kubernetes.**>
@type kubernetes_metadata
use_journal true
</filter>
<match **>
@type stdout
</match>
```


## Environment variables for Kubernetes

If the name of the Kubernetes node the plugin is running on is set as
Expand Down Expand Up @@ -199,18 +162,6 @@ Then output becomes as belows
}
```

If using journal input, from docker configured with `--log-driver=journald`, the input looks like the `journalctl -o export` format:
```
# The stream identification is encoded into the PRIORITY field as an
# integer: 6, or github.com/coreos/go-systemd/journal.Info, marks stdout,
# while 3, or github.com/coreos/go-systemd/journal.Err, marks stderr.
PRIORITY=6
CONTAINER_ID=b6cbb6e73c0a
CONTAINER_ID_FULL=b6cbb6e73c0ad63ab820e4baa97cdc77cec729930e38a714826764ac0491341a
CONTAINER_NAME=k8s_registry.a49f5318_docker-registry-1-hhoj0_default_ae3a9bdc-1f66-11e6-80a2-fa163e2fff3a_799e4035
MESSAGE=172.17.0.1 - - [21/May/2016:16:52:05 +0000] "GET /healthz HTTP/1.1" 200 0 "" "Go-http-client/1.1"
```

## Contributing

1. Fork it
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions doc/benchmark/5m-1-2500lps-256b-baseline-01/readme.md
@@ -0,0 +1,88 @@

# collector Functionl Benchmark Results
## Options
* Image: quay.io/openshift-logging/fluentd:1.14.6
* Total Log Stressors: 1
* Lines Per Second: 2500
* Run Duration: 5m
* Payload Source: synthetic

## Latency of logs collected based on the time the log was generated and ingested

Total Msg| Size | Elapsed (s) | Mean (s)| Min(s) | Max (s)| Median (s)
---------|------|-------------|---------|--------|--------|---
705733|256|5m0s|16.929|1.826|36.399|14.956

![](cpu.png)

![](mem.png)

![](latency.png)

![](loss.png)

## Percent logs lost between first and last collected sequence ids
Stream | Min Seq | Max Seq | Purged | Collected | Percent Collected |
-------| ---------| --------| -------|-----------|--------------|
| functional.0.0000000000000000DBCED7977B8F643F|0|716850|0|705733|98.4%


## Config

```
<system>
log_level debug
</system>
<source>
@type tail
@id container-input
path /var/log/pods/testhack-clwn63sc_*/loader-*/*
exclude_path ["/var/log/pods/**/*/*.gz","/var/log/pods/**/*/*.tmp"]
pos_file "/var/lib/fluentd/pos/containers-app"
refresh_interval 5
rotate_wait 5
tag kubernetes.*
read_from_head "true"
<parse>
@type regexp
expression /^(?<@timestamp>[^\s]+) (?<stream>stdout|stderr) (?<logtag>[F|P]) (?<message>.*)$/
time_format '%Y-%m-%dT%H:%M:%S.%N%:z'
keep_time_key true
</parse>
</source>
<filter kubernetes.**>
@type concat
key message
partial_key logtag
partial_value P
separator ''
</filter>
<match **>
@type forward
heartbeat_type none
keepalive true
<buffer>
flush_mode interval
flush_interval 5s
flush_at_shutdown true
flush_thread_count 2
retry_type exponential_backoff
retry_wait 1s
retry_max_interval 60s
retry_forever true
overflow_action block
</buffer>
<server>
host 0.0.0.0
port 24224
</server>
</match>
```

127 changes: 127 additions & 0 deletions doc/benchmark/5m-1-2500lps-256b-baseline-01/results.html
@@ -0,0 +1,127 @@

<html>
<div>
<div><b>Options</b><div>
<div>Image: quay.io/openshift-logging/fluentd:1.14.6</div>
<div>Total Log Stressors: 1</div>
<div>Lines Per Second: 2500</div>
<div>Run Duration: 5m</div>
<div>Payload Source: synthetic</div>
</div>
<div>
Latency of logs collected based on the time the log was generated and ingested
</div>
<table border="1">
<tr>
<th>Total</th>
<th>Size</th>
<th>Elapsed</th>
<th>Mean</th>
<th>Min</th>
<th>Max</th>
<th>Median</th>
</tr>
<tr>
<th>Msg</th>
<th></th>
<th>(s)</th>
<th>(s)</th>
<th>(s)</th>
<th>(s)</th>
<th>(s)</th>
</tr>
<tr>
<td>705733</td>
<td>256</td>
<td>5m0s</td>
<td>16.929</td>
<td>1.826</td>
<td>36.399</td>
<td>14.956</td>
</tr>
</table>
<div>
<img src="cpu.png">
</div>
<div>
<img src="mem.png">
</div>
<div>
<img src="latency.png">
</div>
<div>
<img src="loss.png">
</div>
<div>
<table border="1">
<tr>
<th>Stream</th>
<th>Min Seq</th>
<th>Max Seq</th>
<th>Purged</th>
<th>Collected</th>
<th>Percent Collected</th>
</tr>
<tr>
<tr><td>functional.0.0000000000000000DBCED7977B8F643F</td><td>0</td><td>716850</td><td>0</td><td>705733</td><td>98.4%</td><tr>
</table>
</div>
<div>
<code style="display:block;white-space:pre-wrap">

&lt;system&gt;
log_level debug
&lt;/system&gt;

&lt;source&gt;
@type tail
@id container-input
path /var/log/pods/testhack-clwn63sc_*/loader-*/*
exclude_path [&#34;/var/log/pods/**/*/*.gz&#34;,&#34;/var/log/pods/**/*/*.tmp&#34;]
pos_file &#34;/var/lib/fluentd/pos/containers-app&#34;
refresh_interval 5
rotate_wait 5
tag kubernetes.*
read_from_head &#34;true&#34;
&lt;parse&gt;
@type regexp
expression /^(?&lt;@timestamp&gt;[^\s]+) (?&lt;stream&gt;stdout|stderr) (?&lt;logtag&gt;[F|P]) (?&lt;message&gt;.*)$/
time_format &#39;%Y-%m-%dT%H:%M:%S.%N%:z&#39;
keep_time_key true
&lt;/parse&gt;
&lt;/source&gt;

&lt;filter kubernetes.**&gt;
@type concat
key message
partial_key logtag
partial_value P
separator &#39;&#39;
&lt;/filter&gt;

&lt;match **&gt;
@type forward
heartbeat_type none
keepalive true

&lt;buffer&gt;
flush_mode interval
flush_interval 5s
flush_at_shutdown true
flush_thread_count 2
retry_type exponential_backoff
retry_wait 1s
retry_max_interval 60s
retry_forever true
overflow_action block
&lt;/buffer&gt;

&lt;server&gt;
host 0.0.0.0
port 24224
&lt;/server&gt;
&lt;/match&gt;

</code>
</div>
</html>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4171b98

Please sign in to comment.