fluent-plugin-tag-normaliser 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0be47cfc8a8fb73356184a7e0136f3d6b609e438b6ec39ada7c6b87500c9224
4
- data.tar.gz: 8daa7f967cbf3a1459f00574a6035afa030a0d71b5febf83d23683d3c7f7edd3
3
+ metadata.gz: 3de141eacd728b5c64ef048c4ba6541db115da0348752e699f4a907185db93aa
4
+ data.tar.gz: 90fc732beaf853c70176dcf2d27325f7b6e5ee5fe3989219a5404c00ea15165f
5
5
  SHA512:
6
- metadata.gz: 624186d87a41358ec45100c524d2fc170a5a18f2a107fe58e18f994ed545607d7e413abf3520eb7b87eae89def3e75ec935334a78593a075afb12daf640cd59d
7
- data.tar.gz: 395bb59c940e0255c7b9ee170ac007583255c727f1dafe61d8333ca16d8342e6d62f048512f052e40beb4efb925bd1dc9950831c0f8da5fc720f408da1b36ee2
6
+ metadata.gz: fc500f140016b9ce333228829c155b8b9e9f35bbb2c8d6ecaf83dd9abf30873488e275a2889023c00a83ff157b25e148df127c28d026455ef04595a9904945e5
7
+ data.tar.gz: ab4a9663c53a053e347ac204068b460ac3dec4815367dbbc2f9aa3aa7a9a31d69b4d8044ef5fccb67451346de78c57ab75b4d7a7a06e0fb566926d5b50931be1
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-tag-normaliser"
6
- spec.version = "0.1.2"
6
+ spec.version = "0.1.3"
7
7
  spec.authors = ["Banzai Cloud"]
8
8
  spec.email = ["info@banzaicloud.com"]
9
9
 
@@ -72,20 +72,67 @@ module Fluent
72
72
 
73
73
  def get_key_accessors
74
74
  key_accessors = {}
75
- keywords = @format.scan(/\$\{([\w\.\/\-]+)}/)
75
+ keywords = @format.scan(/\$\{([\w\.\/\-\\]+)}/)
76
76
  keywords.each do |key|
77
77
  placeholder = "${#{key[0]}}"
78
- if @key_prefix != ""
79
- path = @key_prefix + "." + key[0]
78
+ if contains_escaped_period?(key[0])
79
+ path = create_path_with_bracket_notation(key[0])
80
80
  else
81
- path = key[0]
81
+ path = create_path(key[0])
82
82
  end
83
- path = "$." + path
84
83
  key_accessors[placeholder] = record_accessor_create(path)
85
84
  end
86
85
  return key_accessors
87
86
  end
88
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
+
89
136
  end
90
137
  end
91
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Banzai Cloud
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-27 00:00:00.000000000 Z
11
+ date: 2024-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,7 +92,7 @@ homepage: https://github.com/banzaicloud/fluent-plugin-tag-normaliser
92
92
  licenses:
93
93
  - Apache-2.0
94
94
  metadata: {}
95
- post_install_message:
95
+ post_install_message:
96
96
  rdoc_options: []
97
97
  require_paths:
98
98
  - lib
@@ -107,8 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubygems_version: 3.1.6
111
- signing_key:
110
+ rubygems_version: 3.0.3.1
111
+ signing_key:
112
112
  specification_version: 4
113
113
  summary: Tag-normaliser is a `fluentd` plugin to help re-tag logs with Kubernetes
114
114
  metadata.