The project is in a healthy, maintained state
Fluent plugin to filter based on Kubernetes annotations
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.3
~> 3.11
~> 3.5

Runtime

~> 1.16.1, >= 1.16.1
 Project Readme

Fluentd Plugin: Kubernetes Annotation Filter

Checks whether the container name is included in an annotation on the pod that is the source of a log entry.

Development

Running Locally

It can be a bit of a challenge to get fluentd running locally for "poke-it-and-see" style testing. One approach is to:

  1. Get a docker container with fluentd in it
  2. Create an app/plugins directory
  3. Copy lib/fluent/plugin/* from this repository into that directory
  4. Create a fluentd configuration that uses this plugin, taking input from a file in the /app directory. An example configuration can be found at example/fluentd-test.conf.
  5. Run the container
  6. Put your test lines into the file
  7. Watch the output

This is not a particularly nice way to develop anything, but it does work. You'll then need to copy the modified source code back into this repository.

Tests

You can run tests locally with:

> rspec

Or in docker with:

> make test

The tests are written using Fluent's Test Driver; this requires the test-unit gem be included (for some helper methods we're not using) in addition to rspec, which is actually used to run the tests (in accordance with what all the rest of DRE's Ruby code uses).

Operations

Installation

Add the following to your Gemfile:

gem 'fluent-plugin-annotation-filter'

Dependencies

This plugin relies on Kubernetes metadata being available on log records. This metadata is provided by the Kubernetes_metadata_filter plugin.

Specifically, we rely on the following fields:

Field Content
kubernetes.container_name The name of the container the record was emitted from
kubernetes.annotations The annotations applied to the pod the record was emitted from

Configuration

An example configuration could look like:

<filter camelid>
@type kubernetes_annotation

<contains_container_name>
annotation dromedary
</contains_container_name>
</filter>

This would look for the value of kubernetes.container_name in the kubernetes.annotations.dromedary field of records tagged "camelid"; for example, these records would be allowed to pass through the filter:

{"message": "hi", "kubernetes": {"container_name": "beluga", ..., "annotations": { "dromedary": "[\"beluga\"]" } } }
{"message": "wat", "kubernetes": {"container_name": "humpback", ..., "annotations": { "dromedary": "[\"minke\", \"humpback\"]" } } }

but these ones would not:

{"message": "hi", "kubernetes": {"container_name": "pelican", ..., "annotations": { "dromedary": "[\"minke\", \"humpback\"]" } } }
{"message": "wat", "kubernetes": {"container_name": "gannet", ..., "annotations": { } } }

Note that the value of the provided annotation is expected to be a JSON array inside a string (this appears to be the way people suggest encoding data of this kind).

The pass_through_events_without_kubernetes_tags option can be used to control whether objects without Kubernetes tags are passed through the filter or dropped. It defaults to false, i.e. drop unmatched objects.

Maintainers

delivery-engineers@redbubble.com

fluentd-plugin-annotation-filter

Copyright (c) Redbubble

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.