Skip to content

Commit

Permalink
fix: test key presence in pvcs_in_kubernetes before using it (DevOps-…
Browse files Browse the repository at this point in the history
  • Loading branch information
SimoneLazzaris authored May 19, 2024
1 parent f7b773f commit 0a5f016
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,19 @@
volume_namespace = str(item['metric']['namespace'])
volume_description = "{}.{}".format(item['metric']['namespace'], item['metric']['persistentvolumeclaim'])
volume_used_percent = int(item['value'][1])

# Precursor check to ensure we have info for this pvc in kubernetes object
if volume_description not in pvcs_in_kubernetes:
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))
continue

pvcs_in_kubernetes[volume_description]['volume_used_percent'] = volume_used_percent
try:
volume_used_inode_percent = int(item['value_inodes'])
except:
volume_used_inode_percent = -1
pvcs_in_kubernetes[volume_description]['volume_used_inode_percent'] = volume_used_inode_percent

# Precursor check to ensure we have info for this pvc in kubernetes object
if volume_description not in pvcs_in_kubernetes:
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))
continue

if VERBOSE:
print(" VERBOSE DETAILS:")
print("-------------------------------------------------------------------------------------------------------------")
Expand Down

0 comments on commit 0a5f016

Please sign in to comment.