4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
102 lines
3.0 KiB
Python
102 lines
3.0 KiB
Python
"""HTTP helpers for posting synthetic alerts to a remote investigation stream URL."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
import requests
|
|
|
|
from tests.utils.conftest import REMOTE_RUN_LOCAL_STREAM_URL, REMOTE_RUN_REMOTE_STREAM_URL
|
|
|
|
|
|
def _select_endpoint() -> str:
|
|
"""Prefer a responding local stream URL, otherwise use the configured remote."""
|
|
base = REMOTE_RUN_LOCAL_STREAM_URL.rsplit("/runs/", 1)[0]
|
|
try:
|
|
requests.get(f"{base}/ok", timeout=1)
|
|
return REMOTE_RUN_LOCAL_STREAM_URL
|
|
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
|
|
return REMOTE_RUN_REMOTE_STREAM_URL
|
|
|
|
|
|
def _post_alert(
|
|
endpoint: str,
|
|
alert_name: str,
|
|
pipeline_name: str,
|
|
severity: str,
|
|
raw_alert: dict[str, Any],
|
|
config_metadata: dict[str, Any] | None = None,
|
|
stream_mode: list[str] | None = None,
|
|
timeout: int = 300,
|
|
) -> requests.Response:
|
|
payload = {
|
|
"input": {
|
|
"alert_name": alert_name,
|
|
"pipeline_name": pipeline_name,
|
|
"severity": severity,
|
|
"raw_alert": raw_alert,
|
|
},
|
|
"config": {"metadata": config_metadata or {}},
|
|
"stream_mode": stream_mode or ["values"],
|
|
}
|
|
|
|
response = requests.post(endpoint, json=payload, stream=True, timeout=timeout)
|
|
response.raise_for_status()
|
|
return response
|
|
|
|
|
|
def fire_alert_to_remote_run_stream(
|
|
alert_name: str,
|
|
pipeline_name: str,
|
|
severity: str,
|
|
raw_alert: dict[str, Any],
|
|
config_metadata: dict[str, Any] | None = None,
|
|
stream_mode: list[str] | None = None,
|
|
timeout: int = 300,
|
|
) -> requests.Response:
|
|
"""POST an alert payload to the configured remote ``/runs/stream`` URL."""
|
|
return _post_alert(
|
|
endpoint=REMOTE_RUN_REMOTE_STREAM_URL,
|
|
alert_name=alert_name,
|
|
pipeline_name=pipeline_name,
|
|
severity=severity,
|
|
raw_alert=raw_alert,
|
|
config_metadata=config_metadata,
|
|
stream_mode=stream_mode,
|
|
timeout=timeout,
|
|
)
|
|
|
|
|
|
def fire_alert_to_run_stream(
|
|
alert_name: str,
|
|
pipeline_name: str,
|
|
severity: str,
|
|
raw_alert: dict[str, Any],
|
|
config_metadata: dict[str, Any] | None = None,
|
|
stream_mode: list[str] | None = None,
|
|
timeout: int = 300,
|
|
) -> requests.Response:
|
|
"""POST an alert to local stream URL if reachable, else the remote stream URL."""
|
|
endpoint = _select_endpoint()
|
|
return _post_alert(
|
|
endpoint=endpoint,
|
|
alert_name=alert_name,
|
|
pipeline_name=pipeline_name,
|
|
severity=severity,
|
|
raw_alert=raw_alert,
|
|
config_metadata=config_metadata,
|
|
stream_mode=stream_mode,
|
|
timeout=timeout,
|
|
)
|
|
|
|
|
|
def stream_investigation_results(response: requests.Response) -> None:
|
|
"""Stream and print lines from a streaming investigation HTTP response."""
|
|
print("\nStreaming investigation:\n")
|
|
|
|
for line in response.iter_lines():
|
|
if line:
|
|
decoded = line.decode("utf-8")
|
|
if decoded.strip():
|
|
print(decoded)
|