Add eval runner and tool orchestration
This commit is contained in:
1 parent
4294f3c92e
commit
5579db54da
66 files changed
+6162
-242
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import type { GarnetClient } from "@common/garnet";
|
||||
import { AGENT_ALERT_SUBJECT, type AlertPayload } from "@common/nats-subjects";
|
||||
import type { NatsClient } from "@common/nats";
|
||||
import { getAlertRateLimitSec } from "../config.js";
|
||||
import { getLogger } from "./logger.js";
|
||||
|
||||
export interface AlertSender {
|
||||
sendAlert(
|
||||
payload: AlertPayload,
|
||||
options?: {
|
||||
dedupeKey?: string | undefined;
|
||||
},
|
||||
): Promise<boolean>;
|
||||
}
|
||||
|
||||
function getAlertDedupeKey(kind: AlertPayload["kind"]): string {
|
||||
return `lolympus-agent:alert:dedupe:${kind}`;
|
||||
}
|
||||
|
||||
export class AlertService implements AlertSender {
|
||||
private readonly logger = getLogger();
|
||||
|
||||
constructor(
|
||||
private readonly garnetClient: Pick<GarnetClient, "setStringIfAbsent">,
|
||||
private readonly natsClient: Pick<NatsClient, "publish">,
|
||||
) {}
|
||||
|
||||
async sendAlert(
|
||||
payload: AlertPayload,
|
||||
options?: {
|
||||
dedupeKey?: string | undefined;
|
||||
},
|
||||
): Promise<boolean> {
|
||||
const dedupeKey = options?.dedupeKey ?? getAlertDedupeKey(payload.kind);
|
||||
const claimed = await this.garnetClient.setStringIfAbsent(
|
||||
dedupeKey,
|
||||
payload.timestamp,
|
||||
getAlertRateLimitSec(),
|
||||
);
|
||||
|
||||
if (!claimed) {
|
||||
this.logger.debug(
|
||||
{
|
||||
dedupeKey,
|
||||
kind: payload.kind,
|
||||
},
|
||||
"[Alert] Suppressed by rate limit",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
await this.natsClient.publish(AGENT_ALERT_SUBJECT, payload);
|
||||
this.logger.warn(
|
||||
{
|
||||
kind: payload.kind,
|
||||
metric: payload.metric,
|
||||
severity: payload.severity,
|
||||
threshold: payload.threshold,
|
||||
value: payload.value,
|
||||
window: payload.window,
|
||||
},
|
||||
"[Alert] Published",
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user