fluent-plugin-kubernetes-metrics 1.1.7 → 1.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7953f3fade3d0c126f70d9b6922d6b36eccb92461903a723975eb5cb29ee958
4
- data.tar.gz: ceb8d47bbb69b1de2bfafa6c9c05cf8f5ad2909db2d432c7eed78721f6c985f5
3
+ metadata.gz: '01494a399012dc40a3a2d9597327839453e95abc642d5510ad3e423b50c9fd25'
4
+ data.tar.gz: d7d5f2f45267de03f5e519b4ac48ad0b03ae9058a04f399e563c529da1664c7f
5
5
  SHA512:
6
- metadata.gz: 5a310b0ac5c2f1af6cdb34c9c74413dc6b1e4bef7a42f996dc6741a512a80f1fc1822302c313f57ef6772f0a6416b61b64188fe75ff1a3c2a3cee9a969c13828
7
- data.tar.gz: 63dec59922164f39a20eb8ed51bb4f11d464811544eee28b591bf9eba79a7b29f29c3ffb80a89496f7abe433a0fd8b5872f8fe7d841e7bff5f6919a438977b45
6
+ metadata.gz: 870c5b311bd3157f485872149ae1d360cbfc0e44a804c92863d17fe40a114854a6722f512d58f505cdbde950f851b780aba2ceb364bc5b01ab8819bb3c37fe1a
7
+ data.tar.gz: 99b97218aa1a33de365d6ce36f8403f774cba1e2975255253fa5147241b143009082320ffd934752a2b485a42a2d2ed9af2a06d4de0f6ebf99c38ac3ad07f5cd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-kubernetes-metrics (1.1.7)
4
+ fluent-plugin-kubernetes-metrics (1.1.8)
5
5
  fluentd (>= 1.9.1)
6
6
  kubeclient (~> 4.6.0)
7
7
  multi_json (~> 1.14.1)
@@ -107,4 +107,4 @@ DEPENDENCIES
107
107
  webmock (~> 3.5.1)
108
108
 
109
109
  BUNDLED WITH
110
- 2.2.30
110
+ 2.2.33
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.7
1
+ 1.1.8
@@ -90,8 +90,13 @@ module Fluent
90
90
  super
91
91
 
92
92
  timer_execute :metric_scraper, @interval, &method(:scrape_metrics)
93
- timer_execute :stats_metric_scraper, @interval, &method(:scrape_stats_metrics)
94
93
  timer_execute :cadvisor_metric_scraper, @interval, &method(:scrape_cadvisor_metrics)
94
+ # It is done to optionally fetch from 'stats' for k8s version <1.21
95
+ if is_stats_endpoint_available?
96
+ timer_execute :stats_metric_scraper, @interval, &method(:scrape_stats_metrics)
97
+ else
98
+ log.info "'/stats' endpoint is not available. It has been deprecated since k8s v1.15, disabled since v1.18, and removed in v1.21 and onwards"
99
+ end
95
100
  end
96
101
 
97
102
  def close
@@ -597,33 +602,35 @@ module Fluent
597
602
  emit_stats_breakdown(metrics['stats']) unless metrics['stats'].nil?
598
603
  end
599
604
 
605
+ # Make sure regex has only one capturing group
606
+ def grep_using_regex(metric, regex)
607
+ match = metric.match(regex)
608
+ return nil if match.nil?
609
+ match[1]
610
+ end
611
+
600
612
  def emit_cadvisor_metrics(metrics)
601
613
  metrics = metrics.split("\n")
602
614
  metrics.each do |metric|
603
- next unless metric.include? 'container_name='
604
-
605
- next unless metric.match(/^((?!container_name="").)*$/) && metric[0] != '#'
606
-
615
+
616
+ next if metric[0] == '#' or not container_name = grep_using_regex(metric, /container(?:_name)?="([^"]*)"/)
617
+ next if container_name.empty?
618
+
607
619
  metric_str, metric_val = metric.split(' ')
608
620
  metric_val = metric_val.to_f if metric_val.is_a? String
609
621
  first_occur = metric_str.index('{')
610
622
  metric_name = metric_str[0..first_occur - 1]
611
- pod_name = metric.match(/pod_name="\S*"/).to_s
612
- pod_name = pod_name.split('"')[1]
613
- image_name = metric.match(/image="\S*"/).to_s
614
- image_name = image_name.split('"')[1]
615
- namespace = metric.match(/namespace="\S*"/).to_s
616
- namespace = namespace.split('"')[1]
623
+ pod_name = grep_using_regex(metric, /pod(?:_name)?="([^"]*)"/).to_s
624
+ image_name = grep_using_regex(metric, /image="([^"]*)"/).to_s
625
+ namespace = grep_using_regex(metric, /namespace="([^"]*)"/).to_s
617
626
  metric_labels = { 'pod_name' => pod_name, 'image' => image_name, 'namespace' => namespace, 'value' => metric_val, 'node' => @node_name }
618
- if metric =~ /^((?!container_name="POD").)*$/
627
+ if container_name=="POD"
619
628
  tag = 'pod'
620
629
  tag = generate_tag("#{tag}#{metric_name.tr('_', '.')}")
621
630
  tag = tag.gsub('container', '')
622
631
  else
623
- container_name = metric.match(/container_name="\S*"/).to_s
624
- container_name = container_name.split('"')[1]
625
632
  container_label = { 'container_name' => container_name }
