40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
# agents/core-logic/feedback_loop.py
|
|
|
|
import requests
|
|
from google.cloud import bigquery
|
|
|
|
# Configuration
|
|
TELEMETRY_URL = "https://osvauco-agent-357036551735.europe-west1.run.app/telemetry/history"
|
|
BIGQUERY_PROJECT = "propane-will-491900-m5"
|
|
BIGQUERY_DATASET = "osvauco_logs"
|
|
BIGQUERY_TABLE = "cloud_run_logs"
|
|
|
|
def collect_and_store_telemetry():
|
|
"""
|
|
Collects telemetry data from the specified endpoint and stores it in BigQuery.
|
|
"""
|
|
try:
|
|
# 1. Collect telemetry data
|
|
response = requests.get(TELEMETRY_URL)
|
|
response.raise_for_status() # Raise an exception for bad status codes
|
|
telemetry_data = response.json()
|
|
|
|
# 2. Store data in BigQuery
|
|
client = bigquery.Client(project=BIGQUERY_PROJECT)
|
|
table_id = f"{BIGQUERY_PROJECT}.{BIGQUERY_DATASET}.{BIGQUERY_TABLE}"
|
|
|
|
# Assuming telemetry_data is a list of dicts matching the table schema
|
|
errors = client.insert_rows_json(table_id, telemetry_data)
|
|
if errors == []:
|
|
print(f"Successfully inserted {len(telemetry_data)} rows into {table_id}")
|
|
else:
|
|
print(f"Encountered errors while inserting rows: {errors}")
|
|
|
|
except requests.exceptions.RequestException as e:
|
|
print(f"Error collecting telemetry data: {e}")
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
collect_and_store_telemetry()
|