From c14424f3cef9877d96c555c5bfeebc1775f99027 Mon Sep 17 00:00:00 2001 From: nam Date: Mon, 2 Aug 2021 10:37:06 +0200 Subject: [PATCH 1/5] [kubernetes_state] add sts count --- .../tests/fixtures/prometheus/ksm.txt | 4 ++++ kubernetes_state/CHANGELOG.md | 4 ++++ .../kubernetes_state/kubernetes_state.py | 5 +++++ kubernetes_state/metadata.csv | 1 + kubernetes_state/tests/test_kubernetes_state.py | 12 ++++++++++++ 5 files changed, 26 insertions(+) diff --git a/datadog_checks_base/tests/fixtures/prometheus/ksm.txt b/datadog_checks_base/tests/fixtures/prometheus/ksm.txt index dcaa8b6ff8490..634d02b02cea5 100644 --- a/datadog_checks_base/tests/fixtures/prometheus/ksm.txt +++ b/datadog_checks_base/tests/fixtures/prometheus/ksm.txt @@ -867,3 +867,7 @@ kube_service_labels{label_addonmanager_kubernetes_io_mode="Reconcile",label_kube kube_service_labels{label_addonmanager_kubernetes_io_mode="Reconcile",label_k8s_app="glbc",label_kubernetes_io_cluster_service="true",label_kubernetes_io_name="GLBCDefaultBackend",namespace="kube-system",service="default-http-backend"} 1 kube_service_labels{label_addonmanager_kubernetes_io_mode="Reconcile",label_k8s_app="kube-dns",label_kubernetes_io_cluster_service="true",label_kubernetes_io_name="KubeDNS",namespace="kube-system",service="kube-dns"} 1 kube_service_labels{label_app="kube-state-metrics",label_chart="kube-state-metrics-0.5.0",label_heritage="Tiller",label_release="ungaged-panther",namespace="default",service="ungaged-panther-kube-state-metrics"} 1 +# HELP kube_statefulset_status_observed_generation The generation observed by the StatefulSet controller. +# TYPE kube_statefulset_status_observed_generation gauge +kube_statefulset_status_observed_generation{namespace="datadog-agent",statefulset="web"} 1 +kube_statefulset_status_observed_generation{namespace="kube-system",statefulset="mysql"} 1 \ No newline at end of file diff --git a/kubernetes_state/CHANGELOG.md b/kubernetes_state/CHANGELOG.md index 35cb80ef5382e..a848cc62a0ae5 100644 --- a/kubernetes_state/CHANGELOG.md +++ b/kubernetes_state/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG - kubernetes_state +## 5.7.2 / 2021-08-02 + +* [Added] KSM `kubernetes_state.statefulset.count` metric. See [#tbd](tbd). + ## 5.7.1 / 2021-06-03 * [Fixed] Fix `node.by_condition` metric. See [#9467](https://github.com/DataDog/integrations-core/pull/9467). diff --git a/kubernetes_state/datadog_checks/kubernetes_state/kubernetes_state.py b/kubernetes_state/datadog_checks/kubernetes_state/kubernetes_state.py index 0be95709406cb..7fa62a0533506 100644 --- a/kubernetes_state/datadog_checks/kubernetes_state/kubernetes_state.py +++ b/kubernetes_state/datadog_checks/kubernetes_state/kubernetes_state.py @@ -105,6 +105,10 @@ def __init__(self, name, init_config, instances): 'metric_name': 'deployment.count', 'allowed_labels': ['namespace'], }, + 'kube_statefulset_status_observed_generation': { + 'metric_name': 'statefulset.count', + 'allowed_labels': ['namespace'], + }, } self.METRIC_TRANSFORMERS = { @@ -131,6 +135,7 @@ def __init__(self, name, init_config, instances): 'kube_replicaset_owner': self.count_objects_by_tags, 'kube_job_owner': self.count_objects_by_tags, 'kube_deployment_status_observed_generation': self.count_objects_by_tags, + 'kube_statefulset_status_observed_generation': self.count_objects_by_tags, } # Handling cron jobs succeeded/failed counts diff --git a/kubernetes_state/metadata.csv b/kubernetes_state/metadata.csv index 7670684fbe32c..a962b3a029740 100644 --- a/kubernetes_state/metadata.csv +++ b/kubernetes_state/metadata.csv @@ -100,6 +100,7 @@ kubernetes_state.resourcequota.requests.storage.limit,gauge,,byte,,Hard limit on kubernetes_state.resourcequota.limits.cpu.limit,gauge,,cpu,,Hard limit on the sum of CPU core limits for a resource quota,0,kubernetes,k8s_state.resourcequota.limits.cpu.limit kubernetes_state.resourcequota.limits.memory.limit,gauge,,byte,,Hard limit on the sum of memory bytes limits for a resource quota,0,kubernetes,k8s_state.resourcequota.limits.mem.limit kubernetes_state.service.count,gauge,,,,Sum by namespace and type to count active services,0,kubernetes,k8s_state.svc.count +kubernetes_state.statefulset.count,gauge,,,,The number of statefulsets,0,kubernetes,k8s_state.statefulset.count kubernetes_state.statefulset.replicas,gauge,,,,The number of replicas per statefulset,0,kubernetes,k8s_state.statefulset.replicas kubernetes_state.statefulset.replicas_desired,gauge,,,,The number of desired replicas per statefulset,0,kubernetes,k8s_state.statefulset.replicas_desired kubernetes_state.statefulset.replicas_current,gauge,,,,The number of current replicas per StatefulSet,0,kubernetes,k8s_state.statefulset.replicas_current diff --git a/kubernetes_state/tests/test_kubernetes_state.py b/kubernetes_state/tests/test_kubernetes_state.py index c71783131b80a..0153e67c3b3dc 100644 --- a/kubernetes_state/tests/test_kubernetes_state.py +++ b/kubernetes_state/tests/test_kubernetes_state.py @@ -441,6 +441,18 @@ def test_update_kube_state_metrics(aggregator, instance, check): value=2, ) + # statefulset count + aggregator.assert_metric( + NAMESPACE + '.statefulset.count', + tags=['namespace:default', 'optional:tag1'], + value=2, + ) + aggregator.assert_metric( + NAMESPACE + '.statefulset.count', + tags=['namespace:kube-system', 'optional:tag1'], + value=2, + ) + for metric in METRICS: aggregator.assert_metric(metric, hostname=HOSTNAMES.get(metric, None)) for tag in TAGS.get(metric, []): From ae169844bfc17deff781042d552d8646e14b0dca Mon Sep 17 00:00:00 2001 From: nam Date: Mon, 2 Aug 2021 10:57:26 +0200 Subject: [PATCH 2/5] [kubernetes_state] add sts count --- datadog_checks_base/tests/fixtures/prometheus/ksm.txt | 6 +----- .../datadog_checks/kubernetes_state/kubernetes_state.py | 1 - kubernetes_state/tests/fixtures/prometheus.txt | 6 ++++++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/datadog_checks_base/tests/fixtures/prometheus/ksm.txt b/datadog_checks_base/tests/fixtures/prometheus/ksm.txt index 634d02b02cea5..c7732aedd560c 100644 --- a/datadog_checks_base/tests/fixtures/prometheus/ksm.txt +++ b/datadog_checks_base/tests/fixtures/prometheus/ksm.txt @@ -866,8 +866,4 @@ kube_service_labels{label_addonmanager_kubernetes_io_mode="Reconcile",label_k8s_ kube_service_labels{label_addonmanager_kubernetes_io_mode="Reconcile",label_kubernetes_io_cluster_service="true",label_kubernetes_io_name="Heapster",namespace="kube-system",service="heapster"} 1 kube_service_labels{label_addonmanager_kubernetes_io_mode="Reconcile",label_k8s_app="glbc",label_kubernetes_io_cluster_service="true",label_kubernetes_io_name="GLBCDefaultBackend",namespace="kube-system",service="default-http-backend"} 1 kube_service_labels{label_addonmanager_kubernetes_io_mode="Reconcile",label_k8s_app="kube-dns",label_kubernetes_io_cluster_service="true",label_kubernetes_io_name="KubeDNS",namespace="kube-system",service="kube-dns"} 1 -kube_service_labels{label_app="kube-state-metrics",label_chart="kube-state-metrics-0.5.0",label_heritage="Tiller",label_release="ungaged-panther",namespace="default",service="ungaged-panther-kube-state-metrics"} 1 -# HELP kube_statefulset_status_observed_generation The generation observed by the StatefulSet controller. -# TYPE kube_statefulset_status_observed_generation gauge -kube_statefulset_status_observed_generation{namespace="datadog-agent",statefulset="web"} 1 -kube_statefulset_status_observed_generation{namespace="kube-system",statefulset="mysql"} 1 \ No newline at end of file +kube_service_labels{label_app="kube-state-metrics",label_chart="kube-state-metrics-0.5.0",label_heritage="Tiller",label_release="ungaged-panther",namespace="default",service="ungaged-panther-kube-state-metrics"} 1 \ No newline at end of file diff --git a/kubernetes_state/datadog_checks/kubernetes_state/kubernetes_state.py b/kubernetes_state/datadog_checks/kubernetes_state/kubernetes_state.py index 7fa62a0533506..dd7370f45a044 100644 --- a/kubernetes_state/datadog_checks/kubernetes_state/kubernetes_state.py +++ b/kubernetes_state/datadog_checks/kubernetes_state/kubernetes_state.py @@ -328,7 +328,6 @@ def _create_kubernetes_state_prometheus_instance(self, instance): 'kube_replicationcontroller_metadata_generation', 'kube_replicationcontroller_status_observed_generation', 'kube_statefulset_metadata_generation', - 'kube_statefulset_status_observed_generation', 'kube_hpa_metadata_generation', # kube_node_status_phase has no use case as a service check 'kube_node_status_phase', diff --git a/kubernetes_state/tests/fixtures/prometheus.txt b/kubernetes_state/tests/fixtures/prometheus.txt index 59caacd6cf928..5d2d41c4abc60 100644 --- a/kubernetes_state/tests/fixtures/prometheus.txt +++ b/kubernetes_state/tests/fixtures/prometheus.txt @@ -31,6 +31,12 @@ kube_cronjob_status_active{cronjob="hello",namespace="default"} 0 # HELP kube_cronjob_status_last_schedule_time LastScheduleTime keeps information of when was the last time the job was successfully scheduled. # TYPE kube_cronjob_status_last_schedule_time gauge kube_cronjob_status_last_schedule_time{cronjob="hello",namespace="default"} 1.50999846e+09 +# HELP kube_statefulset_status_observed_generation The generation observed by the StatefulSet controller. +# TYPE kube_statefulset_status_observed_generation gauge +kube_statefulset_status_observed_generation{namespace="default",statefulset="web"} 1 +kube_statefulset_status_observed_generation{namespace="default",statefulset="nginx"} 4 +kube_statefulset_status_observed_generation{namespace="kube-system",statefulset="mysql"} 1 +kube_statefulset_status_observed_generation{namespace="kube-system",statefulset="redis"} 2 # HELP kube_statefulset_status_replicas The number of replicas per StatefulSet. # TYPE kube_statefulset_status_replicas gauge kube_statefulset_status_replicas{namespace="ns3",statefulset="statefulset3"} 7 From a7c7aa8f7826089bc7a6a13dbed47b8a090f0946 Mon Sep 17 00:00:00 2001 From: nam Date: Mon, 2 Aug 2021 11:02:09 +0200 Subject: [PATCH 3/5] [fix] [test] telemtry size --- kubernetes_state/tests/test_kubernetes_state.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kubernetes_state/tests/test_kubernetes_state.py b/kubernetes_state/tests/test_kubernetes_state.py index 0153e67c3b3dc..9c96f0c5e7408 100644 --- a/kubernetes_state/tests/test_kubernetes_state.py +++ b/kubernetes_state/tests/test_kubernetes_state.py @@ -885,9 +885,9 @@ def test_telemetry(aggregator, instance): for _ in range(2): check.check(instance) - aggregator.assert_metric(NAMESPACE + '.telemetry.payload.size', tags=['optional:tag1'], value=93895.0) - aggregator.assert_metric(NAMESPACE + '.telemetry.metrics.processed.count', tags=['optional:tag1'], value=994.0) - aggregator.assert_metric(NAMESPACE + '.telemetry.metrics.input.count', tags=['optional:tag1'], value=1326.0) + aggregator.assert_metric(NAMESPACE + '.telemetry.payload.size', tags=['optional:tag1'], value=94412.0) + aggregator.assert_metric(NAMESPACE + '.telemetry.metrics.processed.count', tags=['optional:tag1'], value=1002.0) + aggregator.assert_metric(NAMESPACE + '.telemetry.metrics.input.count', tags=['optional:tag1'], value=1334.0) aggregator.assert_metric(NAMESPACE + '.telemetry.metrics.blacklist.count', tags=['optional:tag1'], value=24.0) aggregator.assert_metric(NAMESPACE + '.telemetry.metrics.ignored.count', tags=['optional:tag1'], value=332.0) aggregator.assert_metric( From e9f2eeabde65af15411718dbddc4f2af1425bdfb Mon Sep 17 00:00:00 2001 From: nam Date: Mon, 2 Aug 2021 11:02:59 +0200 Subject: [PATCH 4/5] [kubernetes_state] update pr link --- kubernetes_state/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubernetes_state/CHANGELOG.md b/kubernetes_state/CHANGELOG.md index a848cc62a0ae5..50d61a61dc572 100644 --- a/kubernetes_state/CHANGELOG.md +++ b/kubernetes_state/CHANGELOG.md @@ -2,7 +2,7 @@ ## 5.7.2 / 2021-08-02 -* [Added] KSM `kubernetes_state.statefulset.count` metric. See [#tbd](tbd). +* [Added] KSM `kubernetes_state.statefulset.count` metric. See [#9813](https://github.com/DataDog/integrations-core/pull/9813). ## 5.7.1 / 2021-06-03 From 2b9b016590eae7723b306c72903fd1c44f432253 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Mon, 2 Aug 2021 16:35:45 +0200 Subject: [PATCH 5/5] Update kubernetes_state/CHANGELOG.md Co-authored-by: Florian Veaux --- kubernetes_state/CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/kubernetes_state/CHANGELOG.md b/kubernetes_state/CHANGELOG.md index 50d61a61dc572..35cb80ef5382e 100644 --- a/kubernetes_state/CHANGELOG.md +++ b/kubernetes_state/CHANGELOG.md @@ -1,9 +1,5 @@ # CHANGELOG - kubernetes_state -## 5.7.2 / 2021-08-02 - -* [Added] KSM `kubernetes_state.statefulset.count` metric. See [#9813](https://github.com/DataDog/integrations-core/pull/9813). - ## 5.7.1 / 2021-06-03 * [Fixed] Fix `node.by_condition` metric. See [#9467](https://github.com/DataDog/integrations-core/pull/9467).