fluent-plugin-kubernetes-metrics-hbrewster 1.2.2
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 +7 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +110 -0
- data/LICENSE +268 -0
- data/README.md +125 -0
- data/Rakefile +29 -0
- data/VERSION +1 -0
- data/fluent-plugin-kubernetes-metrics.gemspec +31 -0
- data/lib/fluent/plugin/in_kubernetes_metrics.rb +713 -0
- data/metrics-information.md +269 -0
- data/test/helper.rb +151 -0
- data/test/plugin/test_in_kubernetes_metrics.rb +462 -0
- data/test/plugin/test_missing_timestamps.rb +44 -0
- metadata +185 -0
@@ -0,0 +1,462 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fluent/plugin/in_kubernetes_metrics.rb'
|
3
|
+
|
4
|
+
class KubernetesMetricsInputTest < Test::Unit::TestCase
|
5
|
+
include Fluent::Test::Helpers
|
6
|
+
include PluginTestHelper
|
7
|
+
|
8
|
+
@@driver = nil
|
9
|
+
|
10
|
+
@@hash_map_test = {}
|
11
|
+
@@hash_map_cadvisor = {}
|
12
|
+
|
13
|
+
CONFIG = %(
|
14
|
+
type kubernetes_metrics
|
15
|
+
node_name generics-aws-node-name
|
16
|
+
tag kube.*
|
17
|
+
insecure_ssl true
|
18
|
+
interval 10s
|
19
|
+
use_rest_client true
|
20
|
+
use_rest_client_ssl false
|
21
|
+
kubelet_port 10_255
|
22
|
+
kubelet_address generics-aws-node-name
|
23
|
+
).freeze
|
24
|
+
|
25
|
+
SUMMARY_CONFIG = %(
|
26
|
+
type kubernetes_metrics
|
27
|
+
node_names 'generics-aws-node-name'
|
28
|
+
tag kube.*
|
29
|
+
insecure_ssl true
|
30
|
+
interval 10s
|
31
|
+
use_rest_client false
|
32
|
+
use_rest_client_ssl false
|
33
|
+
kubelet_port 10_255
|
34
|
+
kubelet_address generics-aws-node-name
|
35
|
+
).freeze
|
36
|
+
|
37
|
+
setup do
|
38
|
+
Fluent::Test.setup
|
39
|
+
|
40
|
+
@@parsed_unit_string = JSON.parse(get_unit_parsed_string)
|
41
|
+
@@parsed_string2 = JSON.parse(get_stats_parsed_string)
|
42
|
+
|
43
|
+
get_cadvisor_parsed_string = nil
|
44
|
+
open(File.expand_path('../metrics_cadvisor.txt', __dir__)).tap do |f|
|
45
|
+
get_cadvisor_parsed_string = f.read
|
46
|
+
end.close
|
47
|
+
|
48
|
+
stub_k8s_requests
|
49
|
+
|
50
|
+
@@ca_driver = create_driver
|
51
|
+
@@ca_driver.run timeout: 20, expect_emits: 1, shutdown: true
|
52
|
+
|
53
|
+
@@driver = create_driver
|
54
|
+
@@driver.run timeout: 20, expect_emits: 1, shutdown: true
|
55
|
+
|
56
|
+
metrics = get_cadvisor_parsed_string.split("\n")
|
57
|
+
metrics.each do |metric|
|
58
|
+
next unless metric.include? 'container_name='
|
59
|
+
|
60
|
+
next unless metric.match(/^((?!container_name="").)*$/) && metric[0] != '#'
|
61
|
+
|
62
|
+
metric_str, metric_val = metric.split(' ')
|
63
|
+
metric_val = metric_val.to_f if metric_val.is_a? String
|
64
|
+
first_occur = metric_str.index('{')
|
65
|
+
metric_name = metric_str[0..first_occur - 1]
|
66
|
+
pod_name = metric.match(/pod_name="\S*"/).to_s
|
67
|
+
pod_name = pod_name.split('"')[1]
|
68
|
+
image_name = metric.match(/image="\S*"/).to_s
|
69
|
+
image_name = image_name.split('"')[1]
|
70
|
+
namespace = metric.match(/namespace="\S*"/).to_s
|
71
|
+
namespace = namespace.split('"')[1]
|
72
|
+
metric_labels = { 'pod_name' => pod_name, 'image' => image_name, 'namespace' => namespace, 'value' => metric_val, 'node' => @node_name }
|
73
|
+
if metric =~ /^((?!container_name="POD").)*$/
|
74
|
+
tag = 'pod'
|
75
|
+
tag = generate_tag("#{tag}#{metric_name.tr('_', '.')}", @@driver.instance.tag)
|
76
|
+
tag = tag.gsub('container', '')
|
77
|
+
else
|
78
|
+
container_name = metric.match(/container_name="\S*"/).to_s
|
79
|
+
container_name = container_name.split('"')[1]
|
80
|
+
container_label = { 'container_name' => container_name }
|
81
|
+
metric_labels.merge(container_label)
|
82
|
+
tag = generate_tag(metric_name.tr('_', '.').to_s, @@driver.instance.tag)
|
83
|
+
end
|
84
|
+
@@hash_map_cadvisor[tag] = metric_labels['value']
|
85
|
+
end
|
86
|
+
|
87
|
+
@@driver.events.each do |tag, time, record|
|
88
|
+
@@hash_map_test[tag] = tag, time, record
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def create_driver(conf = CONFIG)
|
93
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::KubernetesMetricsInput).configure(conf)
|
94
|
+
end
|
95
|
+
|
96
|
+
test 'configuration' do
|
97
|
+
assert_nothing_raised(Fluent::ConfigError) do
|
98
|
+
create_driver(CONFIG)
|
99
|
+
end
|
100
|
+
|
101
|
+
d = create_driver
|
102
|
+
assert_equal 'generics-aws-node-name', d.instance.node_name
|
103
|
+
assert_equal 'kube.*', d.instance.tag
|
104
|
+
assert_equal true, d.instance.insecure_ssl
|
105
|
+
assert_equal 10, d.instance.interval
|
106
|
+
assert_equal true, d.instance.use_rest_client
|
107
|
+
end
|
108
|
+
|
109
|
+
sub_test_case 'node_unit_tests' do
|
110
|
+
test 'test_emit_cpu_metrics' do
|
111
|
+
assert_not_nil @@hash_map_test.key?('kube.node.cpu.usage')
|
112
|
+
assert_equal @@parsed_unit_string['node']['cpu']['usageNanoCores'], @@hash_map_test['kube.node.cpu.usage'][2]['value']
|
113
|
+
|
114
|
+
assert_not_nil @@hash_map_test.key?('kube.node.cpu.usage_rate')
|
115
|
+
assert_equal @@parsed_unit_string['node']['cpu']['usageNanoCores'] / 1_000_000, @@hash_map_test['kube.node.cpu.usage_rate'][2]['value']
|
116
|
+
end
|
117
|
+
|
118
|
+
test 'test_emit_memory_metrics' do
|
119
|
+
assert_not_nil @@hash_map_test.find('kube.node.memory.available_bytes')
|
120
|
+
assert_equal @@parsed_unit_string['node']['memory']['availableBytes'], @@hash_map_test['kube.node.memory.available_bytes'][2]['value']
|
121
|
+
|
122
|
+
assert_not_nil @@hash_map_test.find('kube.node.memory.usage_bytes')
|
123
|
+
assert_equal @@parsed_unit_string['node']['memory']['usageBytes'], @@hash_map_test['kube.node.memory.usage_bytes'][2]['value']
|
124
|
+
|
125
|
+
assert_not_nil @@hash_map_test.find('kube.node.memory.working_set_bytes')
|
126
|
+
assert_equal @@parsed_unit_string['node']['memory']['workingSetBytes'], @@hash_map_test['kube.node.memory.working_set_bytes'][2]['value']
|
127
|
+
|
128
|
+
assert_not_nil @@hash_map_test.find('kube.node.memory.rss_bytes')
|
129
|
+
assert_equal @@parsed_unit_string['node']['memory']['rssBytes'], @@hash_map_test['kube.node.memory.rss_bytes'][2]['value']
|
130
|
+
|
131
|
+
assert_not_nil @@hash_map_test.find('kube.node.memory.page_faults')
|
132
|
+
assert_equal @@parsed_unit_string['node']['memory']['pageFaults'], @@hash_map_test['kube.node.memory.page_faults'][2]['value']
|
133
|
+
|
134
|
+
assert_not_nil @@hash_map_test.find('kube.node.memory.major_page_faults')
|
135
|
+
assert_equal @@parsed_unit_string['node']['memory']['majorPageFaults'], @@hash_map_test['kube.node.memory.major_page_faults'][2]['value']
|
136
|
+
end
|
137
|
+
|
138
|
+
test 'test_emit_network_metrics' do
|
139
|
+
assert_not_nil @@hash_map_test.find('kube.node.network.rx_bytes')
|
140
|
+
assert_equal @@parsed_unit_string['node']['network']['rxBytes'], @@hash_map_test['kube.node.network.rx_bytes'][2]['value']
|
141
|
+
|
142
|
+
assert_not_nil @@hash_map_test.find('kube.node.network.rx_errors')
|
143
|
+
assert_equal @@parsed_unit_string['node']['network']['rxErrors'], @@hash_map_test['kube.node.network.rx_errors'][2]['value']
|
144
|
+
|
145
|
+
assert_not_nil @@hash_map_test.find('kube.node.network.tx_bytes')
|
146
|
+
assert_equal @@parsed_unit_string['node']['network']['txBytes'], @@hash_map_test['kube.node.network.tx_bytes'][2]['value']
|
147
|
+
|
148
|
+
assert_not_nil @@hash_map_test.find('kube.node.network.tx_errors')
|
149
|
+
assert_equal @@parsed_unit_string['node']['network']['txErrors'], @@hash_map_test['kube.node.network.tx_errors'][2]['value']
|
150
|
+
end
|
151
|
+
|
152
|
+
test 'test_emit_fs_metrics' do
|
153
|
+
assert_not_nil @@hash_map_test.find('kube.node.fs.available_bytes')
|
154
|
+
assert_equal @@parsed_unit_string['node']['fs']['availableBytes'], @@hash_map_test['kube.node.fs.available_bytes'][2]['value']
|
155
|
+
|
156
|
+
assert_not_nil @@hash_map_test.find('kube.node.fs.capacity_bytes')
|
157
|
+
assert_equal @@parsed_unit_string['node']['fs']['capacityBytes'], @@hash_map_test['kube.node.fs.capacity_bytes'][2]['value']
|
158
|
+
|
159
|
+
assert_not_nil @@hash_map_test.find('kube.node.fs.used_bytes')
|
160
|
+
assert_equal @@parsed_unit_string['node']['fs']['usedBytes'], @@hash_map_test['kube.node.fs.used_bytes'][2]['value']
|
161
|
+
|
162
|
+
assert_not_nil @@hash_map_test.find('kube.node.fs.inodes_free')
|
163
|
+
assert_equal @@parsed_unit_string['node']['fs']['inodesFree'], @@hash_map_test['kube.node.fs.inodes_free'][2]['value']
|
164
|
+
|
165
|
+
assert_not_nil @@hash_map_test.find('kube.node.fs.inodes')
|
166
|
+
assert_equal @@parsed_unit_string['node']['fs']['inodes'], @@hash_map_test['kube.node.fs.inodes'][2]['value']
|
167
|
+
|
168
|
+
assert_not_nil @@hash_map_test.find('kube.node.fs.inodes_used')
|
169
|
+
assert_equal @@parsed_unit_string['node']['fs']['inodesUsed'], @@hash_map_test['kube.node.fs.inodes_used'][2]['value']
|
170
|
+
end
|
171
|
+
|
172
|
+
test 'test_emit_fs_imagefs_metrics' do
|
173
|
+
assert_not_nil @@hash_map_test.find('kube.node.fs.available_bytes')
|
174
|
+
assert_equal @@parsed_unit_string['node']['runtime']['imageFs']['availableBytes'], @@hash_map_test['kube.node.imagefs.available_bytes'][2]['value']
|
175
|
+
|
176
|
+
assert_not_nil @@hash_map_test.find('kube.node.fs.capacity_bytes')
|
177
|
+
assert_equal @@parsed_unit_string['node']['runtime']['imageFs']['capacityBytes'], @@hash_map_test['kube.node.imagefs.capacity_bytes'][2]['value']
|
178
|
+
|
179
|
+
assert_not_nil @@hash_map_test.find('kube.node.fs.used_bytes')
|
180
|
+
assert_equal @@parsed_unit_string['node']['runtime']['imageFs']['usedBytes'], @@hash_map_test['kube.node.imagefs.used_bytes'][2]['value']
|
181
|
+
|
182
|
+
assert_not_nil @@hash_map_test.find('kube.node.fs.inodes_free')
|
183
|
+
assert_equal @@parsed_unit_string['node']['runtime']['imageFs']['inodesFree'], @@hash_map_test['kube.node.imagefs.inodes_free'][2]['value']
|
184
|
+
|
185
|
+
assert_not_nil @@hash_map_test.find('kube.node.fs.inodes')
|
186
|
+
assert_equal @@parsed_unit_string['node']['runtime']['imageFs']['inodes'], @@hash_map_test['kube.node.imagefs.inodes'][2]['value']
|
187
|
+
|
188
|
+
assert_not_nil @@hash_map_test.find('kube.node.fs.inodes_used')
|
189
|
+
assert_equal @@parsed_unit_string['node']['runtime']['imageFs']['inodesUsed'], @@hash_map_test['kube.node.imagefs.inodes_used'][2]['value']
|
190
|
+
end
|
191
|
+
|
192
|
+
test 'summary_api' do
|
193
|
+
d = create_driver SUMMARY_CONFIG
|
194
|
+
d.run timeout: 20, expect_emits: 1, shutdown: true
|
195
|
+
events = d.events
|
196
|
+
assert_not_nil events
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
sub_test_case 'metrics_cadvisor_unit_tests' do
|
201
|
+
test 'Test - metrics cadvisor: container_cpu_load_average_10s' do
|
202
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.cpu.load.average.10s')
|
203
|
+
assert_equal @@hash_map_cadvisor['kube.container.cpu.load.average.10s'], @@hash_map_test['kube.container.cpu.load.average.10s'][2]['value']
|
204
|
+
end
|
205
|
+
|
206
|
+
test 'Test - metrics cadvisor: container_cpu_system_seconds_total' do
|
207
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.cpu.system.seconds.total')
|
208
|
+
assert_equal @@hash_map_cadvisor['kube.container.cpu.system.seconds.total'], @@hash_map_test['kube.container.cpu.system.seconds.total'][2]['value']
|
209
|
+
end
|
210
|
+
|
211
|
+
test 'Test - metrics cadvisor: container_cpu_usage_seconds_total' do
|
212
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.cpu.usage.seconds.total')
|
213
|
+
assert_equal @@hash_map_cadvisor['kube.container.cpu.usage.seconds.total'], @@hash_map_test['kube.container.cpu.usage.seconds.total'][2]['value']
|
214
|
+
end
|
215
|
+
|
216
|
+
test 'Test - metrics cadvisor: container_cpu_user_seconds_total' do
|
217
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.cpu.user.seconds.total')
|
218
|
+
assert_equal @@hash_map_cadvisor['kube.container.cpu.user.seconds.total'], @@hash_map_test['kube.container.cpu.user.seconds.total'][2]['value']
|
219
|
+
end
|
220
|
+
|
221
|
+
test 'Test - metrics cadvisor: container_fs_inodes_free' do
|
222
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.inodes.free')
|
223
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.inodes.free'], @@hash_map_test['kube.container.fs.inodes.free'][2]['value']
|
224
|
+
end
|
225
|
+
|
226
|
+
test 'Test - metrics cadvisor: container_fs_inodes_total' do
|
227
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.inodes.total')
|
228
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.inodes.total'], @@hash_map_test['kube.container.fs.inodes.total'][2]['value']
|
229
|
+
end
|
230
|
+
|
231
|
+
test 'Test - metrics cadvisor: container_fs_io_current' do
|
232
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.io.current')
|
233
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.io.current'], @@hash_map_test['kube.container.fs.io.current'][2]['value']
|
234
|
+
end
|
235
|
+
|
236
|
+
test 'Test - metrics cadvisor: container_fs_io_time_seconds_total' do
|
237
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.io.time.seconds.total')
|
238
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.io.time.seconds.total'], @@hash_map_test['kube.container.fs.io.time.seconds.total'][2]['value']
|
239
|
+
end
|
240
|
+
|
241
|
+
test 'Test - metrics cadvisor: container_fs_io_time_weighted_seconds_total' do
|
242
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.io.time.weighted.seconds.total')
|
243
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.io.time.weighted.seconds.total'], @@hash_map_test['kube.container.fs.io.time.weighted.seconds.total'][2]['value']
|
244
|
+
end
|
245
|
+
|
246
|
+
test 'Test - metrics cadvisor: container_fs_limit_bytes' do
|
247
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.limit.bytes')
|
248
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.limit.bytes'], @@hash_map_test['kube.container.fs.limit.bytes'][2]['value']
|
249
|
+
end
|
250
|
+
|
251
|
+
test 'Test - metrics cadvisor: container_fs_read_seconds_total' do
|
252
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.read.seconds.total')
|
253
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.read.seconds.total'], @@hash_map_test['kube.container.fs.read.seconds.total'][2]['value']
|
254
|
+
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
|
257
|
+
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
|
+
end
|
261
|
+
|
262
|
+
test 'Test - metrics cadvisor: container_fs_reads_merged_total' do
|
263
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.reads.merged.total')
|
264
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.reads.merged.total'], @@hash_map_test['kube.container.fs.reads.merged.total'][2]['value']
|
265
|
+
end
|
266
|
+
|
267
|
+
test 'Test - metrics cadvisor: container_fs_reads_total' do
|
268
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.reads.total')
|
269
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.reads.total'], @@hash_map_test['kube.container.fs.reads.total'][2]['value']
|
270
|
+
end
|
271
|
+
|
272
|
+
test 'Test - metrics cadvisor: container_fs_sector_reads_total' do
|
273
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.sector.reads.total')
|
274
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.sector.reads.total'], @@hash_map_test['kube.container.fs.sector.reads.total'][2]['value']
|
275
|
+
end
|
276
|
+
|
277
|
+
test 'Test - metrics cadvisor: container_fs_sector_writes_total' do
|
278
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.sector.writes.total')
|
279
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.sector.writes.total'], @@hash_map_test['kube.container.fs.sector.writes.total'][2]['value']
|
280
|
+
end
|
281
|
+
|
282
|
+
test 'Test - metrics cadvisor: container_fs_usage_bytes' do
|
283
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.usage.bytes')
|
284
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.usage.bytes'], @@hash_map_test['kube.container.fs.usage.bytes'][2]['value']
|
285
|
+
end
|
286
|
+
|
287
|
+
test 'Test - metrics cadvisor: container_fs_write_seconds_total' do
|
288
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.write.seconds.total')
|
289
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.write.seconds.total'], @@hash_map_test['kube.container.fs.write.seconds.total'][2]['value']
|
290
|
+
end
|
291
|
+
|
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
|
+
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"]
|
296
|
+
end
|
297
|
+
|
298
|
+
test 'Test - metrics cadvisor: container_fs_writes_merged_total' do
|
299
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.writes.merged.total')
|
300
|
+
# assert_equal @@hash_map_cadvisor['kube.container.fs.writes.merged.total'], @@hash_map_test["kube.container.fs.writes.merged.total"][2]["value"]
|
301
|
+
end
|
302
|
+
|
303
|
+
test 'Test - metrics cadvisor: container_fs_writes_total' do
|
304
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.fs.writes.total')
|
305
|
+
assert_equal @@hash_map_cadvisor['kube.container.fs.writes.total'], @@hash_map_test['kube.container.fs.writes.total'][2]['value']
|
306
|
+
end
|
307
|
+
|
308
|
+
test 'Test - metrics cadvisor: container_last_seen' do
|
309
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.last.seen')
|
310
|
+
assert_equal @@hash_map_cadvisor['kube.container.last.seen'], @@hash_map_test['kube.container.last.seen'][2]['value']
|
311
|
+
end
|
312
|
+
|
313
|
+
test 'Test - metrics cadvisor: container_memory_cache' do
|
314
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.memory.cache')
|
315
|
+
assert_equal @@hash_map_cadvisor['kube.container.memory.cache'], @@hash_map_test['kube.container.memory.cache'][2]['value']
|
316
|
+
end
|
317
|
+
|
318
|
+
test 'Test - metrics cadvisor: container_memory_failcnt' do
|
319
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.memory.failcnt')
|
320
|
+
assert_equal @@hash_map_cadvisor['kube.container.memory.failcnt'], @@hash_map_test['kube.container.memory.failcnt'][2]['value']
|
321
|
+
end
|
322
|
+
|
323
|
+
test 'Test - metrics cadvisor: container_memory_failures_total' do
|
324
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.memory.failures.total')
|
325
|
+
assert_equal @@hash_map_cadvisor['kube.container.memory.failures.total'], @@hash_map_test['kube.container.memory.failures.total'][2]['value']
|
326
|
+
end
|
327
|
+
|
328
|
+
test 'Test - metrics cadvisor: container_memory_max_usage_bytes' do
|
329
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.memory.max.usage.bytes')
|
330
|
+
assert_equal @@hash_map_cadvisor['kube.container.memory.max.usage.bytes'], @@hash_map_test['kube.container.memory.max.usage.bytes'][2]['value']
|
331
|
+
end
|
332
|
+
|
333
|
+
test 'Test - metrics cadvisor: container_memory_rss' do
|
334
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.memory.rss')
|
335
|
+
assert_equal @@hash_map_cadvisor['kube.container.memory.rss'], @@hash_map_test['kube.container.memory.rss'][2]['value']
|
336
|
+
end
|
337
|
+
|
338
|
+
test 'Test - metrics cadvisor: container_memory_swap' do
|
339
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.memory.swap')
|
340
|
+
assert_equal @@hash_map_cadvisor['kube.container.memory.swap'], @@hash_map_test['kube.container.memory.swap'][2]['value']
|
341
|
+
end
|
342
|
+
|
343
|
+
test 'Test - metrics cadvisor: container_memory_usage_bytes' do
|
344
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.memory.usage.bytes')
|
345
|
+
assert_equal @@hash_map_cadvisor['kube.container.memory.usage.bytes'], @@hash_map_test['kube.container.memory.usage.bytes'][2]['value']
|
346
|
+
end
|
347
|
+
|
348
|
+
test 'Test - metrics cadvisor: container_memory_working_set_bytes' do
|
349
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.memory.working.set.bytes')
|
350
|
+
assert_equal @@hash_map_cadvisor['kube.container.memory.working.set.bytes'], @@hash_map_test['kube.container.memory.working.set.bytes'][2]['value']
|
351
|
+
end
|
352
|
+
|
353
|
+
test 'Test - metrics cadvisor: container_network_receive_bytes_total' do
|
354
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.network.receive.bytes.total')
|
355
|
+
assert_equal @@hash_map_cadvisor['kube.container.network.receive.bytes.total'], @@hash_map_test['kube.container.network.receive.bytes.total'][2]['value']
|
356
|
+
end
|
357
|
+
|
358
|
+
test 'Test - metrics cadvisor: container_network_receive_errors_total' do
|
359
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.network.receive.errors.total')
|
360
|
+
assert_equal @@hash_map_cadvisor['kube.container.network.receive.errors.total'], @@hash_map_test['kube.container.network.receive.errors.total'][2]['value']
|
361
|
+
end
|
362
|
+
|
363
|
+
test 'Test - metrics cadvisor: container_network_receive_packets_dropped_total' do
|
364
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.network.receive.packets.dropped.total')
|
365
|
+
assert_equal @@hash_map_cadvisor['kube.container.network.receive.packets.dropped.total'], @@hash_map_test['kube.container.network.receive.packets.dropped.total'][2]['value']
|
366
|
+
end
|
367
|
+
|
368
|
+
test 'Test - metrics cadvisor: container_network_receive_packets_total' do
|
369
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.network.receive.packets.total')
|
370
|
+
assert_equal @@hash_map_cadvisor['kube.container.network.receive.packets.total'], @@hash_map_test['kube.container.network.receive.packets.total'][2]['value']
|
371
|
+
end
|
372
|
+
|
373
|
+
test 'Test - metrics cadvisor: container_network_tcp_usage_total' do
|
374
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.network.tcp.usage.total')
|
375
|
+
assert_equal @@hash_map_cadvisor['kube.container.network.tcp.usage.total'], @@hash_map_test['kube.container.network.tcp.usage.total'][2]['value']
|
376
|
+
end
|
377
|
+
|
378
|
+
test 'Test - metrics cadvisor: container_network_transmit_bytes_total' do
|
379
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.network.transmit.bytes.total')
|
380
|
+
assert_equal @@hash_map_cadvisor['kube.container.network.transmit.bytes.total'], @@hash_map_test['kube.container.network.transmit.bytes.total'][2]['value']
|
381
|
+
end
|
382
|
+
|
383
|
+
test 'Test - metrics cadvisor: container_network_transmit_errors_total' do
|
384
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.network.transmit.errors.total')
|
385
|
+
assert_equal @@hash_map_cadvisor['kube.container.network.transmit.errors.total'], @@hash_map_test['kube.container.network.transmit.errors.total'][2]['value']
|
386
|
+
end
|
387
|
+
|
388
|
+
test 'Test - metrics cadvisor: container_network_transmit_packets_dropped_total' do
|
389
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.network.transmit.packets.dropped.total')
|
390
|
+
assert_equal @@hash_map_cadvisor['kube.container.network.transmit.packets.dropped.total'], @@hash_map_test['kube.container.network.transmit.packets.dropped.total'][2]['value']
|
391
|
+
end
|
392
|
+
|
393
|
+
test 'Test - metrics cadvisor: container_network_transmit_packets_total' do
|
394
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.network.transmit.packets.total')
|
395
|
+
assert_equal @@hash_map_cadvisor['kube.container.network.transmit.packets.total'], @@hash_map_test['kube.container.network.transmit.packets.total'][2]['value']
|
396
|
+
end
|
397
|
+
|
398
|
+
test 'Test - metrics cadvisor: container_network_udp_usage_total' do
|
399
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.network.udp.usage.total')
|
400
|
+
assert_equal @@hash_map_cadvisor['kube.container.network.udp.usage.total'], @@hash_map_test['kube.container.network.udp.usage.total'][2]['value']
|
401
|
+
end
|
402
|
+
|
403
|
+
# TODO: Current Test does not work - metric present in metrics_cadvisor.txt but not being parsed by connector
|
404
|
+
test 'Test - metrics cadvisor: container_scrape_error' do
|
405
|
+
assert_false @@hash_map_cadvisor.key?('kube.container.scrape.error')
|
406
|
+
# assert_equal @@hash_map_cadvisor['kube.container.scrape.error'], @@hash_map_test["kube.container.scrape.error"][2]["value"]
|
407
|
+
end
|
408
|
+
|
409
|
+
test 'Test - metrics cadvisor: container_spec_cpu_period' do
|
410
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.spec.cpu.period')
|
411
|
+
assert_equal @@hash_map_cadvisor['kube.container.spec.cpu.period'], @@hash_map_test['kube.container.spec.cpu.period'][2]['value']
|
412
|
+
end
|
413
|
+
|
414
|
+
test 'Test - metrics cadvisor: container_spec_cpu_shares' do
|
415
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.spec.cpu.shares')
|
416
|
+
assert_equal @@hash_map_cadvisor['kube.container.spec.cpu.shares'], @@hash_map_test['kube.container.spec.cpu.shares'][2]['value']
|
417
|
+
end
|
418
|
+
|
419
|
+
test 'Test - metrics cadvisor: container_spec_memory_limit_bytes' do
|
420
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.spec.memory.limit.bytes')
|
421
|
+
assert_equal @@hash_map_cadvisor['kube.container.spec.memory.limit.bytes'], @@hash_map_test['kube.container.spec.memory.limit.bytes'][2]['value']
|
422
|
+
end
|
423
|
+
|
424
|
+
test 'Test - metrics cadvisor: container_spec_memory_reservation_limit_bytes' do
|
425
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.spec.memory.reservation.limit.bytes')
|
426
|
+
assert_equal @@hash_map_cadvisor['kube.container.spec.memory.reservation.limit.bytes'], @@hash_map_test['kube.container.spec.memory.reservation.limit.bytes'][2]['value']
|
427
|
+
end
|
428
|
+
|
429
|
+
test 'Test - metrics cadvisor: container_spec_memory_swap_limit_bytes' do
|
430
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.spec.memory.swap.limit.bytes')
|
431
|
+
assert_equal @@hash_map_cadvisor['kube.container.spec.memory.swap.limit.bytes'], @@hash_map_test['kube.container.spec.memory.swap.limit.bytes'][2]['value']
|
432
|
+
end
|
433
|
+
|
434
|
+
test 'Test - metrics cadvisor: container_start_time_seconds' do
|
435
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.start.time.seconds')
|
436
|
+
assert_equal @@hash_map_cadvisor['kube.container.start.time.seconds'], @@hash_map_test['kube.container.start.time.seconds'][2]['value']
|
437
|
+
end
|
438
|
+
|
439
|
+
test 'Test - metrics cadvisor: container_tasks_state' do
|
440
|
+
assert_true @@hash_map_cadvisor.key?('kube.container.tasks.state')
|
441
|
+
assert_equal @@hash_map_cadvisor['kube.container.tasks.state'], @@hash_map_test['kube.container.tasks.state'][2]['value']
|
442
|
+
end
|
443
|
+
|
444
|
+
# TODO: Current Test does not work - metric present in metrics_cadvisor.txt but not being parsed by connector
|
445
|
+
test 'Test - metrics cadvisor: machine_cpu_cores' do
|
446
|
+
assert_false @@hash_map_cadvisor.key?('kube.machine.cpu.cores')
|
447
|
+
# assert_equal @@hash_map_cadvisor['kube.machine.cpu.cores'], @@hash_map_test["kube.machine.cpu.cores"][2]["value"]
|
448
|
+
end
|
449
|
+
|
450
|
+
# TODO: Current Test does not work - metric present in metrics_cadvisor.txt but not being parsed by connector
|
451
|
+
test 'Test - metrics cadvisor: machine_memory_bytes' do
|
452
|
+
assert_false @@hash_map_cadvisor.key?('kube.container.machine.memory.bytes')
|
453
|
+
# assert_equal @@hash_map_cadvisor['kube.container.machine.memory.bytes'], @@hash_map_test["kube.container.machine.memory.bytes"][2]["value"]
|
454
|
+
end
|
455
|
+
|
456
|
+
# TODO: Test does not work - metric not present in metrics_cadvisor.txt
|
457
|
+
test 'Test - metrics cadvisor: container_cpu_cfs_throttled_seconds_total' do
|
458
|
+
assert_false @@hash_map_cadvisor.key?('kube.container.cpu.cfs.throttled.seconds.total')
|
459
|
+
# assert_equal @@hash_map_cadvisor['kube.container.cpu.cfs.throttled.seconds.total'], @@hash_map_test["kube.container.cpu.cfs.throttled.seconds.total"][2]["value"]
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fluent/plugin/in_kubernetes_metrics.rb'
|
3
|
+
|
4
|
+
class KubernetesMetricsInputTest < Test::Unit::TestCase
|
5
|
+
include Fluent::Test::Helpers
|
6
|
+
include PluginTestHelper
|
7
|
+
|
8
|
+
@@driver = nil
|
9
|
+
|
10
|
+
CONFIG = %(
|
11
|
+
type kubernetes_metrics
|
12
|
+
node_name generics-aws-node-name
|
13
|
+
tag kube.*
|
14
|
+
insecure_ssl true
|
15
|
+
interval 10s
|
16
|
+
use_rest_client true
|
17
|
+
use_rest_client_ssl false
|
18
|
+
kubelet_port 10_255
|
19
|
+
kubelet_address generics-aws-node-name
|
20
|
+
).freeze
|
21
|
+
|
22
|
+
setup do
|
23
|
+
Fluent::Test.setup
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_driver(conf = CONFIG)
|
27
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::KubernetesMetricsInput).configure(conf)
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'timestamps_missing' do
|
31
|
+
@@parsed_unit_string = JSON.parse(get_unit_parsed_string_missing_timestamps)
|
32
|
+
ENV['KUBERNETES_SERVICE_HOST'] = k8s_host
|
33
|
+
ENV['KUBERNETES_SERVICE_PORT'] = k8s_port
|
34
|
+
# all stub response bodies are from real k8s 1.8 API calls
|
35
|
+
stub_k8s_api
|
36
|
+
stub_kubelet_summary_api_missing_timestamps
|
37
|
+
stub_k8s_v1
|
38
|
+
stub_kubelet_summary_api_missing_timestamps
|
39
|
+
stub_metrics_cadvisor
|
40
|
+
stub_metrics_stats
|
41
|
+
@@driver = create_driver
|
42
|
+
@@driver.run timeout: 20, expect_emits: 1, shutdown: true
|
43
|
+
end
|
44
|
+
end
|