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 labels from self.SAMPLE_LABELS to container status metrics #7602

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
Original file line number Diff line number Diff line change
Expand Up @@ -585,21 +585,23 @@ def _submit_metric_kube_pod_container_status_reason(
tags = []

reason = sample[self.SAMPLE_LABELS].get('reason')
if reason:
if reason and reason.lower() in allowed_status_reasons:
# Filtering according to the reason here is paramount to limit cardinality
if reason.lower() in allowed_status_reasons:
tags += self._build_tags('reason', reason, scraper_config)
else:
continue
tags += self._build_tags('reason', reason, scraper_config)
else:
continue

if 'container' in sample[self.SAMPLE_LABELS]:
tags += self._build_tags('kube_container_name', sample[self.SAMPLE_LABELS]['container'], scraper_config)
for label_name, label_value in iteritems(sample[self.SAMPLE_LABELS]):
if label_name == "reason":
continue

if 'namespace' in sample[self.SAMPLE_LABELS]:
tags += self._build_tags('namespace', sample[self.SAMPLE_LABELS]['namespace'], scraper_config)
elif label_name == 'container':
tags += self._build_tags(
'kube_container_name', sample[self.SAMPLE_LABELS]['container'], scraper_config
)

if 'pod' in sample[self.SAMPLE_LABELS]:
tags += self._build_tags('pod', sample[self.SAMPLE_LABELS]['pod'], scraper_config)
else:
tags += self._build_tags(label_name, label_value, scraper_config)

self.gauge(
metric_name,
Expand Down
10 changes: 8 additions & 2 deletions kubernetes_state/tests/test_kubernetes_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@
'label_addonmanager_kubernetes_io_mode:reconcile',
'deployment:kube-dns',
],
NAMESPACE
+ '.container.status_report.count.waiting': [
'label_addonmanager_kubernetes_io_mode:reconcile',
'pod:registry-creds-hq249',
],
}

HOSTNAMES = {
Expand Down Expand Up @@ -552,9 +557,10 @@ def test_join_standard_tags_labels(aggregator, instance, check_with_join_standar
def test_join_custom_labels(aggregator, instance, check):
instance['label_joins'] = {
'kube_deployment_labels': {
'label_to_match': 'deployment',
'labels_to_match': ['deployment'],
'labels_to_get': ['label_addonmanager_kubernetes_io_mode'],
}
},
'kube_pod_labels': {'labels_to_match': ['pod'], 'labels_to_get': ['label_addonmanager_kubernetes_io_mode']},
}

endpoint = instance['kube_state_url']
Expand Down