Skip to content

Commit 8b5e069

Browse files
authored
prometheus - do not fail on scrape_interval if keys do not exist (#389)
prometheus - do not fail on scrape_interval
1 parent 7bd8646 commit 8b5e069

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ocp_utilities/monitoring.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ def get_scrape_interval(self) -> int:
144144
response = self._get_response(query=f"{self.api_v1}/targets")
145145
result = response.get("data", {}).get("activeTargets", [])
146146
for item in result:
147-
if item and item["labels"]["job"] == "prometheus-k8s":
148-
scrape_interval = item["scrapeInterval"]
149-
if scrape_interval_match := re.match(r"\d+", scrape_interval):
150-
return int(scrape_interval_match.group())
147+
if item and item.get("labels", {}).get("job") == "prometheus-k8s":
148+
if scrape_interval := item.get("scrapeInterval"):
149+
if scrape_interval_match := re.match(r"\d+", scrape_interval):
150+
return int(scrape_interval_match.group())
151151

152152
return 30
153153

0 commit comments

Comments
 (0)