fluent-plugin-barito 0.3.5 → 0.5.1
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 +4 -4
- data/CHANGELOG.md +13 -1
- data/fluent-plugin-barito.gemspec +2 -2
- data/lib/fluent/plugin/out_barito_batch_k8s.rb +6 -0
- data/lib/fluent/plugin/out_barito_batch_vm.rb +6 -0
- data/lib/fluent/plugin/out_barito_dynamic_app_batch_k8s.rb +132 -0
- data/spec/lib/fluent/plugin/out_barito_dynamic_app_batch_k8s_spec.rb +81 -0
- data/spec/spec_helper.rb +1 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77b08876975a60787f945406ceef1c8c6885d6c14e9fce2f780e2a11aced749d
|
4
|
+
data.tar.gz: 3422b7d24b4c836dce95fd5987e793ca798fff91691dcf256ff2835253c1f558
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9eeb839e61e1a6cfb1eb8223138873e58063e7d546b2106d51dddceb063e1ae8894d8d23782081f3184e4adad8dcd4afc53632fec7d0371651b0c1739e4f42d8
|
7
|
+
data.tar.gz: 85657a49d27eeae2f4928c13c686e586d5349a31e62897a6b8e84687e5b8ef1b374b4c6b7951bfe8da8597f35325919d032188a35b7d85849f0d7d0208ab19a0
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
**0.5.1**
|
4
|
+
|
5
|
+
- rename extralabels field to `additional_labels`
|
6
|
+
|
7
|
+
**0.5.0**
|
8
|
+
|
9
|
+
- Add extralabels field for additional information on client trail. e.g cloud_service_provider or else.
|
10
|
+
|
11
|
+
**0.4.0**
|
12
|
+
|
13
|
+
- Add custom output that can use dynamic application name format
|
14
|
+
|
3
15
|
**0.3.5**
|
4
16
|
|
5
17
|
- Add gzip/compressed feature before sent timber
|
@@ -7,7 +19,7 @@
|
|
7
19
|
**0.3.4**
|
8
20
|
|
9
21
|
- Add cluster name field (from k8s)
|
10
|
-
|
22
|
+
|
11
23
|
**0.3.3**
|
12
24
|
|
13
25
|
- Print verbose error on logs when receiving failed response from the server
|
@@ -3,9 +3,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "fluent-plugin-barito"
|
6
|
-
spec.version = "0.
|
6
|
+
spec.version = "0.5.1"
|
7
7
|
spec.authors = ["BaritoLog"]
|
8
|
-
spec.email = ["
|
8
|
+
spec.email = ["fadli.nurhasan@gmail.com", "gnu.iben@gmail.com"]
|
9
9
|
|
10
10
|
spec.summary = %q{Fluentd output plugin for BaritoLog}
|
11
11
|
spec.description = %q{This gem will forward output from fluentd to Barito-Flow}
|
@@ -15,6 +15,7 @@ module Fluent
|
|
15
15
|
config_param :application_name, :string, :default => nil
|
16
16
|
config_param :produce_url, :string, :default => ''
|
17
17
|
config_param :cluster_name, :string, :default => ''
|
18
|
+
config_param :additional_labels, :hash, :default => {}
|
18
19
|
|
19
20
|
# Overide from BufferedOutput
|
20
21
|
def start
|
@@ -51,6 +52,11 @@ module Fluent
|
|
51
52
|
'host' => k8s_metadata['host'],
|
52
53
|
'cluster_name' => @cluster_name
|
53
54
|
}
|
55
|
+
|
56
|
+
# Add extra labels from config_params
|
57
|
+
unless @additional_labels.empty?
|
58
|
+
new_timber['client_trail'].merge!(@additional_labels)
|
59
|
+
end
|
54
60
|
|
55
61
|
data['items'] << new_timber
|
56
62
|
end
|
@@ -14,6 +14,7 @@ module Fluent
|
|
14
14
|
config_param :application_group_secret, :string, :default => nil
|
15
15
|
config_param :application_name, :string, :default => nil
|
16
16
|
config_param :produce_url, :string, :default => ''
|
17
|
+
config_param :additional_labels, :hash, :default => {}
|
17
18
|
|
18
19
|
# Overide from BufferedOutput
|
19
20
|
def start
|
@@ -35,6 +36,11 @@ module Fluent
|
|
35
36
|
trail = Fluent::Plugin::ClientTrail.new(false)
|
36
37
|
timber = Fluent::Plugin::TimberFactory::create_timber(tag, time, record, trail)
|
37
38
|
|
39
|
+
# Add extra labels from config_params
|
40
|
+
unless @additional_labels.empty?
|
41
|
+
timber['client_trail'].merge!(@additional_labels)
|
42
|
+
end
|
43
|
+
|
38
44
|
data['items'] << timber
|
39
45
|
end
|
40
46
|
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'fluent/output'
|
2
|
+
require_relative 'barito_timber'
|
3
|
+
require_relative 'barito_client_trail'
|
4
|
+
require_relative 'barito_transport'
|
5
|
+
|
6
|
+
module Fluent
|
7
|
+
class BaritoDynamicAppBatchK8sOutput < BufferedOutput
|
8
|
+
|
9
|
+
PLUGIN_NAME = 'barito_dynamic_app_batch_k8s'
|
10
|
+
|
11
|
+
Fluent::Plugin.register_output(PLUGIN_NAME, self)
|
12
|
+
|
13
|
+
config_param :application_name_format, :string, :default => nil
|
14
|
+
config_param :application_group_secret, :string, :default => nil
|
15
|
+
config_param :produce_url, :string, :default => ''
|
16
|
+
config_param :cluster_name, :string, :default => ''
|
17
|
+
config_param :additional_labels, :hash, :default => {}
|
18
|
+
|
19
|
+
# Overide from BufferedOutput
|
20
|
+
def start
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
# Overide from BufferedOutput
|
25
|
+
def format(tag, time, record)
|
26
|
+
[tag, time, record].to_msgpack
|
27
|
+
end
|
28
|
+
|
29
|
+
# Overide from BufferedOutput
|
30
|
+
def write(chunk)
|
31
|
+
data = {}
|
32
|
+
|
33
|
+
transport = Fluent::Plugin::BaritoTransport.new(@produce_url, log)
|
34
|
+
chunk.msgpack_each do |tag, time, record|
|
35
|
+
|
36
|
+
# generate application name
|
37
|
+
if @application_name_format.nil?
|
38
|
+
return
|
39
|
+
end
|
40
|
+
|
41
|
+
application_name = expand_application_name_format(record)
|
42
|
+
|
43
|
+
# Kubernetes annotations
|
44
|
+
k8s_metadata = record['kubernetes']
|
45
|
+
|
46
|
+
record = clean_attribute(record)
|
47
|
+
trail = Fluent::Plugin::ClientTrail.new(true)
|
48
|
+
timber = Fluent::Plugin::TimberFactory::create_timber(tag, time, record, trail)
|
49
|
+
new_timber = merge_log_attribute(timber)
|
50
|
+
|
51
|
+
# Add kubernetes information
|
52
|
+
new_timber['k8s_metadata'] = {
|
53
|
+
'pod_name' => k8s_metadata['pod_name'],
|
54
|
+
'namespace_name' => k8s_metadata['namespace_name'],
|
55
|
+
'container_name' => k8s_metadata['container_name'],
|
56
|
+
'host' => k8s_metadata['host'],
|
57
|
+
'cluster_name' => @cluster_name
|
58
|
+
}
|
59
|
+
|
60
|
+
# Add extra labels from config_params
|
61
|
+
unless @additional_labels.empty?
|
62
|
+
new_timber['client_trail'].merge!(@additional_labels)
|
63
|
+
end
|
64
|
+
|
65
|
+
if data[application_name].nil?
|
66
|
+
data[application_name] = { 'items' => [] }
|
67
|
+
end
|
68
|
+
data[application_name]['items'] << new_timber
|
69
|
+
end
|
70
|
+
|
71
|
+
data.each do |application_name, record|
|
72
|
+
header = {
|
73
|
+
content_type: :json,
|
74
|
+
'X-App-Group-Secret' => @application_group_secret,
|
75
|
+
'X-App-Name' => application_name
|
76
|
+
}
|
77
|
+
transport.send_compressed(record, header)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def clean_attribute(record)
|
82
|
+
# Delete kubernetes & docker field
|
83
|
+
record.delete('kubernetes')
|
84
|
+
record.delete('docker')
|
85
|
+
record
|
86
|
+
end
|
87
|
+
|
88
|
+
def merge_log_attribute(record)
|
89
|
+
message_log = nil
|
90
|
+
begin
|
91
|
+
message_log = JSON.parse(record['log'])
|
92
|
+
rescue
|
93
|
+
end
|
94
|
+
|
95
|
+
if !message_log.nil?
|
96
|
+
return record.merge(message_log)
|
97
|
+
end
|
98
|
+
|
99
|
+
record
|
100
|
+
end
|
101
|
+
|
102
|
+
def expand_application_name_format(record)
|
103
|
+
application_name = @application_name_format.dup
|
104
|
+
|
105
|
+
# Regular expression to match placeholders like ${record["key1"]["key2"]}
|
106
|
+
placeholder_regex = /\${record(\["[^"]*"\])+}/
|
107
|
+
|
108
|
+
application_name.gsub!(placeholder_regex) do |placeholder|
|
109
|
+
# Extract keys from the placeholder
|
110
|
+
keys = placeholder.scan(/\["([^"]*)"\]/).flatten
|
111
|
+
# Retrieve the value from the record hash
|
112
|
+
value = get_nested_value(record, keys)
|
113
|
+
value.to_s
|
114
|
+
end
|
115
|
+
|
116
|
+
application_name
|
117
|
+
end
|
118
|
+
|
119
|
+
# Retrieve nested value from record using array of keys
|
120
|
+
def get_nested_value(record, keys)
|
121
|
+
keys.reduce(record) do |acc, key|
|
122
|
+
if acc.is_a?(Hash) && acc.key?(key)
|
123
|
+
acc[key]
|
124
|
+
else
|
125
|
+
# Key not found; return nil to stop further traversal
|
126
|
+
return nil
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Fluent::BaritoBatchDynamicAppK8sOutput' do
|
4
|
+
before do
|
5
|
+
@plugin = Fluent::BaritoDynamicAppBatchK8sOutput.new
|
6
|
+
@plugin.instance_variable_set(:@application_name_format, 'clusterA-${record["kubernetes"]["namespace_name"]}-${record["kubernetes"]["labels"]["app_name"]}')
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '.merge_log_attribute' do
|
10
|
+
it do
|
11
|
+
record = {
|
12
|
+
"kubernetes" => {"some_attr" => "some_value"},
|
13
|
+
"docker" => "docker_value",
|
14
|
+
"log" => "{\"some_attr\": \"info\", \"other_attr\": \"other_value\"}"
|
15
|
+
}
|
16
|
+
new_record = @plugin.merge_log_attribute(record)
|
17
|
+
|
18
|
+
expect(new_record['some_attr']).to eq("info")
|
19
|
+
expect(new_record['other_attr']).to eq("other_value")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.clean_attribute' do
|
24
|
+
it do
|
25
|
+
record = {
|
26
|
+
"kubernetes" => {"some_attr" => "some_value"},
|
27
|
+
"docker" => "docker_value",
|
28
|
+
"attr" => "some_value"
|
29
|
+
}
|
30
|
+
new_record = @plugin.clean_attribute(record)
|
31
|
+
|
32
|
+
expect(new_record['kubernetes']).to be_nil
|
33
|
+
expect(new_record['docker']).to be_nil
|
34
|
+
expect(new_record['attr']).to eq("some_value")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#expand_application_name_format' do
|
39
|
+
it 'expands the application name format with values from the record' do
|
40
|
+
record = {
|
41
|
+
'kubernetes' => {
|
42
|
+
'namespace_name' => 'namespace1',
|
43
|
+
'labels' => {
|
44
|
+
'app_name' => 'app1'
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
expanded_name = @plugin.expand_application_name_format(record)
|
50
|
+
expect(expanded_name).to eq('clusterA-namespace1-app1')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns the format string if no placeholders are present' do
|
54
|
+
@plugin.instance_variable_set(:@application_name_format, 'static_name')
|
55
|
+
record = {}
|
56
|
+
|
57
|
+
expanded_name = @plugin.expand_application_name_format(record)
|
58
|
+
expect(expanded_name).to eq('static_name')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns the format string with empty values if keys are missing in the record' do
|
62
|
+
record = {
|
63
|
+
'kubernetes' => {
|
64
|
+
'namespace_name' => 'namespace1'
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
expanded_name = @plugin.expand_application_name_format(record)
|
69
|
+
expect(expanded_name).to eq('clusterA-namespace1-')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns nil if the format string is nil' do
|
73
|
+
@plugin.instance_variable_set(:@application_name_format, "")
|
74
|
+
record = {}
|
75
|
+
|
76
|
+
expanded_name = @plugin.expand_application_name_format(record)
|
77
|
+
expect(expanded_name).to be_empty
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -115,6 +115,7 @@ RSpec.configure do |config|
|
|
115
115
|
require 'fluent/plugin/out_barito_vm'
|
116
116
|
require 'fluent/plugin/out_barito_k8s'
|
117
117
|
require 'fluent/plugin/out_barito_batch_k8s'
|
118
|
+
require 'fluent/plugin/out_barito_dynamic_app_batch_k8s'
|
118
119
|
require 'fluent/plugin/barito_client_trail'
|
119
120
|
require 'fluent/plugin/barito_timber'
|
120
121
|
require 'fluent/plugin/barito_transport'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-barito
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BaritoLog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -158,8 +158,8 @@ dependencies:
|
|
158
158
|
version: '2'
|
159
159
|
description: This gem will forward output from fluentd to Barito-Flow
|
160
160
|
email:
|
161
|
-
-
|
162
|
-
-
|
161
|
+
- fadli.nurhasan@gmail.com
|
162
|
+
- gnu.iben@gmail.com
|
163
163
|
executables: []
|
164
164
|
extensions: []
|
165
165
|
extra_rdoc_files: []
|
@@ -179,11 +179,13 @@ files:
|
|
179
179
|
- lib/fluent/plugin/barito_transport.rb
|
180
180
|
- lib/fluent/plugin/out_barito_batch_k8s.rb
|
181
181
|
- lib/fluent/plugin/out_barito_batch_vm.rb
|
182
|
+
- lib/fluent/plugin/out_barito_dynamic_app_batch_k8s.rb
|
182
183
|
- lib/fluent/plugin/out_barito_k8s.rb
|
183
184
|
- lib/fluent/plugin/out_barito_vm.rb
|
184
185
|
- spec/lib/fluent/plugin/barito_timber_spec.rb
|
185
186
|
- spec/lib/fluent/plugin/barito_transport_spec.rb
|
186
187
|
- spec/lib/fluent/plugin/out_barito_batch_k8s_spec.rb
|
188
|
+
- spec/lib/fluent/plugin/out_barito_dynamic_app_batch_k8s_spec.rb
|
187
189
|
- spec/lib/fluent/plugin/out_barito_k8s_spec.rb
|
188
190
|
- spec/spec_helper.rb
|
189
191
|
homepage: https://github.com/BaritoLog/Barito-Fluent-Plugin
|
@@ -213,5 +215,6 @@ test_files:
|
|
213
215
|
- spec/lib/fluent/plugin/barito_timber_spec.rb
|
214
216
|
- spec/lib/fluent/plugin/barito_transport_spec.rb
|
215
217
|
- spec/lib/fluent/plugin/out_barito_batch_k8s_spec.rb
|
218
|
+
- spec/lib/fluent/plugin/out_barito_dynamic_app_batch_k8s_spec.rb
|
216
219
|
- spec/lib/fluent/plugin/out_barito_k8s_spec.rb
|
217
220
|
- spec/spec_helper.rb
|