Skip to content

Commit

Permalink
feat(agent): add self-monitoring logs (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreDemailly authored Nov 20, 2023
1 parent f50948c commit 4f159ce
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/agent/src/utils/selfMonitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,21 @@ function hasAgentFailureThrottle(throttle: SigynInitializedSelfMonitoring["throt
export function handleAgentFailure(errorMessage: string, rule: Rule, logger: Logger) {
const config = getConfig();
if (!config.selfMonitoring) {
logger.info("[SELF MONITORING](skip: disabled)");

return;
}
const { errorFilters, ruleFilters, minimumErrorCount = 0 } = config.selfMonitoring;

if (errorFilters && !errorFilters?.includes(errorMessage)) {
logger.info(`[SELF MONITORING](skip: error message "${errorMessage}" is not in errorFilters)`);

return;
}

if (ruleFilters && !ruleFilters?.includes(rule.config.name)) {
logger.info(`[SELF MONITORING](skip: rule "${rule.config.name}" is not in ruleFilters)`);

return;
}

Expand All @@ -67,9 +73,13 @@ export function handleAgentFailure(errorMessage: string, rule: Rule, logger: Log
const agentFailures = getDB().prepare("SELECT * FROM agentFailures").all() as DbAgentFailure[];
if (agentFailures.length > minimumErrorCount) {
if (hasAgentFailureThrottle(config.selfMonitoring.throttle)) {
logger.info(`[SELF MONITORING](skip: throttle is activated)`);

return;
}

logger.info(`[SELF MONITORING](new alert: ${agentFailures.length} agent failures detected)`);

createAgentFailureAlert(agentFailures, config.selfMonitoring, logger);

// delete all agentFailures, if there is throttle: delete only the old ones
Expand Down

0 comments on commit 4f159ce

Please sign in to comment.