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:
|
try:
|
||||||
p = Point(event.type).time(event.time * 1_000_000_000)
|
p = Point(event.type).time(event.time * 1_000_000_000)
|
||||||
p.tag("game", game)
|
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():
|
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)
|
p.field(k, v)
|
||||||
write_api.write(bucket=INFLUX_BUCKET, record=p)
|
write_api.write(bucket=INFLUX_BUCKET, record=p)
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -36,12 +36,9 @@ async def ingest_event(payload: Event | BatchEvents, game: str = Depends(verify_
|
|||||||
def check_event(e: Event):
|
def check_event(e: Event):
|
||||||
if not e.type or not e.type.strip():
|
if not e.type or not e.type.strip():
|
||||||
raise HTTPException(400, "Event type is required")
|
raise HTTPException(400, "Event type is required")
|
||||||
if not e.serverId:
|
|
||||||
raise HTTPException(400, "serverId is required")
|
|
||||||
if e.time <= 0:
|
if e.time <= 0:
|
||||||
raise HTTPException(400, "Invalid timestamp")
|
raise HTTPException(400, "Invalid timestamp")
|
||||||
# Optionally refuse huge data (e.g., >1KB per event)
|
|
||||||
|
|
||||||
if isinstance(payload, BatchEvents):
|
if isinstance(payload, BatchEvents):
|
||||||
for event in payload.events:
|
for event in payload.events:
|
||||||
write_event(event, game)
|
write_event(event, game)
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from typing import Any, List, Optional
|
|||||||
class Event(BaseModel):
|
class Event(BaseModel):
|
||||||
type: str
|
type: str
|
||||||
time: int
|
time: int
|
||||||
serverId: str
|
|
||||||
data: Optional[dict] = {}
|
data: Optional[dict] = {}
|
||||||
|
|
||||||
class BatchEvents(BaseModel):
|
class BatchEvents(BaseModel):
|
||||||
|
|||||||
Reference in New Issue
Block a user