feat(cg6): publish anomalies to Pub/Sub topic

This commit is contained in:
Chris Christiansen 2026-05-27 17:29:22 +00:00
parent 63f3b404b6
commit 5c1693994e

View File

@ -14,7 +14,7 @@ class AnomalyDetector:
if not self.billing_table:
raise ValueError("BILLING_TABLE environment variable not set.")
self.pubsub_topic_name = os.environ.get("PUBSUB_TOPIC", "billing_alerts")
self.pubsub_topic_name = os.environ.get("ANOMALY_TOPIC", "osvauco-billing-anomalies")
self.bq_client = bigquery.Client(project=self.project_id)
self.publisher = pubsub_v1.PublisherClient()
self.topic_path = self.publisher.topic_path(self.project_id, self.pubsub_topic_name)
@ -77,7 +77,7 @@ class AnomalyDetector:
"today_cost": anomaly["today_cost"],
"avg_7d": anomaly["avg_7d"],
"ratio": anomaly["ratio"],
"timestamp": datetime.datetime.now().isoformat()
"timestamp_utc": datetime.datetime.utcnow().isoformat()
}
message_bytes = json.dumps(message_data).encode("utf-8")
self.publisher.publish(self.topic_path, data=message_bytes)