47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import time
|
|
|
|
from starry_client_sdk import StarryClient, StarryNotFoundError, force_flush
|
|
|
|
|
|
def _bool_env(name: str, default: bool) -> bool:
|
|
raw = os.getenv(name)
|
|
if raw is None:
|
|
return default
|
|
return raw.strip().lower() not in {"0", "false", "f", "no", "n", "off"}
|
|
|
|
|
|
def _paths() -> list[str]:
|
|
raw = os.getenv("DEMO_PATHS", ",__sdk_demo_not_found__")
|
|
return [item.strip() for item in raw.split(",")]
|
|
|
|
|
|
def main() -> None:
|
|
client = StarryClient()
|
|
loop = _bool_env("DEMO_LOOP", True)
|
|
interval_seconds = float(os.getenv("DEMO_INTERVAL_SECONDS", "5"))
|
|
paths = _paths()
|
|
|
|
while True:
|
|
for path in paths:
|
|
try:
|
|
text = client.get(path)
|
|
print(f"OK path={path!r} bytes={len(text)}")
|
|
except StarryNotFoundError as exc:
|
|
print(f"NOT_FOUND path={path!r} error={exc}")
|
|
except Exception as exc:
|
|
print(f"ERROR path={path!r} type={exc.__class__.__name__} error={exc}")
|
|
|
|
# Demo app is short-looping, so flush logs, traces, and remote_write metrics quickly.
|
|
force_flush()
|
|
|
|
if not loop:
|
|
break
|
|
time.sleep(interval_seconds)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|