Skip to content

Commit ff00705

Browse files
committed
resolve if oc is not in environment
1 parent b7dd88f commit ff00705

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

batchtools/prom_metrics.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
from datetime import datetime, timezone
33
from .helpers import is_on_project
44

5+
import os
6+
import shutil
57
import openshift_client as oc
8+
69
from prometheus_client import (
710
CollectorRegistry,
811
Histogram,
@@ -16,7 +19,17 @@
1619

1720
PROMETHEUS_PUSH_URL = "http://localhost:8080/metrics"
1821

19-
PROMETHEUS_INSTANCE = oc.get_project_name() if is_on_project() else "devpod"
22+
23+
def detect_instance() -> str:
24+
if shutil.which("oc") is None:
25+
return "devpod"
26+
try:
27+
return oc.get_project_name() if is_on_project() else "devpod"
28+
except Exception:
29+
return "devpod"
30+
31+
32+
PROMETHEUS_INSTANCE = os.getenv("PROMETHEUS_INSTANCE") or detect_instance()
2033

2134
registry = CollectorRegistry()
2235

0 commit comments

Comments
 (0)