Loading…
Loading…
Technical reference for the Alert Evaluation Service, which monitors service health, evaluates against thresholds, and sends notifications for failures.
The Alert Evaluation Service is a background worker component responsible for monitoring the health of production services. It detects service degradation by evaluating key performance metrics against configured thresholds for error rates, latency, and consecutive failures.
This service operates by periodically querying service metric data from platform logs. When a metric crosses a predefined threshold, the service can trigger an alert, persist the new alert state, and send a notification email to designated recipients. When the metric returns to normal, a corresponding "clear" notification is sent.
The service is designed for a multi-tenant environment. It processes each tenant's services independently, using the tenant's specific configuration for alert thresholds and SMTP notification settings. This ensures that alert evaluation and notification are properly scoped and isolated between tenants.
The alert evaluation process is initiated by a call to the runEvaluation method. The service performs a series of steps to identify services to monitor, gather metrics, evaluate alert conditions, and send notifications.
flowchart TD
subgraph Alert Evaluation Run
A[Start Evaluation] --> B{Query all active 'prod' services};
B --> C{Group services by Tenant};
C --> D{For each Tenant...};
end
subgraph "Per-Tenant Processing"
D --> E[1. Bind Tenant Context];
E --> F{2. Load Tenant's SMTP & Alert Settings};
F --> G{3. For each Service in Tenant...};
end
subgraph "Per-Service Evaluation"
G --> H{Is alerting enabled?};
H -- No --> G;
H -- Yes --> I[4. Load metrics for 6 alert types];
I --> J[5. Evaluate metrics vs. thresholds];
J --> K{State changed? (e.g., OK to Firing)};
K -- No --> L;
K -- Yes --> M[6. Send Email Notification];
M --> L[7. Update Alert State in DB];
L --> G;
end
G --> Z[Collate Results];
D --> Z;
Z --> End[Return Summary Report];The service is built to support a multi-tenant architecture. The evaluation process respects tenant boundaries to ensure data and configuration isolation.
s2r_service table for all active services in the prod environment.tenant_id.TenantContext before processing that tenant's services. This context ensures that all subsequent database lookups for configuration (like SMTP settings and default alert thresholds) are scoped to the current tenant. Platform-wide defaults are used as a fallback.Within a tenant's context, each service is evaluated individually.
s2r_system_setting table. A critical feature is the selectSmtpBlock logic: the system uses either all of a tenant's custom SMTP settings or all of the platform defaults. It never mixes them, preventing a tenant's SMTP host from being used with the platform's credentials, for example.s2r_runtime_log (runtime metrics) and s2r_traffic_log (F5 network metrics), to gather data for six distinct alert types.s2r_service_alert_config. If not set there, they fall back to the tenant-wide defaults loaded in step 1.evaluateAndPersist method is called for each alert type. It compares the current evaluation result with the last known state stored in the s2r_alert_state table.sendMail method is invoked.
smtp_recipients) before falling back to the tenant's default list.host, port, credentials).s2r_alert_mail_history table for auditing.s2r_alert_state table is updated to reflect the new state (is_active), evaluation time, and a JSON blob containing the detailed metrics that led to the result.The service evaluates six types of alerts for each service, drawing from two different data sources.
| Alert Type | Data Source | Trigger Condition |
|---|---|---|
prod-consecutive-failures | s2r_runtime_log | The last N calls recorded in the runtime log have a non-successful HTTP status code (< 200 or >= 300). |
prod-error-rate | s2r_runtime_log | The percentage of calls with a non-successful HTTP status code within a configured time window exceeds the threshold. |
prod-latency-increase | s2r_runtime_log | The average call duration in a recent time window is a specified percentage higher than the average duration over the last 24 hours. |
prod-f5-consecutive-failures | s2r_traffic_log | The last N F5 traffic log events are failures. A failure is an HTTP status < 200 or >= 400, or a result_code of failed, backend_failure, blocked, error, or timeout. |
prod-f5-error-rate | s2r_traffic_log | The percentage of F5 traffic log events that are failures within a configured time window exceeds the threshold. |
prod-f5-latency-increase | s2r_traffic_log | The average transaction latency calculated from F5 events in a recent window is a specified percentage higher than the 24-hour baseline. Latency is derived from correlated F5 event timestamps. |
Alerting behavior is controlled by settings at the tenant and individual service levels. Service-level settings always override tenant-level settings.
These settings are stored in the s2r_system_setting table and are scoped per tenant. They provide the default behavior for all services within that tenant.
| Key | Type | Default | Description |
|---|---|---|---|
alert_smtp_enabled | Boolean | false | Master switch to enable or disable email notifications for the tenant. |
alert_smtp_host | String | "" | SMTP server host. |
alert_smtp_port | Integer | 587 | SMTP server port. |
alert_smtp_username | String | "" | Username for SMTP authentication. |
alert_smtp_password | String | "" | Password for SMTP authentication. Stored as a CredentialsCipher envelope. |
alert_smtp_auth | Boolean | true | Whether to attempt SMTP authentication. |
alert_smtp_starttls | Boolean | true | Whether to use STARTTLS to upgrade the connection. |
alert_smtp_from | String | — | The From: address for alert emails. |
alert_smtp_subject_prefix | String | [S2R] | Text to prepend to the subject line of alert emails. |
alert_smtp_default_recipients | String | — | A comma, semicolon, or space-separated list of default email addresses to receive alerts. |
alert_prod_consecutive_failures | Integer | 5 | Default number of consecutive failures to trigger an alert. |
alert_prod_error_rate_pct | Double | 20.0 | Default error rate percentage to trigger an alert. |
alert_prod_latency_increase_pct | Double | 10.0 | Default latency increase percentage to trigger an alert. |
alert_prod_error_rate_window_minutes | Integer | 5 | Default time window in minutes for error rate and latency calculations. |
These settings are stored in the s2r_service_alert_config table and apply to a single service, overriding the tenant-level defaults.
| Column | Type | Description |
|---|---|---|
enabled | Boolean | Enables or disables alerting for this specific service. Defaults to true if not set. |
consecutive_failure_threshold | Integer | Overrides alert_prod_consecutive_failures for this service. |
error_rate_threshold_pct | Double | Overrides alert_prod_error_rate_pct for this service. |
latency_increase_threshold_pct | Double | Overrides alert_prod_latency_increase_pct for this service. |
error_rate_window_minutes | Integer | Overrides alert_prod_error_rate_window_minutes for this service. |
smtp_recipients | String | A comma, semicolon, or space-separated list of email addresses. Overrides alert_smtp_default_recipients. |
The service is an internal component and exposes its functionality through a Java method, not a web API endpoint.
runEvaluation() MethodThis is the main entry point for the evaluation process. It is called by the platform's scheduling mechanism.
public Map<String, Object> runEvaluation()Map<String, Object> containing a summary of the evaluation run.The returned map provides a high-level summary of the actions taken during the run.
{
"status": "DONE",
"smtpEnabled": true,
"evaluatedServices": 5,
"triggeredAlerts": 1,
"clearedAlerts": 0,
"results": [
{
"serviceId": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"serviceKey": "my-service-1",
"serviceName": "My Service 1",
"consecutiveFailure": {
"alertType": "prod-consecutive-failures",
"state": "ok",
"notified": false,
"detail": {
"threshold": 5,
"observed": 0,
"lastOccurredAt": null,
"locations": [],
"window": "latest_calls"
}
},
"errorRate": {
"alertType": "prod-error-rate",
"state": "triggered",
"notified": true,
"detail": {
"thresholdPct": 10.0,
"observedPct": 15.5,
"totalCalls": 200,
"failedCalls": 31,
"windowMinutes": 5,
"lastOccurredAt": "2023-10-27T10:00:00Z",
"locations": []
}
},
"latencyIncrease": { "...": "..." },
"f5ConsecutiveFailure": { "...": "..." },
"f5ErrorRate": { "...": "..." },
"f5LatencyIncrease": { "...": "..." }
}
],
"time": "2023-10-27T10:00:05.123Z"
}
The alert_smtp_password setting is stored in an encrypted format.
WARNING
The service requires a S2R_CREDENTIAL_KEY to be available in its environment to decrypt the SMTP password. If the key is missing or the password value is corrupt, decryption will fail.
When decryption fails, the service logs a warning with the code S2R-WRK-0419, and the evaluation proceeds using an empty password. This will likely cause SMTP authentication to fail, which will be recorded in the mail history.
If alerts are triggering but notifications are not being received, consult the s2r_alert_mail_history table. This table records every mail delivery attempt, its status (sent or failed), and an error message if the delivery failed. Common causes include:
alert_smtp_enabled is false for the tenant.host, port, credentials).The Alert Evaluation Service interacts with several key tables in the platform database.
| Table | Purpose |
|---|---|
s2r_service | The master list of services. Evaluation targets are selected from here. |
s2r_service_alert_config | Stores service-level overrides for alert thresholds and recipients. |
s2r_system_setting | Stores tenant-scoped configurations, including default thresholds and SMTP settings. |
s2r_runtime_log | Provides runtime metrics (status codes, duration) for alert calculations. |
s2r_traffic_log | Provides F5 network-level metrics for alert calculations. |
s2r_alert_state | Persists the current state (active/cleared) of each alert type for each service. |
s2r_alert_mail_history | An audit log of all email notification attempts and their outcomes. |