fluent-plugin-tag-normaliser 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +2 -1
- data/fluent-plugin-tag-normaliser.gemspec +1 -1
- data/lib/fluent/plugin/out_tag_normaliser.rb +56 -5
- data/test/plugin/test_out_tag_normaliser.rb +27 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3de141eacd728b5c64ef048c4ba6541db115da0348752e699f4a907185db93aa
|
4
|
+
data.tar.gz: 90fc732beaf853c70176dcf2d27325f7b6e5ee5fe3989219a5404c00ea15165f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc500f140016b9ce333228829c155b8b9e9f35bbb2c8d6ecaf83dd9abf30873488e275a2889023c00a83ff157b25e148df127c28d026455ef04595a9904945e5
|
7
|
+
data.tar.gz: ab4a9663c53a053e347ac204068b460ac3dec4815367dbbc2f9aa3aa7a9a31d69b4d8044ef5fccb67451346de78c57ab75b4d7a7a06e0fb566926d5b50931be1
|
data/README.md
CHANGED
@@ -39,7 +39,8 @@ You only need to specify the `format` option.
|
|
39
39
|
|-----------|-------------|---------|
|
40
40
|
| key_prefix | Prefix used to access record attributes | kubernetes |
|
41
41
|
| format | Format to rewrite tag to. You can access record with `${record_name}` expression. Nested attributes available via `.` separator: `${labels.app}` | "" |
|
42
|
-
| unknown | Fallback value for missing record attribute | "unknown |
|
42
|
+
| unknown | Fallback value for missing record attribute | "unknown" |
|
43
|
+
| sticky_tags | Sticky tags will match only one record from an event stream. The same tag will be treated the same way | true |
|
43
44
|
|
44
45
|
### Available fluent-bit provided kubernetes attributes
|
45
46
|
|
@@ -37,6 +37,10 @@ module Fluent
|
|
37
37
|
@tag_map = Hash.new { |k, v| k[v] = "" }
|
38
38
|
end
|
39
39
|
|
40
|
+
def multi_workers_ready?
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
40
44
|
def process(tag, es)
|
41
45
|
if @sticky_tags
|
42
46
|
if @tag_map.has_key?(tag)
|
@@ -68,20 +72,67 @@ module Fluent
|
|
68
72
|
|
69
73
|
def get_key_accessors
|
70
74
|
key_accessors = {}
|
71
|
-
keywords = @format.scan(/\$\{([\w
|
75
|
+
keywords = @format.scan(/\$\{([\w\.\/\-\\]+)}/)
|
72
76
|
keywords.each do |key|
|
73
77
|
placeholder = "${#{key[0]}}"
|
74
|
-
if
|
75
|
-
path =
|
78
|
+
if contains_escaped_period?(key[0])
|
79
|
+
path = create_path_with_bracket_notation(key[0])
|
76
80
|
else
|
77
|
-
path = key[0]
|
81
|
+
path = create_path(key[0])
|
78
82
|
end
|
79
|
-
path = "$." + path
|
80
83
|
key_accessors[placeholder] = record_accessor_create(path)
|
81
84
|
end
|
82
85
|
return key_accessors
|
83
86
|
end
|
84
87
|
|
88
|
+
private
|
89
|
+
|
90
|
+
def contains_escaped_period?(key)
|
91
|
+
key.include?('\.')
|
92
|
+
end
|
93
|
+
|
94
|
+
def create_path(key)
|
95
|
+
if @key_prefix != ""
|
96
|
+
path = @key_prefix + "." + key
|
97
|
+
else
|
98
|
+
path = key
|
99
|
+
end
|
100
|
+
path = "$." + path
|
101
|
+
end
|
102
|
+
|
103
|
+
# Produces the output in bracket notation, e.g. $['kubernetes']['labels']['app.tier']"
|
104
|
+
def create_path_with_bracket_notation(key)
|
105
|
+
path = split_by_unescaped_dots(key)
|
106
|
+
.map { |elem| "['#{elem}']" }
|
107
|
+
.join("")
|
108
|
+
if @key_prefix != ""
|
109
|
+
path = "['#{@key_prefix}']" + path
|
110
|
+
end
|
111
|
+
path = "$" + path
|
112
|
+
end
|
113
|
+
|
114
|
+
# Splits the input string by the . character if it is not escaped by \
|
115
|
+
def split_by_unescaped_dots(text)
|
116
|
+
result = []
|
117
|
+
current_part = ""
|
118
|
+
escaped = false
|
119
|
+
|
120
|
+
text.each_char do |char|
|
121
|
+
if char == "\\" && !escaped
|
122
|
+
escaped = true
|
123
|
+
elsif char == "." && !escaped
|
124
|
+
result << current_part
|
125
|
+
current_part = ""
|
126
|
+
else
|
127
|
+
current_part += char
|
128
|
+
escaped = false
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
result << current_part
|
133
|
+
result
|
134
|
+
end
|
135
|
+
|
85
136
|
end
|
86
137
|
end
|
87
138
|
end
|
@@ -21,10 +21,37 @@ class TagNormaliserOutputTest < Test::Unit::TestCase
|
|
21
21
|
d = create_driver(config)
|
22
22
|
d.run(default_tag: 'test') do
|
23
23
|
d.feed("tag1", event_time, record.dup)
|
24
|
+
end
|
25
|
+
events = d.events
|
26
|
+
puts events
|
27
|
+
|
28
|
+
assert_equal("cluster.default.understood-butterfly-nginx-logging-demo-7dcdcfdcd7-h7p9n.nginx", events[0][0])
|
29
|
+
end
|
30
|
+
|
31
|
+
test "escape_test" do
|
32
|
+
config = %[
|
33
|
+
format cluster.${namespace_name}.${labels.app}.${labels.app\\.tier}.${labels.app\\.kubernetes\\.io/managed-by}
|
34
|
+
]
|
35
|
+
record = {
|
36
|
+
"log" => "Example",
|
37
|
+
"kubernetes" => {
|
38
|
+
"pod_name" => "understood-butterfly-nginx-logging-demo-7dcdcfdcd7-h7p9n",
|
39
|
+
"namespace_name" => "default",
|
40
|
+
"labels" => {
|
41
|
+
"app" => "nginx",
|
42
|
+
"app.tier" => "frontend",
|
43
|
+
"app.kubernetes.io/managed-by" => "helm"
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
d = create_driver(config)
|
48
|
+
d.run(default_tag: 'test') do
|
24
49
|
d.feed("tag1", event_time, record.dup)
|
25
50
|
end
|
26
51
|
events = d.events
|
27
52
|
puts events
|
53
|
+
|
54
|
+
assert_equal("cluster.default.nginx.frontend.helm", events[0][0])
|
28
55
|
end
|
29
56
|
|
30
57
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-tag-normaliser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Banzai Cloud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,8 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
|
-
|
111
|
-
rubygems_version: 2.5.2.3
|
110
|
+
rubygems_version: 3.0.3.1
|
112
111
|
signing_key:
|
113
112
|
specification_version: 4
|
114
113
|
summary: Tag-normaliser is a `fluentd` plugin to help re-tag logs with Kubernetes
|