-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathtest_kubelet.py
1647 lines (1413 loc) · 66.6 KB
/
test_kubelet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# (C) Datadog, Inc. 2018-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import json
import logging
import os
import sys
from collections import defaultdict
import mock
import pytest
import requests
import requests_mock
from datadog_checks.base.checks.kubelet_base.base import KubeletCredentials
from datadog_checks.base.errors import SkipInstanceError
from datadog_checks.base.utils.date import parse_rfc3339
from datadog_checks.dev.http import MockResponse
from datadog_checks.kubelet import KubeletCheck, PodListUtils
# Skip the whole tests module on Windows
pytestmark = pytest.mark.skipif(sys.platform == 'win32', reason='tests for linux only')
# Constants
HERE = os.path.abspath(os.path.dirname(__file__))
QUANTITIES = {
'12k': 12 * 1000,
'12M': 12 * (1000 * 1000),
'12Ki': 12.0 * 1024,
'12K': 12.0,
'12test': 12.0,
'1.181116006E9': 1.181116006 * (10**9),
'129e6': 129 * (10**6),
'12E': 12 * (1000 * 1000 * 1000 * 1000 * 1000 * 1000),
}
# Kubernetes versions, used to differentiate cadvisor payloads after the label change
KUBE_POST_1_16 = '1.16'
KUBE_1_14 = '1.14'
KUBE_PRE_1_14 = '1.13'
KUBE_1_21 = '1.21'
NODE_SPEC = {
u'cloud_provider': u'GCE',
u'instance_type': u'n1-standard-1',
u'num_cores': 1,
u'system_uuid': u'5556DC4F-C198-07C8-BE37-ACB98B1BA490',
u'network_devices': [{u'mtu': 1460, u'speed': 0, u'name': u'eth0', u'mac_address': u'42:01:0a:84:00:04'}],
u'hugepages': [{u'num_pages': 0, u'page_size': 2048}],
u'memory_capacity': 3885424640,
u'instance_id': u'8153046835786593062',
u'boot_id': u'789bf9ff-77be-4f43-8352-62f84d5e4356',
u'cpu_frequency_khz': 2600000,
u'machine_id': u'5556dc4fc19807c8be37acb98b1ba490',
}
EXPECTED_METRICS_COMMON = [
'kubernetes.pods.running',
'kubernetes.containers.running',
'kubernetes.containers.restarts',
'kubernetes.cpu.capacity',
'kubernetes.cpu.usage.total',
'kubernetes.cpu.limits',
'kubernetes.cpu.requests',
'kubernetes.filesystem.usage',
'kubernetes.filesystem.usage_pct',
'kubernetes.memory.capacity',
'kubernetes.memory.limits',
'kubernetes.memory.requests',
'kubernetes.memory.usage',
'kubernetes.memory.working_set',
'kubernetes.memory.cache',
'kubernetes.memory.rss',
'kubernetes.memory.swap',
'kubernetes.network.rx_bytes',
'kubernetes.network.tx_bytes',
'kubernetes.ephemeral_storage.usage',
'kubernetes.runtime.cpu.usage',
'kubernetes.runtime.memory.usage',
'kubernetes.runtime.memory.rss',
'kubernetes.kubelet.cpu.usage',
'kubernetes.kubelet.memory.usage',
'kubernetes.kubelet.memory.rss',
'kubernetes.node.filesystem.usage',
'kubernetes.node.filesystem.usage_pct',
'kubernetes.node.image.filesystem.usage',
'kubernetes.node.image.filesystem.usage_pct',
]
EXPECTED_METRICS_PROMETHEUS = [
'kubernetes.cpu.load.10s.avg',
'kubernetes.cpu.system.total',
'kubernetes.cpu.user.total',
'kubernetes.cpu.cfs.periods',
'kubernetes.cpu.cfs.throttled.periods',
'kubernetes.cpu.cfs.throttled.seconds',
'kubernetes.memory.usage_pct',
'kubernetes.memory.sw_limit',
'kubernetes.network.rx_dropped',
'kubernetes.network.rx_errors',
'kubernetes.network.tx_dropped',
'kubernetes.network.tx_errors',
'kubernetes.io.write_bytes',
'kubernetes.io.read_bytes',
'kubernetes.apiserver.certificate.expiration.count',
'kubernetes.apiserver.certificate.expiration.sum',
'kubernetes.rest.client.requests',
'kubernetes.rest.client.latency.count',
'kubernetes.rest.client.latency.sum',
'kubernetes.kubelet.runtime.operations',
'kubernetes.kubelet.runtime.errors',
'kubernetes.kubelet.runtime.operations.duration.sum',
'kubernetes.kubelet.runtime.operations.duration.count',
'kubernetes.kubelet.runtime.operations.duration.quantile',
'kubernetes.kubelet.docker.operations',
'kubernetes.kubelet.docker.errors',
'kubernetes.kubelet.docker.operations.duration.sum',
'kubernetes.kubelet.docker.operations.duration.count',
'kubernetes.kubelet.docker.operations.duration.quantile',
'kubernetes.kubelet.network_plugin.latency.sum',
'kubernetes.kubelet.network_plugin.latency.count',
'kubernetes.kubelet.volume.stats.available_bytes',
'kubernetes.kubelet.volume.stats.capacity_bytes',
'kubernetes.kubelet.volume.stats.used_bytes',
'kubernetes.kubelet.volume.stats.inodes',
'kubernetes.kubelet.volume.stats.inodes_free',
'kubernetes.kubelet.volume.stats.inodes_used',
'kubernetes.kubelet.evictions',
'kubernetes.kubelet.pod.start.duration.sum',
'kubernetes.kubelet.pod.start.duration.count',
'kubernetes.kubelet.pod.worker.start.duration.sum',
'kubernetes.kubelet.pod.worker.start.duration.count',
'kubernetes.go_threads',
'kubernetes.go_goroutines',
]
EXPECTED_METRICS_PROMETHEUS_1_14 = EXPECTED_METRICS_PROMETHEUS + [
'kubernetes.kubelet.container.log_filesystem.used_bytes',
'kubernetes.kubelet.pod.worker.duration.sum',
'kubernetes.kubelet.pod.worker.duration.count',
'kubernetes.kubelet.pleg.relist_duration.count',
'kubernetes.kubelet.pleg.relist_duration.sum',
'kubernetes.kubelet.pleg.relist_interval.count',
'kubernetes.kubelet.pleg.relist_interval.sum',
]
EXPECTED_METRICS_PROMETHEUS_PRE_1_14 = EXPECTED_METRICS_PROMETHEUS + [
'kubernetes.kubelet.network_plugin.latency.quantile',
'kubernetes.kubelet.pod.start.duration.quantile',
'kubernetes.kubelet.pod.worker.start.duration.quantile',
]
EXPECTED_METRICS_PROMETHEUS_1_21 = [
'kubernetes.apiserver.certificate.expiration.count',
'kubernetes.apiserver.certificate.expiration.sum',
'kubernetes.containers.restarts',
'kubernetes.containers.running',
'kubernetes.cpu.capacity',
'kubernetes.cpu.limits',
'kubernetes.cpu.requests',
'kubernetes.ephemeral_storage.usage',
'kubernetes.go_goroutines',
'kubernetes.go_threads',
'kubernetes.kubelet.container.log_filesystem.used_bytes',
'kubernetes.kubelet.cpu.usage',
'kubernetes.kubelet.memory.usage',
'kubernetes.kubelet.memory.rss',
'kubernetes.kubelet.network_plugin.latency.count',
'kubernetes.kubelet.network_plugin.latency.sum',
'kubernetes.kubelet.pleg.discard_events',
'kubernetes.kubelet.pleg.last_seen',
'kubernetes.kubelet.pleg.relist_duration.count',
'kubernetes.kubelet.pleg.relist_duration.sum',
'kubernetes.kubelet.pleg.relist_interval.count',
'kubernetes.kubelet.pleg.relist_interval.sum',
'kubernetes.kubelet.pod.start.duration.count',
'kubernetes.kubelet.pod.start.duration.sum',
'kubernetes.kubelet.pod.worker.start.duration.count',
'kubernetes.kubelet.pod.worker.start.duration.sum',
'kubernetes.kubelet.runtime.errors',
'kubernetes.kubelet.runtime.operations',
'kubernetes.kubelet.runtime.operations.duration.count',
'kubernetes.kubelet.runtime.operations.duration.sum',
'kubernetes.memory.capacity',
'kubernetes.memory.limits',
'kubernetes.memory.requests',
'kubernetes.pods.running',
'kubernetes.rest.client.latency.count',
'kubernetes.rest.client.latency.sum',
'kubernetes.rest.client.requests',
'kubernetes.runtime.cpu.usage',
'kubernetes.runtime.memory.usage',
'kubernetes.runtime.memory.rss',
'kubernetes.node.filesystem.usage',
'kubernetes.node.filesystem.usage_pct',
'kubernetes.node.image.filesystem.usage',
'kubernetes.node.image.filesystem.usage_pct',
]
COMMON_TAGS = {
"kubernetes_pod_uid://c2319815-10d0-11e8-bd5a-42010af00137": ["pod_name:datadog-agent-jbm2k"],
"kubernetes_pod_uid://2edfd4d9-10ce-11e8-bd5a-42010af00137": ["pod_name:fluentd-gcp-v2.0.10-9q9t4"],
"kubernetes_pod_uid://2fdfd4d9-10ce-11e8-bd5a-42010af00137": ["pod_name:fluentd-gcp-v2.0.10-p13r3"],
'container_id://5741ed2471c0e458b6b95db40ba05d1a5ee168256638a0264f08703e48d76561': [
'kube_container_name:fluentd-gcp',
'kube_deployment:fluentd-gcp-v2.0.10',
],
'container_id://1d1f139dc1c9d49010512744df34740abcfaadf9930d3afd85afbf5fccfadbd6': [
'kube_container_name:init',
'kube_deployment:fluentd-gcp-v2.0.10',
'kube_namespace:default',
],
"container_id://580cb469826a10317fd63cc780441920f49913ae63918d4c7b19a72347645b05": [
'kube_container_name:prometheus-to-sd-exporter',
'kube_deployment:fluentd-gcp-v2.0.10',
],
'container_id://6941ed2471c0e458b6b95db40ba05d1a5ee168256638a0264f08703e48d76561': [
'kube_container_name:fluentd-gcp',
'kube_deployment:fluentd-gcp-v2.0.10',
],
"container_id://690cb469826a10317fd63cc780441920f49913ae63918d4c7b19a72347645b05": [
'kube_container_name:prometheus-to-sd-exporter',
'kube_deployment:fluentd-gcp-v2.0.10',
],
"container_id://5f93d91c7aee0230f77fbe9ec642dd60958f5098e76de270a933285c24dfdc6f": [
"pod_name:demo-app-success-c485bc67b-klj45"
],
"kubernetes_pod_uid://d2e71e36-10d0-11e8-bd5a-42010af00137": ['pod_name:dd-agent-q6hpw'],
"kubernetes_pod_uid://260c2b1d43b094af6d6b4ccba082c2db": [
'pod_name:kube-proxy-gke-haissam-default-pool-be5066f1-wnvn'
],
"kubernetes_pod_uid://24d6daa3-10d8-11e8-bd5a-42010af00137": ['pod_name:demo-app-success-c485bc67b-klj45'],
"container_id://f69aa93ce78ee11e78e7c75dc71f535567961740a308422dafebdb4030b04903": ['pod_name:pi-kff76'],
"kubernetes_pod_uid://12ceeaa9-33ca-11e6-ac8f-42010af00003": ['pod_name:dd-agent-ntepl'],
"container_id://32fc50ecfe24df055f6d56037acb966337eef7282ad5c203a1be58f2dd2fe743": ['pod_name:dd-agent-ntepl'],
"container_id://a335589109ce5506aa69ba7481fc3e6c943abd23c5277016c92dac15d0f40479": [
'kube_container_name:datadog-agent'
],
'container_id://80bd9ebe296615341c68d571e843d800fb4a75bef696d858065572ab4e49920c': [
'kube_container_name:running-init',
'kube_namespace:default',
],
"container_id://326b384481ca95204018e3e837c61e522b64a3b86c3804142a22b2d1db9dbd7b": [
'kube_container_name:datadog-agent'
],
"container_id://6d8c6a05731b52195998c438fdca271b967b171f6c894f11ba59aa2f4deff10c": ['pod_name:cassandra-0'],
"kubernetes_pod_uid://639980e5-2e6c-11ea-8bb1-42010a800074": [
'kube_namespace:default',
'kube_service:nginx',
'kube_stateful_set:web',
'namespace:default',
'persistentvolumeclaim:www-web-2',
'pod_phase:running',
],
"kubernetes_pod_uid://639980e5-2e6c-11ea-8bb1-42010a800075": [
'kube_namespace:default',
'kube_service:nginx',
'kube_stateful_set:web',
'namespace:default',
'persistentvolumeclaim:www-web-2',
'persistentvolumeclaim:www2-web-3',
'pod_phase:running',
],
'kubernetes_pod_uid://d2dfd16e-e829-4f66-91d5-f9233ca7332b': [
'pod_name:sidecar-second',
'kube_namespace:default',
],
'container_id://80bd9ebe296615341c68d571e843d800fb4a75bef696d858065572ab4e49920b': [
'kube_container_name:sidecar',
'pod_name:sidecar-second',
'kube_namespace:default',
],
}
WINDOWS_TAGS = {
'kubernetes_pod_uid://4740a3ec-392f-435f-80a4-b407a37463db': [
'kube_namespace:default',
'pod_name:windows-server-iis-6c68545d57-gwtn9',
],
'container_id://43dfa29d17d358cbdd0bfb290cf27ce82c4de0c88d22d7cac4b88c85de87efba': [
'kube_namespace:default',
'pod_name:windows-server-iis-6c68545d57-gwtn9',
'kube_container_name:windows-server-iis',
],
'kubernetes_pod_uid://8ddf0e3f-ac6c-4d44-87d7-0bc41f6729ec': [
'kube_namespace:default',
'pod_name:dd-datadog-lbvkl',
],
'container_id://a26b9c2c92e4ab03f34b84d03d91bed92259c859576535a3167aa32d39206dc2': [
'kube_namespace:default',
'pod_name:dd-datadog-lbvkl',
'kube_container_name:agent',
],
'container_id://98fb504eb0fab22ce9089d8b1cc172ccb2095ee11a00bacd244419b5c02ee635': [
'kube_namespace:default',
'pod_name:dd-datadog-lbvkl',
'kube_container_name:process-agent',
],
}
PROBE_TAGS = {
'container_id://2c3f5608164033a850c9acbbfdb7fffa6ce1f68feedb1b8dad99777373c35b16': [
'kube_namespace:kube-system',
'pod_name:kube-dns-c598bd956-wgf4n',
'kube_container_name:sidecar',
],
'container_id://b13f7638c80c98946900bdeabec06be564d203330f5bb706a40e6fa7466a674d': [
'kube_namespace:kube-system',
'pod_name:kube-dns-c598bd956-wgf4n',
'kube_container_name:kubedns',
],
'container_id://3102f0d9499c5cd0875225208e3d048e3a9d829f5cdd74758b2d79a429a579fa': [
'kube_namespace:kube-system',
'pod_name:fluentbit-gke-45gvm',
'kube_container_name:fluentbit-gke',
],
'container_id://efa5b57cc110de6d2ca3b4a0e12c0a378090530e5e2d0ba0882dffe9c5846067': [
'kube_namespace:kube-system',
'pod_name:fluentbit-gke-45gvm',
'kube_container_name:fluentbit',
],
'container_id://0d8eea0b23688a4c3fbc29828b455734b323d6aac085c88f8f112e296cd5b521': [
'kube_namespace:kube-system',
'pod_name:kube-dns-c598bd956-wgf4n',
'kube_container_name:dnsmasq',
],
'container_id://1669a6277ebb44aedd2790ba8bce83d21899ba85b1afde4330caf4a4161eee26': [
'kube_namespace:kube-system',
'pod_name:calico-node-9qkw7',
'kube_container_name:calico-node',
],
'container_id://c81dfc25dd24b538a880bfd0f807ba9ec1ff4541e8b8eb49a8d1afcdecc5ef59': [
'kube_namespace:default',
'pod_name:datadog-t9f28',
'kube_container_name:agent',
],
}
METRICS_WITH_DEVICE_TAG = {
'kubernetes.filesystem.usage': '/dev/sda1',
'kubernetes.io.read_bytes': '/dev/sda',
'kubernetes.io.write_bytes': '/dev/sda',
}
METRICS_WITH_INTERFACE_TAG = {
'kubernetes.network.rx_bytes': 'eth0',
'kubernetes.network.tx_bytes': 'eth0',
'kubernetes.network.rx_errors': 'eth0',
'kubernetes.network.tx_errors': 'eth0',
'kubernetes.network.rx_dropped': 'eth0',
'kubernetes.network.tx_dropped': 'eth0',
}
@pytest.fixture
def tagger():
from datadog_checks.base.stubs import tagger
tagger.reset()
tagger.set_tags(COMMON_TAGS)
return tagger
def mock_kubelet_check(
monkeypatch,
instances,
kube_version=KUBE_1_14,
stats_summary_fail=False,
pod_list='pods.json',
probes_available=None,
):
"""
Returns a check that uses mocked data for responses from prometheus endpoints, pod list,
and node spec.
"""
check = KubeletCheck('kubelet', {}, instances)
monkeypatch.setattr(check, 'retrieve_pod_list', mock.Mock(return_value=json.loads(mock_from_file(pod_list))))
mock_resp = mock.Mock(status_code=200, raise_for_status=mock.Mock(), json=mock.Mock(return_value=NODE_SPEC))
monkeypatch.setattr(check, '_retrieve_node_spec', mock.Mock(return_value=mock_resp))
if stats_summary_fail:
monkeypatch.setattr(check, '_retrieve_stats', mock.Mock(return_value={}))
else:
monkeypatch.setattr(
check, '_retrieve_stats', mock.Mock(return_value=json.loads(mock_from_file('stats_summary.json')))
)
monkeypatch.setattr(check, '_perform_kubelet_check', mock.Mock(return_value=None))
monkeypatch.setattr(check, 'compute_pod_expiration_datetime', mock.Mock(return_value=None))
if probes_available:
monkeypatch.setattr(check, '_probes_available', mock.Mock(return_value=True))
def mocked_poll(cadvisor_response, kubelet_response):
def _mocked_poll(*args, **kwargs):
scraper_config = args[0]
prometheus_url = scraper_config['prometheus_url']
if prometheus_url.endswith('/metrics/cadvisor'):
# Mock response for "/metrics/cadvisor"
content = mock_from_file(cadvisor_response)
elif prometheus_url.endswith('/metrics'):
# Mock response for "/metrics"
content = mock_from_file(kubelet_response)
elif prometheus_url.endswith('/metrics/probes'):
# Mock response for "/metrics/probes"
content = mock_from_file('probes.txt')
else:
raise Exception("Must be a valid endpoint")
attrs = {'close.return_value': True, 'iter_lines.return_value': content.split('\n'), 'content': content}
return mock.Mock(headers={'Content-Type': 'text/plain'}, **attrs)
return _mocked_poll
if kube_version == KUBE_POST_1_16:
monkeypatch.setattr(
check,
'poll',
mock.Mock(
side_effect=mocked_poll(
cadvisor_response='cadvisor_metrics_post_1_16.txt', kubelet_response='kubelet_metrics_1_14.txt'
)
),
)
elif kube_version == KUBE_1_14:
monkeypatch.setattr(
check,
'poll',
mock.Mock(
side_effect=mocked_poll(
cadvisor_response='cadvisor_metrics_pre_1_16.txt', kubelet_response='kubelet_metrics_1_14.txt'
)
),
)
elif kube_version == KUBE_PRE_1_14:
monkeypatch.setattr(
check,
'poll',
mock.Mock(
side_effect=mocked_poll(
cadvisor_response='cadvisor_metrics_pre_1_16.txt', kubelet_response='kubelet_metrics.txt'
)
),
)
elif kube_version == KUBE_1_21:
monkeypatch.setattr(
check,
'poll',
mock.Mock(
side_effect=mocked_poll(
cadvisor_response='cadvisor_metrics_1_21.txt', kubelet_response='kubelet_metrics_1_21.txt'
)
),
)
return check
def mock_from_file(fname):
with open(os.path.join(HERE, 'fixtures', fname)) as f:
return f.read()
def test_bad_config():
with pytest.raises(Exception):
KubeletCheck('kubelet', {}, [{}, {}])
def test_parse_quantity():
for raw, res in QUANTITIES.items():
assert KubeletCheck.parse_quantity(raw) == res
def test_kubelet_default_options():
check = KubeletCheck('kubelet', {}, [{}])
assert check.cadvisor_scraper_config['namespace'] == 'kubernetes'
assert check.kubelet_scraper_config['namespace'] == 'kubernetes'
assert check.probes_scraper_config['namespace'] == 'kubernetes'
assert isinstance(check.cadvisor_scraper_config, dict)
assert isinstance(check.kubelet_scraper_config, dict)
assert isinstance(check.probes_scraper_config, dict)
def test_kubelet_check_prometheus_instance_tags(monkeypatch, aggregator, tagger):
_test_kubelet_check_prometheus(
monkeypatch, aggregator, tagger, kube_version=KUBE_1_14, instance_tags=["instance:tag"]
)
def test_kubelet_check_prometheus_no_instance_tags(monkeypatch, aggregator, tagger):
_test_kubelet_check_prometheus(monkeypatch, aggregator, tagger, kube_version=KUBE_1_14, instance_tags=None)
def test_kubelet_check_prometheus_instance_tags_pre_1_14(monkeypatch, aggregator, tagger):
_test_kubelet_check_prometheus(
monkeypatch, aggregator, tagger, kube_version=KUBE_PRE_1_14, instance_tags=["instance:tag"]
)
def test_kubelet_check_prometheus_no_instance_tags_pre_1_14(monkeypatch, aggregator, tagger):
_test_kubelet_check_prometheus(monkeypatch, aggregator, tagger, kube_version=KUBE_PRE_1_14, instance_tags=None)
def test_kubelet_check_prometheus_instance_tags_1_21(monkeypatch, aggregator, tagger):
_test_kubelet_check_prometheus(
monkeypatch, aggregator, tagger, kube_version=KUBE_1_21, instance_tags=["instance:tag"]
)
def test_kubelet_check_prometheus_no_instance_tags_1_21(monkeypatch, aggregator, tagger):
_test_kubelet_check_prometheus(monkeypatch, aggregator, tagger, kube_version=KUBE_1_21, instance_tags=None)
def _test_kubelet_check_prometheus(monkeypatch, aggregator, tagger, kube_version, instance_tags):
instance = {}
if instance_tags:
instance["tags"] = instance_tags
check = mock_kubelet_check(monkeypatch, [instance], kube_version=kube_version)
monkeypatch.setattr(check, 'process_cadvisor', mock.Mock(return_value=None))
check.check(instance)
assert check.cadvisor_legacy_url is None
check.retrieve_pod_list.assert_called_once()
check._retrieve_node_spec.assert_called_once()
check._retrieve_stats.assert_called_once()
check._perform_kubelet_check.assert_called_once()
check.process_cadvisor.assert_not_called()
# called twice so pct metrics are guaranteed to be there
check.check(instance)
if kube_version != KUBE_1_21:
for metric in EXPECTED_METRICS_COMMON:
aggregator.assert_metric(metric)
if instance_tags:
for tag in instance_tags:
aggregator.assert_metric_has_tag(metric, tag)
if kube_version == KUBE_PRE_1_14:
prom_metrics = EXPECTED_METRICS_PROMETHEUS_PRE_1_14
if kube_version == KUBE_1_14:
prom_metrics = EXPECTED_METRICS_PROMETHEUS_1_14
if kube_version == KUBE_1_21:
prom_metrics = EXPECTED_METRICS_PROMETHEUS_1_21
for metric in prom_metrics:
aggregator.assert_metric(metric)
if instance_tags:
for tag in instance_tags:
aggregator.assert_metric_has_tag(metric, tag)
assert aggregator.metrics_asserted_pct == 100.0
def test_kubelet_credentials_update(monkeypatch, aggregator):
instance = {
'kubelet_metrics_endpoint': 'http://10.8.0.1:10255/metrics',
'cadvisor_metrics_endpoint': 'http://10.8.0.1:10255/metrics/cadvisor',
}
check = mock_kubelet_check(monkeypatch, [instance], kube_version=None)
get = mock.MagicMock(
status_code=200, iter_lines=lambda **kwargs: mock_from_file('kubelet_metrics_1_14.txt').splitlines()
)
with mock.patch('requests.get', return_value=get):
check.check(instance)
assert check._http_handlers[instance['kubelet_metrics_endpoint']].options['verify'] is True
assert check._http_handlers[instance['cadvisor_metrics_endpoint']].options['verify'] is True
get = mock.MagicMock(
status_code=200, iter_lines=lambda **kwargs: mock_from_file('kubelet_metrics_1_14.txt').splitlines()
)
kubelet_conn_info = {'url': 'http://127.0.0.1:10255', 'ca_cert': False}
with mock.patch('requests.get', return_value=get), mock.patch(
'datadog_checks.kubelet.kubelet.get_connection_info', return_value=kubelet_conn_info
):
check.check(instance)
assert check._http_handlers[instance['kubelet_metrics_endpoint']].options['verify'] is False
assert check._http_handlers[instance['cadvisor_metrics_endpoint']].options['verify'] is False
def test_prometheus_cpu_summed(monkeypatch, aggregator, tagger):
check = mock_kubelet_check(monkeypatch, [{}])
monkeypatch.setattr(check, 'rate', mock.Mock())
check.check({"cadvisor_metrics_endpoint": "http://dummy/metrics/cadvisor", "kubelet_metrics_endpoint": ""})
# Make sure we submit the summed rates correctly for containers:
# - fluentd-gcp-v2.0.10-9q9t4 uses two cpus, we need to sum (1228.32 + 825.32) * 10**9 = 2053640000000
# - demo-app-success-c485bc67b-klj45 is mono-threaded, we submit 7.756358313 * 10**9 = 7756358313
#
calls = [
mock.call(
'kubernetes.cpu.usage.total',
2053640000000.0,
['kube_container_name:fluentd-gcp', 'kube_deployment:fluentd-gcp-v2.0.10'],
),
mock.call('kubernetes.cpu.usage.total', 7756358313.0, ['pod_name:demo-app-success-c485bc67b-klj45']),
]
check.rate.assert_has_calls(calls, any_order=True)
# Make sure the per-core metrics are not submitted
bad_calls = [
mock.call(
'kubernetes.cpu.usage.total',
1228320000000.0,
['kube_container_name:fluentd-gcp', 'kube_deployment:fluentd-gcp-v2.0.10'],
),
mock.call(
'kubernetes.cpu.usage.total',
825320000000.0,
['kube_container_name:fluentd-gcp', 'kube_deployment:fluentd-gcp-v2.0.10'],
),
]
for c in bad_calls:
assert c not in check.rate.mock_calls
def test_prometheus_net_summed(monkeypatch, aggregator, tagger):
check = mock_kubelet_check(monkeypatch, [{}])
monkeypatch.setattr(check, 'rate', mock.Mock())
check.check({"cadvisor_metrics_endpoint": "http://dummy/metrics/cadvisor", "kubelet_metrics_endpoint": ""})
# Make sure we submit the summed rates correctly for pods:
# - dd-agent-q6hpw has two interfaces, we need to sum (1.2638051777 + 2.2638051777) * 10**10 = 35276103554
# - fluentd-gcp-v2.0.10-9q9t4 has one interface only, we submit 5.8107648 * 10**07 = 58107648
#
calls = [
mock.call('kubernetes.network.rx_bytes', 35276103554.0, ['pod_name:dd-agent-q6hpw', 'interface:eth0']),
mock.call('kubernetes.network.rx_bytes', 58107648.0, ['pod_name:fluentd-gcp-v2.0.10-9q9t4', 'interface:eth0']),
]
check.rate.assert_has_calls(calls, any_order=True)
bad_calls = [
# Make sure the per-interface metrics are not submitted
mock.call('kubernetes.network.rx_bytes', 12638051777.0, ['pod_name:dd-agent-q6hpw']),
mock.call('kubernetes.network.rx_bytes', 22638051777.0, ['pod_name:dd-agent-q6hpw']),
# Make sure hostNetwork pod metrics are not submitted, test with and without sum to be sure
mock.call(
'kubernetes.network.rx_bytes',
(4917138204.0 + 698882782.0),
['pod_name:kube-proxy-gke-haissam-default-pool-be5066f1-wnvn'],
),
mock.call(
'kubernetes.network.rx_bytes', 4917138204.0, ['pod_name:kube-proxy-gke-haissam-default-pool-be5066f1-wnvn']
),
mock.call(
'kubernetes.network.rx_bytes', 698882782.0, ['pod_name:kube-proxy-gke-haissam-default-pool-be5066f1-wnvn']
),
]
for c in bad_calls:
assert c not in check.rate.mock_calls
def test_prometheus_filtering(monkeypatch, aggregator):
# Let's intercept the container_cpu_usage_seconds_total
# metric to make sure no sample with an empty pod (k8s >= 1.16)
# or pod_name (k8s < 1.16) label goes through input filtering
# 12 out of the 45 samples should pass through the filter for k8s < 1.16
# 27 out of 31 for k8s >= 1.16
method_name = "datadog_checks.kubelet.prometheus.CadvisorPrometheusScraperMixin.container_cpu_usage_seconds_total"
with mock.patch(method_name) as mock_method:
# k8s >= 1.16
check = mock_kubelet_check(monkeypatch, [{}], kube_version=KUBE_POST_1_16)
check.check({"cadvisor_metrics_endpoint": "http://dummy/metrics/cadvisor", "kubelet_metrics_endpoint": ""})
mock_method.assert_called_once()
metric = mock_method.call_args[0][0]
assert len(metric.samples) == 27
for sample in metric.samples:
assert sample.name == "container_cpu_usage_seconds_total"
assert sample.labels["pod"] != ""
with mock.patch(method_name) as mock_method:
# k8s < 1.16
check = mock_kubelet_check(monkeypatch, [{}])
check.check({"cadvisor_metrics_endpoint": "http://dummy/metrics/cadvisor", "kubelet_metrics_endpoint": ""})
mock_method.assert_called_once()
metric = mock_method.call_args[0][0]
assert len(metric.samples) == 12
for sample in metric.samples:
assert sample.name == "container_cpu_usage_seconds_total"
assert sample.labels["pod_name"] != ""
def test_ignore_metrics(monkeypatch, aggregator):
check = mock_kubelet_check(monkeypatch, [{"ignore_metrics": ["container_network_[Aa-zZ]*_bytes_total"]}])
check.check({"cadvisor_metrics_endpoint": "http://dummy/metrics/cadvisor", "kubelet_metrics_endpoint": ""})
check._perform_kubelet_check.assert_called_once()
aggregator.assert_metric('kubernetes.network.tx_dropped') # this metric is not filtered out by the regex
assert len(aggregator.metrics('kubernetes.network.rx_bytes')) == 0 # this metric is disabled
assert len(aggregator.metrics('kubernetes.network.tx_bytes')) == 0 # this metric is disabled
def test_kubelet_check_instance_config(monkeypatch):
def mock_kubelet_check_no_prom():
check = mock_kubelet_check(monkeypatch, [{}])
monkeypatch.setattr(check, 'process', mock.Mock(return_value=None))
monkeypatch.setattr(check, 'process_cadvisor', mock.Mock(return_value=None))
return check
check = mock_kubelet_check_no_prom()
check.check({"cadvisor_port": 0, "cadvisor_metrics_endpoint": "", "kubelet_metrics_endpoint": ""})
assert check.cadvisor_legacy_url is None
check.retrieve_pod_list.assert_called_once()
check._retrieve_node_spec.assert_called_once()
check._perform_kubelet_check.assert_called_once()
check.process_cadvisor.assert_not_called()
check = mock_kubelet_check_no_prom()
check.check({"cadvisor_port": 0, "metrics_endpoint": "", "kubelet_metrics_endpoint": "http://dummy"})
def test_report_pods_running(monkeypatch, tagger):
check = KubeletCheck('kubelet', {}, [{}])
monkeypatch.setattr(check, 'retrieve_pod_list', mock.Mock(return_value=json.loads(mock_from_file('pods.json'))))
monkeypatch.setattr(check, 'gauge', mock.Mock())
pod_list = check.retrieve_pod_list()
check._report_pods_running(pod_list, [])
calls = [
mock.call('kubernetes.pods.running', 1, ["pod_name:fluentd-gcp-v2.0.10-9q9t4"]),
mock.call('kubernetes.pods.running', 1, ["pod_name:fluentd-gcp-v2.0.10-p13r3"]),
mock.call('kubernetes.pods.running', 1, ['pod_name:demo-app-success-c485bc67b-klj45']),
mock.call('kubernetes.pods.running', 1, ['kube_namespace:default', 'pod_name:sidecar-second']),
mock.call(
'kubernetes.containers.running',
2,
["kube_container_name:fluentd-gcp", "kube_deployment:fluentd-gcp-v2.0.10"],
),
mock.call(
'kubernetes.containers.running',
2,
["kube_container_name:prometheus-to-sd-exporter", "kube_deployment:fluentd-gcp-v2.0.10"],
),
mock.call('kubernetes.containers.running', 1, ['pod_name:demo-app-success-c485bc67b-klj45']),
mock.call(
'kubernetes.containers.running',
1,
['kube_container_name:running-init', 'kube_namespace:default'],
),
mock.call(
'kubernetes.containers.running',
1,
['kube_container_name:sidecar', 'kube_namespace:default', 'pod_name:sidecar-second'],
),
]
check.gauge.assert_has_calls(calls, any_order=True)
# Make sure non running container/pods are not sent
bad_calls = [
mock.call('kubernetes.pods.running', 1, ['pod_name:dd-agent-q6hpw']),
mock.call('kubernetes.containers.running', 1, ['pod_name:dd-agent-q6hpw']),
mock.call(
'kubernetes.containers.running',
1,
["kube_container_name:init", "kube_deployment:fluentd-gcp-v2.0.10"],
),
]
for c in bad_calls:
assert c not in check.gauge.mock_calls
def test_report_pods_running_none_ids(monkeypatch, tagger):
# Make sure the method is resilient to inconsistent podlists
podlist = json.loads(mock_from_file('pods.json'))
podlist["items"][0]['metadata']['uid'] = None
podlist["items"][1]['status']['containerStatuses'][0]['containerID'] = None
check = KubeletCheck('kubelet', {}, [{}])
monkeypatch.setattr(check, 'retrieve_pod_list', mock.Mock(return_value=podlist))
monkeypatch.setattr(check, 'gauge', mock.Mock())
pod_list = check.retrieve_pod_list()
check._report_pods_running(pod_list, [])
calls = [
mock.call('kubernetes.pods.running', 1, ["pod_name:fluentd-gcp-v2.0.10-9q9t4"]),
mock.call(
'kubernetes.containers.running',
2,
["kube_container_name:prometheus-to-sd-exporter", "kube_deployment:fluentd-gcp-v2.0.10"],
),
]
check.gauge.assert_has_calls(calls, any_order=True)
def test_report_container_spec_metrics(monkeypatch, tagger):
check = KubeletCheck('kubelet', {}, [{}])
monkeypatch.setattr(check, 'retrieve_pod_list', mock.Mock(return_value=json.loads(mock_from_file('pods.json'))))
monkeypatch.setattr(check, 'gauge', mock.Mock())
attrs = {'is_excluded.return_value': False}
check.pod_list_utils = mock.Mock(**attrs)
pod_list = check.retrieve_pod_list()
instance_tags = ["one:1", "two:2"]
check._report_container_spec_metrics(pod_list, instance_tags)
calls = [
mock.call(
'kubernetes.cpu.requests',
0.1,
['kube_container_name:fluentd-gcp', 'kube_deployment:fluentd-gcp-v2.0.10'] + instance_tags,
),
mock.call(
'kubernetes.memory.requests',
209715200.0,
['kube_container_name:fluentd-gcp', 'kube_deployment:fluentd-gcp-v2.0.10'] + instance_tags,
),
mock.call(
'kubernetes.memory.limits',
314572800.0,
['kube_container_name:fluentd-gcp', 'kube_deployment:fluentd-gcp-v2.0.10'] + instance_tags,
),
mock.call('kubernetes.cpu.requests', 0.1, ['kube_container_name:datadog-agent'] + instance_tags),
mock.call('kubernetes.cpu.requests', 0.1, ['kube_container_name:datadog-agent'] + instance_tags),
mock.call('kubernetes.memory.requests', 134217728.0, ['kube_container_name:datadog-agent'] + instance_tags),
mock.call('kubernetes.cpu.limits', 0.25, ['kube_container_name:datadog-agent'] + instance_tags),
mock.call('kubernetes.memory.limits', 536870912.0, ['kube_container_name:datadog-agent'] + instance_tags),
mock.call('kubernetes.cpu.requests', 0.1, ["pod_name:demo-app-success-c485bc67b-klj45"] + instance_tags),
# init container
mock.call(
'kubernetes.cpu.requests',
0.05,
['kube_container_name:running-init', 'kube_namespace:default'] + instance_tags,
),
mock.call(
'kubernetes.memory.requests',
104857600.0,
['kube_container_name:running-init', 'kube_namespace:default'] + instance_tags,
),
mock.call(
'kubernetes.memory.limits',
157286400.0,
['kube_container_name:running-init', 'kube_namespace:default'] + instance_tags,
),
]
if any(('pod_name:pi-kff76' in e for e in [x[0][2] for x in check.gauge.call_args_list])):
raise AssertionError("kubernetes.cpu.requests was submitted for a non-running pod")
if any(('kube_container_name:init' in e for e in [x[0][2] for x in check.gauge.call_args_list])):
raise AssertionError("kubernetes.cpu.requests was submitted for a terminated init container")
check.gauge.assert_has_calls(calls, any_order=True)
def test_report_container_state_metrics(monkeypatch, tagger):
check = KubeletCheck('kubelet', {}, [{}])
check.pod_list_url = "dummyurl"
monkeypatch.setattr(
check,
'perform_kubelet_query',
mock.Mock(return_value=MockResponse(file_path=os.path.join(HERE, 'fixtures', 'pods_crashed.json'))),
)
monkeypatch.setattr(check, 'compute_pod_expiration_datetime', mock.Mock(return_value=None))
monkeypatch.setattr(check, 'gauge', mock.Mock())
attrs = {'is_excluded.return_value': False}
check.pod_list_utils = mock.Mock(**attrs)
pod_list = check.retrieve_pod_list()
instance_tags = ["one:1", "two:2"]
check._report_container_state_metrics(pod_list, instance_tags)
calls = [
mock.call(
'kubernetes.containers.last_state.terminated',
1,
['kube_container_name:fluentd-gcp', 'kube_deployment:fluentd-gcp-v2.0.10']
+ instance_tags
+ ['reason:OOMKilled'],
),
mock.call(
'kubernetes.containers.state.waiting',
1,
['kube_container_name:prometheus-to-sd-exporter', 'kube_deployment:fluentd-gcp-v2.0.10']
+ instance_tags
+ ['reason:CrashLoopBackOff'],
),
mock.call(
'kubernetes.containers.restarts',
1,
['kube_container_name:fluentd-gcp', 'kube_deployment:fluentd-gcp-v2.0.10'] + instance_tags,
),
mock.call(
'kubernetes.containers.restarts',
0,
['kube_container_name:prometheus-to-sd-exporter', 'kube_deployment:fluentd-gcp-v2.0.10'] + instance_tags,
),
mock.call('kubernetes.containers.restarts', 0, ['kube_container_name:datadog-agent'] + instance_tags),
mock.call('kubernetes.containers.restarts', 0, ['kube_container_name:datadog-agent'] + instance_tags),
# init container
mock.call(
'kubernetes.containers.restarts',
0,
['kube_container_name:init', 'kube_deployment:fluentd-gcp-v2.0.10', 'kube_namespace:default']
+ instance_tags,
),
]
check.gauge.assert_has_calls(calls, any_order=True)
container_state_gauges = [
x[0][2] for x in check.gauge.call_args_list if x[0][0].startswith('kubernetes.containers.state')
]
if any(('reason:TransientReason' in e for e in container_state_gauges)):
raise AssertionError('kubernetes.containers.state.* was submitted with a transient reason')
if any((not any(x for x in e if x.startswith('reason:')) for e in container_state_gauges)):
raise AssertionError('kubernetes.containers.state.* was submitted without a reason')
def test_no_tags_no_metrics(monkeypatch, aggregator, tagger):
# Reset tagger without tags
tagger.reset()
tagger.set_tags({})
check = mock_kubelet_check(monkeypatch, [{}])
check.check({"cadvisor_metrics_endpoint": "http://dummy/metrics/cadvisor", "kubelet_metrics_endpoint": ""})
# Test that we get only the node related metrics (no calls to the tagger for these ones)
aggregator.assert_metric('kubernetes.memory.capacity')
aggregator.assert_metric('kubernetes.cpu.capacity')
aggregator.assert_metric('kubernetes.runtime.cpu.usage')
aggregator.assert_metric('kubernetes.runtime.memory.usage')
aggregator.assert_metric('kubernetes.runtime.memory.rss')
aggregator.assert_metric('kubernetes.kubelet.cpu.usage')
aggregator.assert_metric('kubernetes.kubelet.memory.usage')
aggregator.assert_metric('kubernetes.kubelet.memory.rss')
aggregator.assert_metric('kubernetes.apiserver.certificate.expiration.count')
aggregator.assert_metric('kubernetes.apiserver.certificate.expiration.sum')
aggregator.assert_metric('kubernetes.go_goroutines')
aggregator.assert_metric('kubernetes.go_threads')
aggregator.assert_metric('kubernetes.kubelet.container.log_filesystem.used_bytes')
aggregator.assert_metric('kubernetes.kubelet.docker.errors')
aggregator.assert_metric('kubernetes.kubelet.docker.operations')
aggregator.assert_metric('kubernetes.kubelet.docker.operations.duration.count')
aggregator.assert_metric('kubernetes.kubelet.docker.operations.duration.quantile')
aggregator.assert_metric('kubernetes.kubelet.docker.operations.duration.sum')
aggregator.assert_metric('kubernetes.kubelet.evictions')
aggregator.assert_metric('kubernetes.kubelet.network_plugin.latency.count')
aggregator.assert_metric('kubernetes.kubelet.network_plugin.latency.sum')
aggregator.assert_metric('kubernetes.kubelet.pleg.relist_duration.count')
aggregator.assert_metric('kubernetes.kubelet.pleg.relist_duration.sum')
aggregator.assert_metric('kubernetes.kubelet.pleg.relist_interval.count')
aggregator.assert_metric('kubernetes.kubelet.pleg.relist_interval.sum')
aggregator.assert_metric('kubernetes.kubelet.pod.start.duration.count')
aggregator.assert_metric('kubernetes.kubelet.pod.start.duration.sum')
aggregator.assert_metric('kubernetes.kubelet.pod.worker.duration.count')
aggregator.assert_metric('kubernetes.kubelet.pod.worker.duration.sum')
aggregator.assert_metric('kubernetes.kubelet.pod.worker.start.duration.count')
aggregator.assert_metric('kubernetes.kubelet.pod.worker.start.duration.sum')
aggregator.assert_metric('kubernetes.kubelet.runtime.errors')
aggregator.assert_metric('kubernetes.kubelet.runtime.operations')
aggregator.assert_metric('kubernetes.kubelet.runtime.operations.duration.count')
aggregator.assert_metric('kubernetes.kubelet.runtime.operations.duration.quantile')
aggregator.assert_metric('kubernetes.kubelet.runtime.operations.duration.sum')
aggregator.assert_metric('kubernetes.kubelet.volume.stats.available_bytes')
aggregator.assert_metric('kubernetes.kubelet.volume.stats.capacity_bytes')
aggregator.assert_metric('kubernetes.kubelet.volume.stats.inodes')
aggregator.assert_metric('kubernetes.kubelet.volume.stats.inodes_free')
aggregator.assert_metric('kubernetes.kubelet.volume.stats.inodes_used')
aggregator.assert_metric('kubernetes.kubelet.volume.stats.used_bytes')
aggregator.assert_metric('kubernetes.rest.client.latency.count')
aggregator.assert_metric('kubernetes.rest.client.latency.sum')
aggregator.assert_metric('kubernetes.rest.client.requests')
aggregator.assert_metric('kubernetes.node.filesystem.usage')
aggregator.assert_metric('kubernetes.node.filesystem.usage_pct')
aggregator.assert_metric('kubernetes.node.image.filesystem.usage')
aggregator.assert_metric('kubernetes.node.image.filesystem.usage_pct')
aggregator.assert_all_metrics_covered()
def test_static_pods(monkeypatch, aggregator, tagger):
tagger.reset()
tagger.set_tags(
{
"kubernetes_pod_uid://260c2b1d43b094af6d6b4ccba082c2db": [
'pod_name:kube-proxy-gke-haissam-default-pool-be5066f1-wnvn'
]
}
)
check = mock_kubelet_check(monkeypatch, [{}])
check.check({"cadvisor_metrics_endpoint": "http://dummy/metrics/cadvisor", "kubelet_metrics_endpoint": ""})
# Test that we get metrics for this static pod
aggregator.assert_metric(
'kubernetes.cpu.user.total',
109.76,
['kube_container_name:kube-proxy', 'pod_name:kube-proxy-gke-haissam-default-pool-be5066f1-wnvn'],
)
def test_pod_expiration(monkeypatch, aggregator, tagger):