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 issue when the storage class of a persistent volume is empty and add test #6615

Merged
merged 2 commits into from
Jun 9, 2020
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 @@ -861,9 +861,13 @@ def count_objects_by_tags(self, metric, scraper_config):
object_counter = Counter()

for sample in metric.samples:
tags = [
self._label_to_tag(l, sample[self.SAMPLE_LABELS], scraper_config) for l in config['allowed_labels']
] + scraper_config['custom_tags']
tags = []
for l in config['allowed_labels']:
tag = self._label_to_tag(l, sample[self.SAMPLE_LABELS], scraper_config)
if tag is None:
tag = self._format_tag(l, "unknown", scraper_config)
tags.append(tag)
tags += scraper_config['custom_tags']
object_counter[tuple(sorted(tags))] += sample[self.SAMPLE_VALUE]

for tags, count in iteritems(object_counter):
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 @@ -286,10 +286,16 @@ kube_persistentvolume_status_phase{persistentvolume="local-pv-15d0a3a3",phase="B
kube_persistentvolume_status_phase{persistentvolume="local-pv-15d0a3a3",phase="Failed"} 0
kube_persistentvolume_status_phase{persistentvolume="local-pv-15d0a3a3",phase="Pending"} 0
kube_persistentvolume_status_phase{persistentvolume="local-pv-15d0a3a3",phase="Released"} 0
kube_persistentvolume_status_phase{persistentvolume="local-pv-16d0a3a3",phase="Available"} 0
kube_persistentvolume_status_phase{persistentvolume="local-pv-16d0a3a3",phase="Bound"} 1
kube_persistentvolume_status_phase{persistentvolume="local-pv-16d0a3a3",phase="Failed"} 0
kube_persistentvolume_status_phase{persistentvolume="local-pv-16d0a3a3",phase="Pending"} 0
kube_persistentvolume_status_phase{persistentvolume="local-pv-16d0a3a3",phase="Released"} 0
# HELP kube_persistentvolume_info Information about persistentvolume.
# TYPE kube_persistentvolume_info gauge
kube_persistentvolume_info{persistentvolume="local-pv-103fef5d",storageclass="local-data"} 1
kube_persistentvolume_info{persistentvolume="local-pv-15d0a3a3",storageclass="local-data"} 1
kube_persistentvolume_info{persistentvolume="local-pv-16d0a3a3",storageclass=""} 1
# HELP kube_persistentvolumeclaim_info Information about persistent volume claim.
# TYPE kube_persistentvolumeclaim_info gauge
kube_persistentvolumeclaim_info{namespace="default",persistentvolumeclaim="task-pv-claim",storageclass="manual"} 1
Expand Down
12 changes: 9 additions & 3 deletions kubernetes_state/tests/test_kubernetes_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ def test_update_kube_state_metrics(aggregator, instance, check):
tags=['storageclass:local-data', 'phase:bound', 'optional:tag1'],
value=2,
)
# No storage class
aggregator.assert_metric(
NAMESPACE + '.persistentvolumes.by_phase',
tags=['storageclass:unknown', 'phase:bound', 'optional:tag1'],
value=1,
)
aggregator.assert_metric(
NAMESPACE + '.persistentvolumes.by_phase',
tags=['storageclass:local-data', 'phase:failed', 'optional:tag1'],
Expand Down Expand Up @@ -782,9 +788,9 @@ def test_telemetry(aggregator, instance):

for _ in range(2):
check.check(instance)
aggregator.assert_metric(NAMESPACE + '.telemetry.payload.size', tags=['optional:tag1'], value=90948.0)
aggregator.assert_metric(NAMESPACE + '.telemetry.metrics.processed.count', tags=['optional:tag1'], value=914.0)
aggregator.assert_metric(NAMESPACE + '.telemetry.metrics.input.count', tags=['optional:tag1'], value=1288.0)
aggregator.assert_metric(NAMESPACE + '.telemetry.payload.size', tags=['optional:tag1'], value=91486.0)
aggregator.assert_metric(NAMESPACE + '.telemetry.metrics.processed.count', tags=['optional:tag1'], value=926.0)
aggregator.assert_metric(NAMESPACE + '.telemetry.metrics.input.count', tags=['optional:tag1'], value=1300.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=374.0)
aggregator.assert_metric(
Expand Down