Skip to content

Commit

Permalink
KSM: fix node.by_condition metric (#9467)
Browse files Browse the repository at this point in the history
  • Loading branch information
L3n41c authored and ofek committed Jun 3, 2021
1 parent 58d42d3 commit 2fc4725
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,17 @@ def _condition_to_tag_check(self, sample, base_sc_name, mapping, scraper_config,
if bool(sample[self.SAMPLE_VALUE]) is False:
return # Ignore if gauge is not 1 and we are not processing the pod phase check

metric_name = scraper_config['namespace'] + '.node.by_condition'
metric_tags = []
for label_name, label_value in iteritems(sample[self.SAMPLE_LABELS]):
metric_tags += self._build_tags(label_name, label_value, scraper_config)
self.gauge(
metric_name,
sample[self.SAMPLE_VALUE],
tags=tags + metric_tags,
hostname=self.get_hostname_for_sample(sample, scraper_config),
)

label_value, condition_map = self._get_metric_condition_map(base_sc_name, sample[self.SAMPLE_LABELS])
service_check_name = condition_map['service_check_name']
mapping = condition_map['mapping']
Expand Down Expand Up @@ -715,8 +726,7 @@ def kube_job_status_succeeded(self, metric, scraper_config):
def kube_node_status_condition(self, metric, scraper_config):
""" The ready status of a cluster node. v1.0+"""
base_check_name = scraper_config['namespace'] + '.node'
aggregated_metric_name = scraper_config['namespace'] + '.nodes.by_condition'
individual_metric_name = scraper_config['namespace'] + '.node.by_condition'
metric_name = scraper_config['namespace'] + '.nodes.by_condition'
by_condition_counter = Counter()

for sample in metric.samples:
Expand All @@ -738,11 +748,8 @@ def kube_node_status_condition(self, metric, scraper_config):
)
by_condition_counter[tuple(sorted(tags))] += sample[self.SAMPLE_VALUE]

tags = list(tags) + self._label_to_tags("node", sample[self.SAMPLE_LABELS], scraper_config)
self.gauge(individual_metric_name, sample[self.SAMPLE_VALUE], tags=tags)

for tags, count in iteritems(by_condition_counter):
self.gauge(aggregated_metric_name, count, tags=list(tags))
self.gauge(metric_name, count, tags=list(tags))

def kube_node_status_ready(self, metric, scraper_config):
""" The ready status of a cluster node (legacy)"""
Expand Down
2 changes: 0 additions & 2 deletions kubernetes_state/tests/test_kubernetes_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@
'condition:ready',
'status:true',
'status:false',
'status:unknown',
'node:minikube',
],
NAMESPACE
+ '.pod.status_phase': [
Expand Down

0 comments on commit 2fc4725

Please sign in to comment.