Skip to content

Commit 2ba0daa

Browse files
util: address gemini code review suggestions
- Replace re.sub with str.replace for literal `:` -> `__` substitution. No regex features used; str.replace is faster and the import becomes unused, so drop `import re`. - v1 fallback path: collect publish futures and resolve them after the loop so the Pub/Sub client can batch messages instead of round-tripping per design. Also use payload.update for the metrics merge. Signed-off-by: Miguel Pedro <miguel.pedro@precisioninno.com>
1 parent a3bd1ad commit 2ba0daa

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎flow/util/uploadMetadata.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import json
44
import argparse
5-
import re
65
import os
76
from datetime import datetime, timezone
87

@@ -88,7 +87,7 @@ def upload_data(db, dataFile, platform, design, variant, args, rules):
8887
excludes = ["run", "commit", "total_time", "constraints"]
8988
gen_date = datetime.now()
9089
for k, v in data.items():
91-
new_key = re.sub(":", "__", k) # replace ':' with '__'
90+
new_key = k.replace(":", "__") # replace ':' with '__'
9291
new_data[new_key] = v
9392
stage_name = k.split("__")[0]
9493
if stage_name not in excludes:
@@ -210,7 +209,7 @@ def build_design_record(dataFile, platform, design, variant, rules):
210209
"""Return a dict for one design to be included in the pipeline-level payload."""
211210
with open(dataFile) as f:
212211
data = json.load(f)
213-
metrics = {re.sub(":", "__", k): v for k, v in data.items()}
212+
metrics = {k.replace(":", "__"): v for k, v in data.items()}
214213
return {
215214
"platform": platform,
216215
"design": design,
@@ -258,6 +257,7 @@ def publish_v1_per_design(publisher, topic_path, design_records, args):
258257
flattened at the root), matching the legacy schema the ingestion service
259258
still supports.
260259
"""
260+
futures = []
261261
for d in design_records:
262262
payload = {
263263
"build_id": args.buildID,
@@ -269,8 +269,7 @@ def publish_v1_per_design(publisher, topic_path, design_records, args):
269269
"jenkins_env": args.jenkinsEnv,
270270
"rules": d["rules"],
271271
}
272-
for k, v in d["metrics"].items():
273-
payload[k] = v
272+
payload.update(d["metrics"])
274273

275274
message_data = json.dumps(payload, default=str).encode("utf-8")
276275
try:
@@ -279,6 +278,15 @@ def publish_v1_per_design(publisher, topic_path, design_records, args):
279278
data=message_data,
280279
jenkins_env=args.jenkinsEnv,
281280
)
281+
futures.append((d, future))
282+
except Exception as e:
283+
print(
284+
f"[WARN] Pub/Sub v1 fallback publish failed for "
285+
f"{d['platform']} {d['design']} {d['variant']}: {e}"
286+
)
287+
288+
for d, future in futures:
289+
try:
282290
message_id = future.result()
283291
print(
284292
f"[INFO] Published v1 fallback message (ID: {message_id}) for "

0 commit comments

Comments
 (0)