fix: Accept string instance_id in telemetry endpoint
The orchestrator sends instance_id as a string (e.g., "letsbe-orchestrator") but the endpoint was expecting a UUID path parameter. This caused 422 validation errors when orchestrators tried to send telemetry. - Changed path parameter from UUID to str - Lookup instance by Instance.instance_id (string) instead of Instance.id (UUID) - Store telemetry with instance.id (UUID) for correct FK relationship - Updated TelemetryPayload schema to use str instead of UUID 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,6 @@ It validates authentication, stores metrics, and updates instance state.
|
||||
import hashlib
|
||||
import logging
|
||||
import secrets
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Header, HTTPException, status
|
||||
from sqlalchemy import select
|
||||
@@ -27,7 +26,7 @@ router = APIRouter(prefix="/api/v1/instances", tags=["Telemetry"])
|
||||
|
||||
@router.post("/{instance_id}/telemetry", response_model=TelemetryResponse)
|
||||
async def receive_telemetry(
|
||||
instance_id: UUID,
|
||||
instance_id: str,
|
||||
payload: TelemetryPayload,
|
||||
db: AsyncSessionDep,
|
||||
hub_api_key: str = Header(..., alias="X-Hub-Api-Key"),
|
||||
@@ -64,8 +63,8 @@ async def receive_telemetry(
|
||||
},
|
||||
)
|
||||
|
||||
# Find instance by UUID (id column, not instance_id string)
|
||||
result = await db.execute(select(Instance).where(Instance.id == instance_id))
|
||||
# Find instance by instance_id string (e.g., "letsbe-orchestrator")
|
||||
result = await db.execute(select(Instance).where(Instance.instance_id == instance_id))
|
||||
instance = result.scalar_one_or_none()
|
||||
|
||||
if instance is None:
|
||||
@@ -114,8 +113,9 @@ async def receive_telemetry(
|
||||
|
||||
# Store telemetry sample
|
||||
# Use PostgreSQL upsert to handle duplicates gracefully
|
||||
# Note: instance_id in DB is the UUID (instance.id), not the string instance_id
|
||||
telemetry_data = {
|
||||
"instance_id": instance_id,
|
||||
"instance_id": instance.id,
|
||||
"window_start": payload.window_start,
|
||||
"window_end": payload.window_end,
|
||||
"uptime_seconds": payload.uptime_seconds,
|
||||
|
||||
Reference in New Issue
Block a user