Skip to content

Commit 61b666f

Browse files
Merge pull request #2169 from openshift-cherrypick-robot/cherry-pick-2163-to-master
[master] fix for https://issues.redhat.com/browse/LOG-1647
2 parents f9fbc8d + 0daac99 commit 61b666f

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

fluentd/lib/fluent-plugin-collected/lib/fluent/plugin/in_collected_tail_monitor.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,25 @@ def labels(plugin_info, path)
114114
namespace = path_match_data['namespace'],
115115
containername = path_match_data['container_name'],
116116
dockerid = path_match_data['docker_id']
117-
118-
@log.debug "path #{path}, namespace #{namespace}, podname #{podname},containername #{containername}"
117+
118+
@log.debug "path #{path}, namespace #{namespace}, podname #{podname[0]},containername #{containername}"
119119

120120
@base_labels.merge(
121121
plugin_id: plugin_info["plugin_id"],
122122
type: plugin_info["type"],
123123
path: path,
124124
namespace: namespace,
125-
podname: podname,
125+
podname: podname[0],
126126
containername: containername,
127127
)
128128
else
129129
@base_labels.merge(
130130
plugin_id: plugin_info["plugin_id"],
131131
type: plugin_info["type"],
132132
path: path,
133+
namespace: "notfound",
134+
podname: "notfound",
135+
containername: "notfound",
133136
)
134137
end
135138
end

fluentd/lib/fluent-plugin-collected/test/plugin/test_in_collected_tail_monitor.rb

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ def setup
99
end
1010

1111
MONITOR_CONFIG = %[
12+
@type tail
13+
path /tmp/tmp.log, /var/log/containers/mypodname_mynamespace_mycontainername-34646d7fb38199129ab8d0e6f41833d26e1826cba92571100fd6c53904a5317e.log
14+
1215
@type collected_tail_monitor
13-
<metric>
14-
name log_collected_bytes_total
15-
type counter
16-
desc Total bytes collected from file
1716
<labels>
18-
tag ${tag}
19-
hostname ${hostname}
17+
tag mytag
18+
host example.com
2019
</labels>
21-
</metric>
2220
]
2321

2422
INVALID_MONITOR_CONFIG = %[
@@ -32,19 +30,52 @@ def setup
3230
</labels>
3331
]
3432

35-
def create_driver(conf = MONITOR_CONFIG)
33+
def create_driver(conf)
3634
Fluent::Test::Driver::Input.new(Fluent::Plugin::CollectedTailMonitorInput).configure(conf)
3735
end
3836

3937
def test_configure
4038
d = create_driver(MONITOR_CONFIG)
4139
end
4240

41+
def test_labels_applied_to_metrics
42+
conf = MONITOR_CONFIG
43+
puts "passing this #{conf}"
44+
d = create_driver(conf)
45+
beforerunlabels = d.instance.instance_variable_get(:@base_labels)
46+
puts "before base labels set to ...#{beforerunlabels}"
47+
d.run {
48+
d.instance.update_monitor_info()
49+
postrunlabels = d.instance.instance_variable_get(:@base_labels)
50+
path = "/tmp/tmp.log"
51+
mergedlabels = d.instance.labels({"plugin_id" => "mypluginid", "type" => "input_plugin"}, path)
52+
puts "with logfilepath as #{path} post merging base labels set to ...#{mergedlabels}"
53+
54+
path = "/var/log/containers/mypodname_mynamespace_mycontainername-34646d7fb38199129ab8d0e6f41833d26e1826cba92571100fd6c53904a5317e.log"
55+
newmergedlabels = d.instance.labels({"plugin_id" => "mypluginid", "type" => "input_plugin"}, path)
56+
puts "with logfilepath as #{path} post merging base labels set to ...#{newmergedlabels}"
57+
58+
assert_equal('mynamespace',newmergedlabels[:namespace])
59+
assert_equal('mycontainername',newmergedlabels[:containername])
60+
assert_equal('mypodname',newmergedlabels[:podname])
61+
}
62+
end
63+
4364
def test_invalid_configure
4465
assert_raise(Fluent::ConfigError) {
4566
d = create_driver(INVALID_MONITOR_CONFIG)
4667
}
4768
end
4869

70+
test 'emit' do
71+
d = create_driver(MONITOR_CONFIG)
72+
d.run(timeout: 0.5)
73+
74+
d.events.each do |tag, time, record|
75+
assert_equal('input.test', tag)
76+
assert_equal({'plugin_id' => 'fluentd','type' => 'tail'}, record)
77+
assert(time.is_a?(Fluent::EventTime))
78+
end
79+
end
4980

5081
end

0 commit comments

Comments
 (0)