Skip to content

Commit

Permalink
use kube_deployment_status_observed_generation to properly count depl…
Browse files Browse the repository at this point in the history
…oyments
  • Loading branch information
mfpierre committed Dec 21, 2020
1 parent fcf960d commit 24d413e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def __init__(self, name, init_config, instances):
'allowed_labels': ['namespace', 'owner_name', 'owner_kind'],
},
'kube_job_owner': {'metric_name': 'job.count', 'allowed_labels': ['namespace', 'owner_name', 'owner_kind']},
'kube_deployment_status_condition': {
'kube_deployment_status_observed_generation': {
'metric_name': 'deployment.count',
'allowed_labels': ['namespace', 'condition', 'status'],
'allowed_labels': ['namespace'],
},
}

Expand Down Expand Up @@ -131,7 +131,7 @@ def __init__(self, name, init_config, instances):
'kube_replicaset_owner': self.count_objects_by_tags,
'kube_job_owner': self.count_objects_by_tags,
# to get overall count is to filter by Available
'kube_deployment_status_condition': self.count_objects_by_tags,
'kube_deployment_status_observed_generation': self.count_objects_by_tags,
}

# Handling cron jobs succeeded/failed counts
Expand Down Expand Up @@ -318,7 +318,7 @@ def _create_kubernetes_state_prometheus_instance(self, instance):
# _generation metrics are more metadata than metrics, no real use case for now
'kube_daemonset_metadata_generation',
'kube_deployment_metadata_generation',
'kube_deployment_status_observed_generation',
'kube_deployment_status_condition',
'kube_replicaset_metadata_generation',
'kube_replicaset_status_observed_generation',
'kube_replicationcontroller_metadata_generation',
Expand Down
18 changes: 14 additions & 4 deletions kubernetes_state/tests/test_kubernetes_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
NAMESPACE + '.node.gpu.cards_allocatable',
NAMESPACE + '.nodes.by_condition',
# deployments
NAMESPACE + '.deployment.count',
NAMESPACE + '.deployment.replicas',
NAMESPACE + '.deployment.replicas_available',
NAMESPACE + '.deployment.replicas_unavailable',
Expand Down Expand Up @@ -149,7 +148,6 @@
'namespace:kube-system',
],
NAMESPACE + '.pod.count': ['uid:b6fb4273-2dd6-4edb-9a23-7642bb121806', 'created_by_kind:daemonset'],
NAMESPACE + '.deployment.count': ['condition:progressing', 'condition:available', 'status:true'],
NAMESPACE + '.replicaset.count': ['owner_kind:deployment', 'owner_name:metrics-server-v0.3.6'],
NAMESPACE + '.namespace.count': ['phase:active', 'phase:terminating'],
NAMESPACE + '.job.count': ['owner_kind:cronjob', 'owner_name:a-cronjob'],
Expand Down Expand Up @@ -375,6 +373,18 @@ def test_update_kube_state_metrics(aggregator, instance, check):
value=0,
)

# deployment counts
aggregator.assert_metric(
NAMESPACE + '.deployment.count',
tags=['namespace:default', 'optional:tag1'],
value=2,
)
aggregator.assert_metric(
NAMESPACE + '.deployment.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 @@ -806,10 +816,10 @@ 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=998.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.metrics.blacklist.count', tags=['optional:tag1'], value=24.0)
aggregator.assert_metric(NAMESPACE + '.telemetry.metrics.ignored.count', tags=['optional:tag1'], value=328.0)
aggregator.assert_metric(NAMESPACE + '.telemetry.metrics.ignored.count', tags=['optional:tag1'], value=332.0)
aggregator.assert_metric(
NAMESPACE + '.telemetry.collector.metrics.count',
tags=['resource_name:pod', 'resource_namespace:default', 'optional:tag1'],
Expand Down

0 comments on commit 24d413e

Please sign in to comment.