@@ -35,6 +35,9 @@ class KubernetesMetricsInputTest < Test::Unit::TestCase
3535 ) . freeze
3636
3737 setup do
38+ stub_k8s_requests
39+
40+ return unless @@hash_map_test . empty?
3841 Fluent ::Test . setup
3942
4043 @@parsed_unit_string = JSON . parse ( get_unit_parsed_string )
@@ -45,8 +48,6 @@ class KubernetesMetricsInputTest < Test::Unit::TestCase
4548 get_cadvisor_parsed_string = f . read
4649 end . close
4750
48- stub_k8s_requests
49-
5051 @@ca_driver = create_driver
5152 @@ca_driver . run timeout : 20 , expect_emits : 1 , shutdown : true
5253
@@ -56,8 +57,10 @@ class KubernetesMetricsInputTest < Test::Unit::TestCase
5657 metrics = get_cadvisor_parsed_string . split ( "\n " )
5758 metrics . each do |metric |
5859 next unless metric . include? 'container_name='
60+ next unless metric [ 0 ] != '#'
5961
60- next unless metric . match ( /^((?!container_name="").)*$/ ) && metric [ 0 ] != '#'
62+ container_name = metric . match ( /container_name="\S *"/ ) . to_s
63+ container_name = container_name . split ( '"' ) [ 1 ]
6164
6265 metric_str , metric_val = metric . split ( ' ' )
6366 metric_val = metric_val . to_f if metric_val . is_a? String
@@ -70,13 +73,11 @@ class KubernetesMetricsInputTest < Test::Unit::TestCase
7073 namespace = metric . match ( /namespace="\S *"/ ) . to_s
7174 namespace = namespace . split ( '"' ) [ 1 ]
7275 metric_labels = { 'pod_name' => pod_name , 'image' => image_name , 'namespace' => namespace , 'value' => metric_val , 'node' => @node_name }
73- if metric =~ /^((?!container_name=" POD").)*$/
76+ if container_name == ' POD'
7477 tag = 'pod'
7578 tag = generate_tag ( "#{ tag } #{ metric_name . tr ( '_' , '.' ) } " , @@driver . instance . tag )
7679 tag = tag . gsub ( 'container' , '' )
7780 else
78- container_name = metric . match ( /container_name="\S *"/ ) . to_s
79- container_name = container_name . split ( '"' ) [ 1 ]
8081 container_label = { 'container_name' => container_name }
8182 metric_labels . merge ( container_label )
8283 tag = generate_tag ( metric_name . tr ( '_' , '.' ) . to_s , @@driver . instance . tag )
@@ -252,11 +253,10 @@ def create_driver(conf = CONFIG)
252253 assert_true @@hash_map_cadvisor . key? ( 'kube.container.fs.read.seconds.total' )
253254 assert_equal @@hash_map_cadvisor [ 'kube.container.fs.read.seconds.total' ] , @@hash_map_test [ 'kube.container.fs.read.seconds.total' ] [ 2 ] [ 'value' ]
254255 end
255-
256- # TODO: Current Test does not work - metric present in metrics_cadvisor.txt but not being parsed by connector in test/working in production
256+
257257 test 'Test - metrics cadvisor: container_fs_reads_bytes_total' do
258- assert_false @@hash_map_cadvisor . key? ( 'kube.container.fs.reads.bytes.total' )
259- # assert_equal @@hash_map_cadvisor['kube.container.fs.reads.bytes.total'], @@hash_map_test["kube.container.fs.reads.bytes.total"][2]["value"]
258+ assert_true @@hash_map_cadvisor . key? ( 'kube.container.fs.reads.bytes.total' )
259+ assert_equal @@hash_map_cadvisor [ 'kube.container.fs.reads.bytes.total' ] , @@hash_map_test [ "kube.container.fs.reads.bytes.total" ] [ 2 ] [ "value" ]
260260 end
261261
262262 test 'Test - metrics cadvisor: container_fs_reads_merged_total' do
@@ -289,10 +289,9 @@ def create_driver(conf = CONFIG)
289289 assert_equal @@hash_map_cadvisor [ 'kube.container.fs.write.seconds.total' ] , @@hash_map_test [ 'kube.container.fs.write.seconds.total' ] [ 2 ] [ 'value' ]
290290 end
291291
292- # TODO: Current Test does not work - metric present in metrics_cadvisor.txt but not being parsed by connector in test/working in production
293292 test 'Test - metrics cadvisor: container_fs_writes_bytes_total' do
294- assert_false @@hash_map_cadvisor . key? ( 'kube.container.fs.writes.bytes.total' )
295- # assert_equal @@hash_map_cadvisor['kube.container.fs.writes.bytes.total'], @@hash_map_test["kube.container.fs.writes.bytes.total"][2]["value"]
293+ assert_true @@hash_map_cadvisor . key? ( 'kube.container.fs.writes.bytes.total' )
294+ assert_equal @@hash_map_cadvisor [ 'kube.container.fs.writes.bytes.total' ] , @@hash_map_test [ "kube.container.fs.writes.bytes.total" ] [ 2 ] [ "value" ]
296295 end
297296
298297 test 'Test - metrics cadvisor: container_fs_writes_merged_total' do
0 commit comments