File tree Expand file tree Collapse file tree 2 files changed +11
-7
lines changed
Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -220,7 +220,14 @@ def run(args: argparse.Namespace):
220220 )
221221
222222 IN_PROGRESS .labels (** labels , result = result_phase ).dec ()
223- push_registry_text ()
223+
224+ # 👇 Create a grouping key unique to this job run
225+ group = {
226+ "instance" : PROMETHEUS_INSTANCE , # e.g. "ope-test"
227+ "job_name" : "job" , # e.g. "job-none-b799d46a6f995a9d8d58b6aff76abefc"
228+ }
229+
230+ push_registry_text (grouping_key = group )
224231
225232 except oc .OpenShiftPythonException as e :
226233 sys .exit (f"Error occurred while creating job: { e } " )
Original file line number Diff line number Diff line change @@ -141,23 +141,20 @@ def generate_metrics_text() -> tuple[str, str]:
141141 payload = generate_latest (registry )
142142 return payload .decode ("utf-8" ), CONTENT_TYPE_LATEST
143143
144- def push_registry_text () -> None :
145- """
146- Push the current registry to a Prometheus Pushgateway.
144+ from prometheus_client import pushadd_to_gateway , delete_from_gateway # add delete if you want cleanup
147145
148- Uses PUSHGATEWAY_ADDR (host:port) and the logical job name "batchtools".
149- """
146+ def push_registry_text (grouping_key : dict [str , str ] | None = None ) -> None :
150147 if not PUSHGATEWAY_ADDR :
151148 body , _ = generate_metrics_text ()
152149 print ("PROM: PUSHGATEWAY_ADDR not set; below is the metrics payload:\n " )
153150 print (body )
154151 return
155-
156152 try :
157153 pushadd_to_gateway (
158154 PUSHGATEWAY_ADDR ,
159155 job = "batchtools" ,
160156 registry = registry ,
157+ grouping_key = grouping_key or {},
161158 )
162159 print (f"PROM: metrics pushed to pushgateway={ PUSHGATEWAY_ADDR } " )
163160 except Exception as e :
You can’t perform that action at this time.
0 commit comments