Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipelines: filters: ecs: Retrieve container ID from record field #1402

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion pipeline/filters/ecs-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ The plugin supports the following configuration parameters:
| Key | Description | Default |
| :--- | :--- | :--- |
| Add | This parameter is similar to the ADD option in the [modify filter](https://docs.fluentbit.io/manual/pipeline/filters/modify). You can specify it any number of times and it takes two arguments, a KEY name and VALUE. The value uses Fluent Bit [record_accessor](https://docs.fluentbit.io/manual/v/1.5/administration/configuring-fluent-bit/record-accessor) syntax to create a template that uses ECS Metadata values. See the list below for supported metadata templating keys. This option is designed to give you full power to control both the key names for metadata as well as the format for metadata values. See the examples below for more. | No default |
| ECS\_Tag\_Prefix | This parameter is similar to the Kube_Tag_Prefix option in the [Kubernetes filter](https://docs.fluentbit.io/manual/pipeline/filters/kubernetes) and performs the same function. The full log tag should be prefixed with this string and after the prefix the filter must find the next characters in the tag to be the Docker Container Short ID (the first 12 characters of the full container ID). The filter uses this to identify which container the log came from so it can find which task it is a part of. See the design section below for more information. If not specified, it defaults to empty string, meaning that the tag must be prefixed with the 12 character container short ID. If you just want to attach cluster metadata to system/OS logs from processes that do not run as part of containers or ECS Tasks, then do not set this parameter and enable the Cluster\_Metadata\_Only option | emptry string |
| ECS\_Tag\_Prefix | This parameter is similar to the Kube_Tag_Prefix option in the [Kubernetes filter](https://docs.fluentbit.io/manual/pipeline/filters/kubernetes) and performs the same function. The full log tag should be prefixed with this string and after the prefix the filter must find the next characters in the tag to be the Docker Container Short ID (the first 12 characters of the full container ID). The filter uses this to identify which container the log came from so it can find which task it is a part of. See the design section below for more information. If not specified, it defaults to empty string, meaning that the tag must be prefixed with the 12 character container short ID. If you just want to attach cluster metadata to system/OS logs from processes that do not run as part of containers or ECS Tasks, then do not set this parameter and enable the Cluster\_Metadata\_Only option | Empty string |
| Container\_Id\_Field\_Name | If set to a non-empty string, retrieves the Container Short ID from an already populated field designated by this parameter. Only the cluster metadata will be attached if the field is incorrect or holds invalid data. | Empty string |
| Cluster\_Metadata\_Only | When enabled, the plugin will only attempt to attach cluster metadata values. This is useful if you want to attach cluster metadata to system/OS logs from processes that do not run as part of containers or ECS Tasks. | Off |
| ECS\_Meta\_Cache\_TTL | The filter builds a hash table in memory mapping each unique container short ID to its metadata. This option sets a max TTL for objects in the hash table. You should set this if you have frequent container/task restarts. For example, your cluster runs short running batch jobs that complete in less than 10 minutes, there is no reason to keep any stored metadata longer than 10 minutes. So you would set this parameter to "10m". | 1h (1 hour) |

Expand Down Expand Up @@ -149,3 +150,30 @@ This examples shows a use case for the `Cluster_Metadata_Only` option- attaching
Format json_lines
```

#### Example 4: Attach task metadata using container ID field

Attaches the cluster metadata, as well as task metadata using the already populated field `container_id` containing the
container ID to query the ECS introspection endpoint. In this configuration the tag can be set to anything.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Attaches the cluster metadata, as well as task metadata using the already populated field `container_id` containing the
container ID to query the ECS introspection endpoint. In this configuration the tag can be set to anything.
Attaches the cluster metadata and task metadata using the populated `container_id`
field, which includes the container ID to query the ECS introspection endpoint. In this
configuration the tag can be set to anything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure what the referenced tag is in the last sentence. Can you provide some clarification?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggested changed!

As for the last sentence, I updated to hopefully make it clearer. To put simply, currently ECS metadata requires incoming log records to have a the tag set in a format <prefix><containerid>. Formatting the tag is no longer necessary when using Container_Id_Field_Name as the container ID is retrieved through a given field within the log record.


```text
RaJiska marked this conversation as resolved.
Show resolved Hide resolved
[INPUT]
Name forward
Listen 0.0.0.0
Port 24224

[FILTER]
Name ecs
Match *
container_id_field_name container_id
ADD ecs_cluster $ClusterName
ADD ecs_task_id $TaskID
ADD ecs_container_name $ECSContainerName
ADD ecs_task_definition_family $TaskDefinitionFamily
ADD ecs_task_id $TaskID

[OUTPUT]
Name stdout
Match *
Format json_lines
```