Skip to content

Commit

Permalink
prometheus - do not fail on scrape_interval if keys do not exist (#389)
Browse files Browse the repository at this point in the history
prometheus - do not fail on scrape_interval
  • Loading branch information
rnetser authored Jan 3, 2025
1 parent 7bd8646 commit 8b5e069
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ocp_utilities/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ def get_scrape_interval(self) -> int:
response = self._get_response(query=f"{self.api_v1}/targets")
result = response.get("data", {}).get("activeTargets", [])
for item in result:
if item and item["labels"]["job"] == "prometheus-k8s":
scrape_interval = item["scrapeInterval"]
if scrape_interval_match := re.match(r"\d+", scrape_interval):
return int(scrape_interval_match.group())
if item and item.get("labels", {}).get("job") == "prometheus-k8s":
if scrape_interval := item.get("scrapeInterval"):
if scrape_interval_match := re.match(r"\d+", scrape_interval):
return int(scrape_interval_match.group())

return 30

Expand Down

0 comments on commit 8b5e069

Please sign in to comment.