fluent-plugin-barito 0.3.4 → 0.4.0
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 +8 -0
- data/fluent-plugin-barito.gemspec +2 -2
- data/lib/fluent/plugin/barito_transport.rb +13 -0
- data/lib/fluent/plugin/out_barito_batch_k8s.rb +1 -1
- data/lib/fluent/plugin/out_barito_batch_vm.rb +1 -1
- data/lib/fluent/plugin/out_barito_dynamic_app_batch_k8s.rb +126 -0
- data/lib/fluent/plugin/out_barito_vm.rb +1 -1
- data/spec/lib/fluent/plugin/out_barito_dynamic_app_batch_k8s_spec.rb +81 -0
- data/spec/spec_helper.rb +1 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f97097933e7dbc552c68e40b0234a0fa7f9108bafd9e321bcc26280dcfbcb8f
|
4
|
+
data.tar.gz: af17fc124d2cbbb527c4266124762c14983c96cd9b9dccf4882df0b2af66eca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a219db3c564d4ebf65aa30b6b03f39c95a3f1ca50280332ee82beaae8c5a7b2068c7f21bc6297dee89bf7869b1cf20ab06476f438526bf143f66063158d251b9
|
7
|
+
data.tar.gz: 26ae3bc887cd80141b64da29a2fabaee88d1da6e2cf3a8b4bafc1d9e272bd7f13c2f94fba128ccc7dfa5cce416edf35b17259d60e2d59b78acc6dda6ceaa7577
|
data/CHANGELOG.md
CHANGED
@@ -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.4.0"
|
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}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rest-client'
|
2
|
+
require 'zlib'
|
2
3
|
|
3
4
|
class Fluent::Plugin::BaritoTransport
|
4
5
|
|
@@ -17,4 +18,16 @@ class Fluent::Plugin::BaritoTransport
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
21
|
+
def send_compressed(timber, header)
|
22
|
+
begin
|
23
|
+
header['Content-Encoding'] = 'gzip'
|
24
|
+
|
25
|
+
gz = Zlib::GzipWriter.new(StringIO.new)
|
26
|
+
gz << timber.to_json
|
27
|
+
RestClient.post @produce_url, gz.close.string, header
|
28
|
+
rescue Exception => e
|
29
|
+
puts(header)
|
30
|
+
@logger.error [e.message, e.response, Hash[header.collect{|k,v| [k.to_s, v]}]].join(', ')
|
31
|
+
end
|
32
|
+
end
|
20
33
|
end
|
@@ -0,0 +1,126 @@
|
|
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
|
+
|
18
|
+
# Overide from BufferedOutput
|
19
|
+
def start
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
# Overide from BufferedOutput
|
24
|
+
def format(tag, time, record)
|
25
|
+
[tag, time, record].to_msgpack
|
26
|
+
end
|
27
|
+
|
28
|
+
# Overide from BufferedOutput
|
29
|
+
def write(chunk)
|
30
|
+
data = {}
|
31
|
+
|
32
|
+
transport = Fluent::Plugin::BaritoTransport.new(@produce_url, log)
|
33
|
+
chunk.msgpack_each do |tag, time, record|
|
34
|
+
|
35
|
+
# generate application name
|
36
|
+
if @application_name_format.nil?
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
application_name = expand_application_name_format(record)
|
41
|
+
|
42
|
+
# Kubernetes annotations
|
43
|
+
k8s_metadata = record['kubernetes']
|
44
|
+
|
45
|
+
record = clean_attribute(record)
|
46
|
+
trail = Fluent::Plugin::ClientTrail.new(true)
|
47
|
+
timber = Fluent::Plugin::TimberFactory::create_timber(tag, time, record, trail)
|
48
|
+
new_timber = merge_log_attribute(timber)
|
49
|
+
|
50
|
+
# Add kubernetes information
|
51
|
+
new_timber['k8s_metadata'] = {
|
52
|
+
'pod_name' => k8s_metadata['pod_name'],
|
53
|
+
'namespace_name' => k8s_metadata['namespace_name'],
|
54
|
+
'container_name' => k8s_metadata['container_name'],
|
55
|
+
'host' => k8s_metadata['host'],
|
56
|
+
'cluster_name' => @cluster_name
|
57
|
+
}
|
58
|
+
|
59
|
+
if data[application_name].nil?
|
60
|
+
data[application_name] = { 'items' => [] }
|
61
|
+
end
|
62
|
+
data[application_name]['items'] << new_timber
|
63
|
+
end
|
64
|
+
|
65
|
+
data.each do |application_name, record|
|
66
|
+
header = {
|
67
|
+
content_type: :json,
|
68
|
+
'X-App-Group-Secret' => @application_group_secret,
|
69
|
+
'X-App-Name' => application_name
|
70
|
+
}
|
71
|
+
transport.send_compressed(record, header)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def clean_attribute(record)
|
76
|
+
# Delete kubernetes & docker field
|
77
|
+
record.delete('kubernetes')
|
78
|
+
record.delete('docker')
|
79
|
+
record
|
80
|
+
end
|
81
|
+
|
82
|
+
def merge_log_attribute(record)
|
83
|
+
message_log = nil
|
84
|
+
begin
|
85
|
+
message_log = JSON.parse(record['log'])
|
86
|
+
rescue
|
87
|
+
end
|
88
|
+
|
89
|
+
if !message_log.nil?
|
90
|
+
return record.merge(message_log)
|
91
|
+
end
|
92
|
+
|
93
|
+
record
|
94
|
+
end
|
95
|
+
|
96
|
+
def expand_application_name_format(record)
|
97
|
+
application_name = @application_name_format.dup
|
98
|
+
|
99
|
+
# Regular expression to match placeholders like ${record["key1"]["key2"]}
|
100
|
+
placeholder_regex = /\${record(\["[^"]*"\])+}/
|
101
|
+
|
102
|
+
application_name.gsub!(placeholder_regex) do |placeholder|
|
103
|
+
# Extract keys from the placeholder
|
104
|
+
keys = placeholder.scan(/\["([^"]*)"\]/).flatten
|
105
|
+
# Retrieve the value from the record hash
|
106
|
+
value = get_nested_value(record, keys)
|
107
|
+
value.to_s
|
108
|
+
end
|
109
|
+
|
110
|
+
application_name
|
111
|
+
end
|
112
|
+
|
113
|
+
# Retrieve nested value from record using array of keys
|
114
|
+
def get_nested_value(record, keys)
|
115
|
+
keys.reduce(record) do |acc, key|
|
116
|
+
if acc.is_a?(Hash) && acc.key?(key)
|
117
|
+
acc[key]
|
118
|
+
else
|
119
|
+
# Key not found; return nil to stop further traversal
|
120
|
+
return nil
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
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.4.0
|
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-09-25 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
|
@@ -205,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
207
|
- !ruby/object:Gem::Version
|
206
208
|
version: '0'
|
207
209
|
requirements: []
|
208
|
-
rubygems_version: 3.0.3
|
210
|
+
rubygems_version: 3.0.3.1
|
209
211
|
signing_key:
|
210
212
|
specification_version: 4
|
211
213
|
summary: Fluentd output plugin for BaritoLog
|
@@ -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
|