626
- metric_labels.merge(container_label)
633
+ metric_labels.merge!(container_label)
627
634
  tag = generate_tag(metric_name.tr('_', '.').to_s)
628
635
  end
629
636
  router.emit tag, @scraped_at_cadvisor, metric_labels
@@ -642,6 +649,20 @@ module Fluent
642
649
  end
643
650
  end
644
651
 
652
+ def is_stats_endpoint_available?
653
+ if @use_rest_client
654
+ response_stats = RestClient::Request.execute request_options_stats
655
+ else
656
+ @node_names.each do |node|
657
+ @node_name = node
658
+ response_stats = stats_proxy_api(node).get(@client.headers)
659
+ end
660
+ end
661
+ true
662
+ rescue RestClient::NotFound
663
+ false
664
+ end
665
+
645
666
  def scrape_stats_metrics
646
667
  if @use_rest_client
647
668
  response_stats = RestClient::Request.execute request_options_stats
@@ -35,6 +35,9 @@ class KubernetesMetricsInputTest < Test::Unit::TestCase
35
35
  ).freeze
36
36
 
37
37
  setup do
38
+ stub_k8s_requests
39
+
40
+ return unless @@hash_map_test.empty?
38
41
  Fluent::Test.setup
39
42
 
40
43
  @@parsed_unit_string = JSON.parse(get_unit_parsed_string)
@@ -45,8 +48,6 @@ class KubernetesMetricsInputTest < Test::Unit::TestCase
45
48
  get_cadvisor_parsed_string = f.read
46
49
  end.close
47
50
 
48
- stub_k8s_requests
49
-
50
51
  @@ca_driver = create_driver
51
52
  @@ca_driver.run timeout: 20, expect_emits: 1, shutdown: true
52
53
 
@@ -56,8 +57,12 @@ class KubernetesMetricsInputTest < Test::Unit::TestCase
56
57
  metrics = get_cadvisor_parsed_string.split("\n")
57
58
  metrics.each do |metric|
58
59
  next unless metric.include? 'container_name='
60
+ next unless metric[0] != '#'
59
61
 
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]
64
+
65
+ next if container_name.empty?
61
66
 
62
67
  metric_str, metric_val = metric.split(' ')
63
68
  metric_val = metric_val.to_f if metric_val.is_a? String
@@ -70,13 +75,11 @@ class KubernetesMetricsInputTest < Test::Unit::TestCase
70
75
  namespace = metric.match(/namespace="\S*"/).to_s
71
76
  namespace = namespace.split('"')[1]
72
77
  metric_labels = { 'pod_name' => pod_name, 'image' => image_name, 'namespace' => namespace, 'value' => metric_val, 'node' => @node_name }
73
- if metric =~ /^((?!container_name="POD").)*$/
78
+ if container_name == 'POD'
74
79
  tag = 'pod'
75
80
  tag = generate_tag("#{tag}#{metric_name.tr('_', '.')}", @@driver.instance.tag)
76
81
  tag = tag.gsub('container', '')
77
82
  else
78
- container_name = metric.match(/container_name="\S*"/).to_s
79
- container_name = container_name.split('"')[1]
80
83
  container_label = { 'container_name' => container_name }
81
84
  metric_labels.merge(container_label)
82
85
  tag = generate_tag(metric_name.tr('_', '.').to_s, @@driver.instance.tag)
@@ -252,11 +255,10 @@ class KubernetesMetricsInputTest < Test::Unit::TestCase
252
255
  assert_true @@hash_map_cadvisor.key?('kube.container.fs.read.seconds.total')
253
256
  assert_equal @@hash_map_cadvisor['kube.container.fs.read.seconds.total'], @@hash_map_test['kube.container.fs.read.seconds.total'][2]['value']
254
257
  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
258
+
257
259
  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"]
260
+ assert_true @@hash_map_cadvisor.key?('kube.container.fs.reads.bytes.total')
261
+ assert_equal @@hash_map_cadvisor['kube.container.fs.reads.bytes.total'], @@hash_map_test["kube.container.fs.reads.bytes.total"][2]["value"]
260
262
  end
261
263
 
262
264
  test 'Test - metrics cadvisor: container_fs_reads_merged_total' do
@@ -289,10 +291,9 @@ class KubernetesMetricsInputTest < Test::Unit::TestCase
289
291
  assert_equal @@hash_map_cadvisor['kube.container.fs.write.seconds.total'], @@hash_map_test['kube.container.fs.write.seconds.total'][2]['value']
290
292
  end
291
293
 
292
- # TODO: Current Test does not work - metric present in metrics_cadvisor.txt but not being parsed by connector in test/working in production
293
294
  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"]
295
+ assert_true @@hash_map_cadvisor.key?('kube.container.fs.writes.bytes.total')
296
+ assert_equal @@hash_map_cadvisor['kube.container.fs.writes.bytes.total'], @@hash_map_test["kube.container.fs.writes.bytes.total"][2]["value"]
296
297
  end
297
298
 
298
299
  test 'Test - metrics cadvisor: container_fs_writes_merged_total' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-kubernetes-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Splunk Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-04 00:00:00.000000000 Z
11
+ date: 2021-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -180,6 +180,6 @@ signing_key:
180
180
  specification_version: 4
181
181
  summary: A fluentd input plugin that collects kubernetes cluster metrics.
182
182
  test_files:
183
+ - test/helper.rb
183
184
  - test/plugin/test_missing_timestamps.rb
184
185
  - test/plugin/test_in_kubernetes_metrics.rb
185
- - test/helper.rb