Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kubernetes_state.statefulset.count metric #9813

Merged
merged 5 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datadog_checks_base/tests/fixtures/prometheus/ksm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -866,4 +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
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
Expand Down Expand Up @@ -323,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',
Expand Down
1 change: 1 addition & 0 deletions kubernetes_state/metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions kubernetes_state/tests/fixtures/prometheus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions kubernetes_state/tests/test_kubernetes_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, []):
Expand Down Expand Up @@ -873,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(
Expand Down