fluent-plugin-kubernetes_metadata_filter 2.8.1 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -1
- data/fluent-plugin-kubernetes_metadata_filter.gemspec +1 -1
- data/lib/fluent/plugin/filter_kubernetes_metadata.rb +16 -0
- data/lib/fluent/plugin/kubernetes_metadata_common.rb +8 -0
- data/test/cassettes/{kubernetes_docker_metadata_dotted_labels.yml → kubernetes_docker_metadata_dotted_slashed_labels.yml} +0 -0
- data/test/plugin/test_filter_kubernetes_metadata.rb +19 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1637f0d5dc3b0962bea8bb25f8cda869044b45fd33d27fee1ef7a58d2c403f4c
|
4
|
+
data.tar.gz: 0bf235def6a0eab1ff766617b704bd3b637403ad88d568c8d087352473a24dc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f31264c9339108f83573e9566ec2f93630afa7c64d4f00a996431925e487a5c74575603183072c10803defac132ef066ef0ec021ad37446e358cef4cad0a05e
|
7
|
+
data.tar.gz: ca81025a46a85d4e87feededf0f9ef2c8047cd3a8b84b75a71baf16feabc364ca69ce4ed69f3f796dbd1542bc602799dac53f87bbb9e7df980a99e4872c7955f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -45,8 +45,10 @@ This must used named capture groups for `container_name`, `pod_name` & `namespac
|
|
45
45
|
* `cache_size` - size of the cache of Kubernetes metadata to reduce requests to the API server (default: `1000`)
|
46
46
|
* `cache_ttl` - TTL in seconds of each cached element. Set to negative value to disable TTL eviction (default: `3600` - 1 hour)
|
47
47
|
* `watch` - set up a watch on pods on the API server for updates to metadata (default: `true`)
|
48
|
-
* `de_dot` - replace dots in labels and annotations with configured `de_dot_separator`, required for ElasticSearch 2.x compatibility (default: `true`)
|
48
|
+
* `de_dot` - replace dots in labels and annotations with configured `de_dot_separator`, required for Datadog and ElasticSearch 2.x compatibility (default: `true`)
|
49
49
|
* `de_dot_separator` - separator to use if `de_dot` is enabled (default: `_`)
|
50
|
+
* `de_slash` - replace slashes in labels and annotations with configured `de_slash_separator`, required for Datadog compatibility (default: `false`)
|
51
|
+
* `de_slash_separator` - separator to use if `de_slash` is enabled (default: `__`)
|
50
52
|
* *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
|
51
53
|
if available, otherwise, will use the tag in the `tag_to_kubernetes_name_regexp` format.
|
52
54
|
* `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)
|
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = 'fluent-plugin-kubernetes_metadata_filter'
|
8
|
-
gem.version = '2.
|
8
|
+
gem.version = '2.9.0'
|
9
9
|
gem.authors = ['Jimmi Dyson']
|
10
10
|
gem.email = ['jimmidyson@gmail.com']
|
11
11
|
gem.description = 'Filter plugin to add Kubernetes metadata'
|
@@ -58,6 +58,8 @@ module Fluent::Plugin
|
|
58
58
|
config_param :secret_dir, :string, default: '/var/run/secrets/kubernetes.io/serviceaccount'
|
59
59
|
config_param :de_dot, :bool, default: true
|
60
60
|
config_param :de_dot_separator, :string, default: '_'
|
61
|
+
config_param :de_slash, :bool, default: false
|
62
|
+
config_param :de_slash_separator, :string, default: '__'
|
61
63
|
# if reading from the journal, the record will contain the following fields in the following
|
62
64
|
# format:
|
63
65
|
# CONTAINER_NAME=k8s_$containername.$containerhash_$podname_$namespacename_$poduuid_$rand32bitashex
|
@@ -166,6 +168,10 @@ module Fluent::Plugin
|
|
166
168
|
raise Fluent::ConfigError, "Invalid de_dot_separator: cannot be or contain '.'"
|
167
169
|
end
|
168
170
|
|
171
|
+
if @de_slash && @de_slash_separator.include?('/')
|
172
|
+
raise Fluent::ConfigError, "Invalid de_slash_separator: cannot be or contain '/'"
|
173
|
+
end
|
174
|
+
|
169
175
|
if @cache_ttl < 0
|
170
176
|
log.info 'Setting the cache TTL to :none because it was <= 0'
|
171
177
|
@cache_ttl = :none
|
@@ -381,6 +387,16 @@ module Fluent::Plugin
|
|
381
387
|
end
|
382
388
|
end
|
383
389
|
|
390
|
+
def de_slash!(h)
|
391
|
+
h.keys.each do |ref|
|
392
|
+
next unless h[ref] && ref =~ /\//
|
393
|
+
|
394
|
+
v = h.delete(ref)
|
395
|
+
newref = ref.to_s.gsub('/', @de_slash_separator)
|
396
|
+
h[newref] = v
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
384
400
|
# copied from activesupport
|
385
401
|
def present?(object)
|
386
402
|
object.respond_to?(:empty?) ? !object.empty? : !!object
|
@@ -47,6 +47,10 @@ module KubernetesMetadata
|
|
47
47
|
de_dot!(labels) unless @skip_labels
|
48
48
|
de_dot!(annotations)
|
49
49
|
end
|
50
|
+
if @de_slash
|
51
|
+
de_slash!(labels) unless @skip_labels
|
52
|
+
de_slash!(annotations)
|
53
|
+
end
|
50
54
|
kubernetes_metadata = {
|
51
55
|
'namespace_id' => namespace_object[:metadata][:uid],
|
52
56
|
'creation_timestamp' => namespace_object[:metadata][:creationTimestamp]
|
@@ -65,6 +69,10 @@ module KubernetesMetadata
|
|
65
69
|
de_dot!(labels) unless @skip_labels
|
66
70
|
de_dot!(annotations)
|
67
71
|
end
|
72
|
+
if @de_slash
|
73
|
+
de_slash!(labels) unless @skip_labels
|
74
|
+
de_slash!(annotations)
|
75
|
+
end
|
68
76
|
|
69
77
|
# collect container information
|
70
78
|
container_meta = {}
|
File without changes
|
@@ -432,13 +432,15 @@ class KubernetesMetadataFilterTest < Test::Unit::TestCase
|
|
432
432
|
assert_equal(msg, filtered[0])
|
433
433
|
end
|
434
434
|
|
435
|
-
test 'with kubernetes dotted labels, de_dot enabled' do
|
435
|
+
test 'with kubernetes dotted and slashed labels, de_dot and de_slash enabled' do
|
436
436
|
VCR.use_cassettes([{ name: 'valid_kubernetes_api_server' }, { name: 'kubernetes_get_api_v1' },
|
437
|
-
{ name: '
|
437
|
+
{ name: 'kubernetes_docker_metadata_dotted_slashed_labels' }]) do
|
438
438
|
filtered = emit({}, '
|
439
439
|
kubernetes_url https://localhost:8443
|
440
440
|
watch false
|
441
441
|
cache_size 1
|
442
|
+
de_dot true
|
443
|
+
de_slash true
|
442
444
|
')
|
443
445
|
expected_kube_metadata = {
|
444
446
|
'docker' => {
|
@@ -452,14 +454,14 @@ class KubernetesMetadataFilterTest < Test::Unit::TestCase
|
|
452
454
|
'container_image_id' => 'docker://b2bd1a24a68356b2f30128e6e28e672c1ef92df0d9ec01ec0c7faea5d77d2303',
|
453
455
|
'namespace_id' => '898268c8-4a36-11e5-9d81-42010af0194c',
|
454
456
|
'namespace_labels' => {
|
455
|
-
'
|
457
|
+
'kubernetes_io__namespacetest' => 'somevalue'
|
456
458
|
},
|
457
459
|
'namespace_name' => 'default',
|
458
460
|
'pod_id' => 'c76927af-f563-11e4-b32d-54ee7527188d',
|
459
461
|
'pod_ip' => '172.17.0.8',
|
460
462
|
'master_url' => 'https://localhost:8443',
|
461
463
|
'labels' => {
|
462
|
-
'
|
464
|
+
'kubernetes_io__test' => 'somevalue'
|
463
465
|
}
|
464
466
|
}
|
465
467
|
}
|
@@ -467,14 +469,15 @@ class KubernetesMetadataFilterTest < Test::Unit::TestCase
|
|
467
469
|
end
|
468
470
|
end
|
469
471
|
|
470
|
-
test 'with kubernetes dotted labels, de_dot disabled' do
|
472
|
+
test 'with kubernetes dotted and slashed labels, de_dot and de_slash disabled' do
|
471
473
|
VCR.use_cassettes([{ name: 'valid_kubernetes_api_server' }, { name: 'kubernetes_get_api_v1' },
|
472
|
-
{ name: '
|
474
|
+
{ name: 'kubernetes_docker_metadata_dotted_slashed_labels' }]) do
|
473
475
|
filtered = emit({}, '
|
474
476
|
kubernetes_url https://localhost:8443
|
475
477
|
watch false
|
476
478
|
cache_size 1
|
477
479
|
de_dot false
|
480
|
+
de_slash false
|
478
481
|
')
|
479
482
|
expected_kube_metadata = {
|
480
483
|
'docker' => {
|
@@ -506,11 +509,21 @@ class KubernetesMetadataFilterTest < Test::Unit::TestCase
|
|
506
509
|
test 'invalid de_dot_separator config' do
|
507
510
|
assert_raise Fluent::ConfigError do
|
508
511
|
create_driver('
|
512
|
+
de_dot true
|
509
513
|
de_dot_separator contains.
|
510
514
|
')
|
511
515
|
end
|
512
516
|
end
|
513
517
|
|
518
|
+
test 'invalid de_slash_separator config' do
|
519
|
+
assert_raise Fluent::ConfigError do
|
520
|
+
create_driver('
|
521
|
+
de_slash true
|
522
|
+
de_slash_separator contains/
|
523
|
+
')
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
514
527
|
test 'with records from journald and docker & kubernetes metadata' do
|
515
528
|
# with use_journal true should ignore tags and use CONTAINER_NAME and CONTAINER_ID_FULL
|
516
529
|
tag = 'var.log.containers.junk1_junk2_junk3-49095a2894da899d3b327c5fde1e056a81376cc9a8f8b09a195f2a92bceed450.log'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-kubernetes_metadata_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmi Dyson
|
@@ -230,7 +230,7 @@ files:
|
|
230
230
|
- lib/fluent/plugin/kubernetes_metadata_watch_pods.rb
|
231
231
|
- test/cassettes/invalid_api_server_config.yml
|
232
232
|
- test/cassettes/kubernetes_docker_metadata_annotations.yml
|
233
|
-
- test/cassettes/
|
233
|
+
- test/cassettes/kubernetes_docker_metadata_dotted_slashed_labels.yml
|
234
234
|
- test/cassettes/kubernetes_get_api_v1.yml
|
235
235
|
- test/cassettes/kubernetes_get_api_v1_using_token.yml
|
236
236
|
- test/cassettes/kubernetes_get_namespace_default.yml
|