Skip to content

Commit

Permalink
feat: update garven to support ws stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Skelmis committed Jan 11, 2024
1 parent cab32a2 commit fbb70b9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
23 changes: 22 additions & 1 deletion garven/routers/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from garven.calculate_dev_cluster import get_dev_cluster
from garven.dependencies import get_auth_header
from garven.schema import Message
from garven.schema.cluster import ClusterHealth, DevShare
from garven.schema.cluster import ClusterHealth, DevShare, ClusterWSInfo

if TYPE_CHECKING:
from zonis.server import Server
Expand Down Expand Up @@ -46,6 +46,27 @@ async def cluster_status(request: Request):
return ClusterHealth(clusters=d, partial_response=partial_response)


@cluster_router.get("/latency/ws", response_model=ClusterWSInfo)
async def cluster_status(request: Request):
partial_response = False
z: Server = request.app.zonis
d: dict[str, dict[str, str]] = await z.request_all("cluster_ws_status")
shard_data = {}
for _, item in deepcopy(d).items():
if isinstance(item, RequestFailed):
partial_response = True
log.error("/cluster/status/ws WS threw '%s'", item.response_data)
continue

for shard_id, value in item.items():
shard_data[shard_id] = value

if len(shard_data.values()) != int(os.environ.get("TOTAL_SHARDS")):
partial_response = True

return ClusterWSInfo(shards=shard_data, partial_response=partial_response) # noqa


@cluster_router.post(
"/notify_devs", status_code=204, responses={503: {"model": Message}}
)
Expand Down
17 changes: 17 additions & 0 deletions garven/schema/cluster/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ class ShardInfo(BaseModel):
)


class ClusterWSInfo(BaseModel):
partial_response: bool = Field(
False,
description="This will be true when the returned statistic "
"does not accurately represent the entire expected dataset.",
)
shards: dict[str, dict[str, str]] = Field(
description="A mapping of shard id's to self reported latencies"
)

class Config:
schema_extra = {
"partial_response": True,
"shards": {"1": {"ws": "1.1", "keepalive": "15.5"}},
}


class ClusterInfo(BaseModel):
cluster_is_up: bool = Field(
description="Ignoring individual shards, is the cluster as a whole functional"
Expand Down

0 comments on commit fbb70b9

Please sign in to comment.