Skip to content

Commit c65aa9c

Browse files
committed
update schema_version value for outgoing Pub/Sub msg attributes (currently None) and add add it to the metadata for bucket objects
1 parent 05b9f9a commit c65aa9c

File tree

1 file changed

+6
-3
lines changed
  • broker/cloud_run/lvk/ps_to_storage

1 file changed

+6
-3
lines changed

broker/cloud_run/lvk/ps_to_storage/main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def run():
7777
except PreconditionFailed:
7878
# this alert is a duplicate. drop it.
7979
return "", HTTP_204
80-
80+
# the schema version is not defined in the schema
81+
# add it manually using the environment variable defined in this script
82+
alert.attributes["schema_version"] = VERSIONTAG
8183
# publish the same alert as JSON
8284
TOPIC_ALERTS.publish(alert)
8385

@@ -91,6 +93,7 @@ def _create_file_metadata(alert: pittgoogle.Alert, event_id: str) -> dict:
9193
metadata["time_created"] = alert.dict["time_created"]
9294
metadata["alert_type"] = alert.dict["alert_type"]
9395
metadata["superevent_id"] = alert.dict["superevent_id"]
96+
metadata["schema_version"] = VERSIONTAG
9497

9598
return metadata
9699

@@ -99,6 +102,6 @@ def _name_in_bucket(alert: pittgoogle.Alert) -> str:
99102
"""Return the name of the file in the bucket."""
100103
_date = alert.dict["time_created"][0:10]
101104
_alert_type = alert.dict["alert_type"]
102-
_id = alert.dict["superevent_id"]
105+
_id = alert.sourceid
103106

104-
return f"{VERSIONTAG}/{_date}/{_alert_type}/{_id}.json"
107+
return f"{VERSIONTAG}/{_id}/{_alert_type}-{_date}.json"

0 commit comments

Comments
 (0)