@@ -9,16 +9,14 @@ def setup
9
9
end
10
10
11
11
MONITOR_CONFIG = %[
12
+ @type tail
13
+ path /tmp/tmp.log, /var/log/containers/mypodname_mynamespace_mycontainername-34646d7fb38199129ab8d0e6f41833d26e1826cba92571100fd6c53904a5317e.log
14
+
12
15
@type collected_tail_monitor
13
- <metric>
14
- name log_collected_bytes_total
15
- type counter
16
- desc Total bytes collected from file
17
16
<labels>
18
- tag ${tag}
19
- hostname ${hostname}
17
+ tag mytag
18
+ host example.com
20
19
</labels>
21
- </metric>
22
20
]
23
21
24
22
INVALID_MONITOR_CONFIG = %[
@@ -32,19 +30,52 @@ def setup
32
30
</labels>
33
31
]
34
32
35
- def create_driver ( conf = MONITOR_CONFIG )
33
+ def create_driver ( conf )
36
34
Fluent ::Test ::Driver ::Input . new ( Fluent ::Plugin ::CollectedTailMonitorInput ) . configure ( conf )
37
35
end
38
36
39
37
def test_configure
40
38
d = create_driver ( MONITOR_CONFIG )
41
39
end
42
40
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
+
43
64
def test_invalid_configure
44
65
assert_raise ( Fluent ::ConfigError ) {
45
66
d = create_driver ( INVALID_MONITOR_CONFIG )
46
67
}
47
68
end
48
69
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
49
80
50
81
end
0 commit comments