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

Fix job metrics tagging on KSM 1.4+ #2384

Merged
merged 3 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -484,7 +484,7 @@ def kube_job_complete(self, metric, scraper_config):
for sample in metric.samples:
tags = []
for label_name, label_value in sample[self.SAMPLE_LABELS].iteritems():
if label_name == 'job':
if label_name == 'job' or label_name == 'job_name':
trimmed_job = self._trim_job_tag(label_value)
tags.append(self._format_tag(label_name, trimmed_job, scraper_config))
else:
Expand All @@ -496,7 +496,7 @@ def kube_job_failed(self, metric, scraper_config):
for sample in metric.samples:
tags = []
for label_name, label_value in sample[self.SAMPLE_LABELS].iteritems():
if label_name == 'job':
if label_name == 'job' or label_name == 'job_name':
trimmed_job = self._trim_job_tag(label_value)
tags.append(self._format_tag(label_name, trimmed_job, scraper_config))
else:
Expand All @@ -507,7 +507,7 @@ def kube_job_status_failed(self, metric, scraper_config):
for sample in metric.samples:
tags = [] + scraper_config['custom_tags']
for label_name, label_value in sample[self.SAMPLE_LABELS].iteritems():
if label_name == 'job':
if label_name == 'job' or label_name == 'job_name':
trimmed_job = self._trim_job_tag(label_value)
tags.append(self._format_tag(label_name, trimmed_job, scraper_config))
else:
Expand All @@ -518,7 +518,7 @@ def kube_job_status_succeeded(self, metric, scraper_config):
for sample in metric.samples:
tags = [] + scraper_config['custom_tags']
for label_name, label_value in sample[self.SAMPLE_LABELS].iteritems():
if label_name == 'job':
if label_name == 'job' or label_name == 'job_name':
trimmed_job = self._trim_job_tag(label_value)
tags.append(self._format_tag(label_name, trimmed_job, scraper_config))
else:
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 @@ -182,6 +182,9 @@ kube_job_status_completion_time{job="hello-1509998460",namespace="default"} 1.50
kube_job_status_failed{job="hello-1509998340",namespace="default"} 0
kube_job_status_failed{job="hello-1509998400",namespace="default"} 0
kube_job_status_failed{job="hello-1509998460",namespace="default"} 0
kube_job_status_failed{job_name="hello2-1509998340",namespace="default"} 0
kube_job_status_failed{job_name="hello2-1509998400",namespace="default"} 0
kube_job_status_failed{job_name="hello2-1509998460",namespace="default"} 0
# HELP kube_job_status_start_time StartTime represents time when the job was acknowledged by the Job Manager.
# TYPE kube_job_status_start_time counter
kube_job_status_start_time{job="hello-1509998340",namespace="default"} 1.509998347e+09
Expand All @@ -192,6 +195,9 @@ kube_job_status_start_time{job="hello-1509998460",namespace="default"} 1.5099984
kube_job_status_succeeded{job="hello-1509998340",namespace="default"} 1
kube_job_status_succeeded{job="hello-1509998400",namespace="default"} 1
kube_job_status_succeeded{job="hello-1509998460",namespace="default"} 1
kube_job_status_succeeded{job_name="hello2-1509998340",namespace="default"} 1
kube_job_status_succeeded{job_name="hello2-1509998400",namespace="default"} 1
kube_job_status_succeeded{job_name="hello2-1509998460",namespace="default"} 1
# HELP kube_namespace_created Unix creation timestamp
# TYPE kube_namespace_created gauge
kube_namespace_created{namespace="default"} 1.508406437e+09
Expand Down
14 changes: 14 additions & 0 deletions kubernetes_state/tests/test_kubernetes_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
NAMESPACE + '.limitrange.cpu.default_request',
# services
NAMESPACE + '.service.count',
# jobs
NAMESPACE + '.job.failed',
NAMESPACE + '.job.succeeded',
]

TAGS = {
Expand Down Expand Up @@ -131,6 +134,14 @@
'type:NodePort',
'type:LoadBalancer',
],
NAMESPACE + '.job.failed': [
'job:hello',
'job_name:hello2',
],
NAMESPACE + '.job.succeeded': [
'job:hello',
'job_name:hello2',
],
}

JOINED_METRICS = {
Expand Down Expand Up @@ -172,6 +183,8 @@
NAMESPACE + '.container.waiting',
NAMESPACE + '.endpoint.address_available',
NAMESPACE + '.endpoint.address_not_ready',
NAMESPACE + '.job.failed',
NAMESPACE + '.job.succeeded',
]


Expand Down Expand Up @@ -273,6 +286,7 @@ def test_update_kube_state_metrics(aggregator, instance, check):
tags=['storageclass:local-data', 'phase:Pending', 'optional:tag1'], value=0)
aggregator.assert_metric(NAMESPACE + '.persistentvolumes.by_phase',
tags=['storageclass:local-data', 'phase:Released', 'optional:tag1'], value=0)


for metric in METRICS:
aggregator.assert_metric(metric, hostname=HOSTNAMES.get(metric, None))
Expand Down