Skip to content

Commit 0a5f016

Browse files
fix: test key presence in pvcs_in_kubernetes before using it (#21)
1 parent f7b773f commit 0a5f016

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

main.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,19 @@
8787
volume_namespace = str(item['metric']['namespace'])
8888
volume_description = "{}.{}".format(item['metric']['namespace'], item['metric']['persistentvolumeclaim'])
8989
volume_used_percent = int(item['value'][1])
90+
91+
# Precursor check to ensure we have info for this pvc in kubernetes object
92+
if volume_description not in pvcs_in_kubernetes:
93+
print("ERROR: The volume {} was not found in Kubernetes but had metrics in Prometheus. This may be an old volume, was just deleted, or some random jitter is occurring. If this continues to occur, please report an bug. You might also be using an older version of Prometheus, please make sure you're using v2.30.0 or newer before reporting a bug for this.".format(volume_description))
94+
continue
95+
9096
pvcs_in_kubernetes[volume_description]['volume_used_percent'] = volume_used_percent
9197
try:
9298
volume_used_inode_percent = int(item['value_inodes'])
9399
except:
94100
volume_used_inode_percent = -1
95101
pvcs_in_kubernetes[volume_description]['volume_used_inode_percent'] = volume_used_inode_percent
96102

97-
# Precursor check to ensure we have info for this pvc in kubernetes object
98-
if volume_description not in pvcs_in_kubernetes:
99-
print("ERROR: The volume {} was not found in Kubernetes but had metrics in Prometheus. This may be an old volume, was just deleted, or some random jitter is occurring. If this continues to occur, please report an bug. You might also be using an older version of Prometheus, please make sure you're using v2.30.0 or newer before reporting a bug for this.".format(volume_description))
100-
continue
101-
102103
if VERBOSE:
103104
print(" VERBOSE DETAILS:")
104105
print("-------------------------------------------------------------------------------------------------------------")

0 commit comments

Comments
 (0)