Compare commits
5 Commits
8766813858
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| e0a596ffe3 | |||
| f98ed38a26 | |||
| c8342ee398 | |||
| e441a22fc8 | |||
| 4822b83069 |
@@ -30,10 +30,10 @@ def write_event(event, game: str) -> bool:
|
||||
try:
|
||||
p = Point(event.type).time(event.time * 1_000_000_000)
|
||||
p.tag("game", game)
|
||||
p.tag("serverId", event.serverId)
|
||||
# Ensure data is a dict, even if not provided
|
||||
for k, v in (event.data or {}).items():
|
||||
if isinstance(v, (int, float, str, bool)):
|
||||
if k.startswith("tag_"):
|
||||
p.tag(k[4:], str(v))
|
||||
elif isinstance(v, (int, float, str, bool)):
|
||||
p.field(k, v)
|
||||
write_api.write(bucket=INFLUX_BUCKET, record=p)
|
||||
return True
|
||||
|
||||
@@ -36,11 +36,8 @@ async def ingest_event(payload: Event | BatchEvents, game: str = Depends(verify_
|
||||
def check_event(e: Event):
|
||||
if not e.type or not e.type.strip():
|
||||
raise HTTPException(400, "Event type is required")
|
||||
if not e.serverId:
|
||||
raise HTTPException(400, "serverId is required")
|
||||
if e.time <= 0:
|
||||
raise HTTPException(400, "Invalid timestamp")
|
||||
# Optionally refuse huge data (e.g., >1KB per event)
|
||||
|
||||
if isinstance(payload, BatchEvents):
|
||||
for event in payload.events:
|
||||
|
||||
@@ -4,7 +4,6 @@ from typing import Any, List, Optional
|
||||
class Event(BaseModel):
|
||||
type: str
|
||||
time: int
|
||||
serverId: str
|
||||
data: Optional[dict] = {}
|
||||
|
||||
class BatchEvents(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user