Loading…
Loading…
Manages the lifecycle of discovery ingest relay VMs. This service handles health checks, automatic recreation, image version reconciliation, and disk
The Discovery Ingest Health Service is an automated reconciliation component that manages the lifecycle of discovery ingest relay Virtual Machines (VMs). These relay VMs are deployed into an API publisher's environment to receive and forward discovery data, such as syslog traffic, to the platform's ingest endpoint.
This service solves the operational problem of ensuring these critical, customer-hosted components remain available, healthy, and correctly configured without manual intervention. It runs periodically within the platform's worker service to perform the following key functions:
The service is cloud-agnostic by design, interacting with different cloud providers through a RelayVmGateway interface. It reads its target list of relays from the platform database and updates their status in the s2r_f5_sync_state table.
NOTE
The service and its related database tables may contain legacy names such as f5. These refer to the generic discovery ingest relay functionality.
The core logic resides in the reconcileActiveRelays method, which executes a reconciliation loop over all active and enabled relay VMs defined in the database. For each relay, the service performs a sequence of checks and actions to converge its state to the desired configuration.
flowchart TD
subgraph "For Each Active Relay"
A(Start Reconciliation) --> B{Discovery Source Enabled?};
B -- No --> C{Auto-Deprovision Enabled?};
C -- Yes --> D[Deprovision Relay VM];
C -- No --> E[Log Orphan and Skip];
B -- Yes / Indeterminate --> F[Check/Create Relay VM];
F --> G{Relay VM Healthy?};
G -- No --> H[Dispatch Asynchronous VM Recreation];
G -- Yes --> I[Probe Relay Health Endpoint];
I --> J[Check Image Version];
J --> K[Check Liveness Heartbeat];
K --> L[Check Disk Usage];
L --> M{Disk Auto-Extend Triggered?};
M -- Yes --> N[Resize VM Disk];
M -- No --> O[Persist Final Status to DB];
N --> O;
H --> O;
D --> End(Done);
E --> End;
O --> End;
endLoad Targets: The service queries the s2r_f5_instance and s2r_f5_sync_state tables to get a list of all relays that are marked as enabled.
Discovery Gate: For each relay, it checks the s2r_discovery_vendor_enabled table to see if the corresponding discovery source is enabled.
S2R_INGEST_DEPROVISION_ON_DISCOVERY_DISABLED flag is true, the service deprovisions the relay VM and updates its status to deleted.false (the default), it logs a warning (S2R-INGEST-ORPHAN) and takes no further action for that relay.Health Check and Recreation: The service ensures the relay VM is healthy.
RUNNING state via the RelayVmGateway. If not, it creates it./healthz endpoint. A healthy relay must return an ok status, be in vm-local-ingest mode, and have its local ingest container sub-process running.relayStartupGrace window), it is marked as starting and left to bootstrap.recreating.Status Evaluation (for Healthy Relays): If the VM is healthy, the service performs deeper analysis based on the data returned from the /healthz probe.
s2r_system_setting table. If the digests differ for longer than the relayDivergenceGrace period, the relay's status is updated to stale-image.relayHeartbeatStale threshold, a S2R-RELAY-NO-HEARTBEAT warning is logged.relayDiskWarnPercent, a S2R-RELAY-DISK-PRESSURE warning is logged. If it exceeds relayDiskGrowPercent and auto-extend is enabled, a disk resize operation is triggered.State Persistence: The service writes the final determined status (ok, starting, recreating, stale-image), health message, IP address, and self-reported image details back to the s2r_f5_sync_state table.
When a relay VM is created or recreated, the service generates and executes a startup script on the instance. This script is responsible for bootstrapping the entire relay environment.
The script performs these critical tasks:
docker.io and python3.s2r-update-relay-installer.service) to ensure key operational scripts are always present.s2r-discovery-ingest-local.service: Runs a Docker container of the platform's worker image. This container exposes an HTTP endpoint for the syslog relay script to forward data to.s2r-discovery-ingest-relay.service: Runs a Python-based syslog server that listens for traffic, queues it, and forwards it to the local ingest container.s2r-discovery-ingest-reconcile.timer). This periodically runs a script that fetches the desired container image from the control plane and restarts the s2r-discovery-ingest-local service if needed, ensuring the relay automatically converges to the correct version.The relay's runtime configuration is published to the platform's central ObjectStore (GCS or S3). The VM is given a signed URL to download this configuration upon startup and periodically refresh it.
The service exposes one primary method for initiating the reconciliation process.
reconcileActiveRelays()Triggers a full reconciliation of all active discovery ingest relay VMs. It iterates through each target, assesses its health and configuration, and takes corrective action as needed.
Map<String, Object> containing a summary of the reconciliation run.The returned map provides a high-level overview of the state of the relay fleet after the run completes.
{
"status": "DONE",
"targetCount": 10,
"healthy": 7,
"starting": 1,
"recreated": 0,
"staleImage": 1,
"noHeartbeat": 0,
"orphanLogged": 1,
"deprovisioned": 0,
"diskGrown": 0,
"failed": 1,
"time": "2023-10-27T10:00:00Z"
}
Response Fields:
| Field | Description |
|---|---|
status | Always DONE on successful completion of the method. |
targetCount | The total number of relay VMs targeted for reconciliation. |
healthy | The number of VMs found to be healthy and correctly configured. |
starting | The number of VMs that are currently bootstrapping and are within their startup grace period. |
recreated | The number of VMs that were newly created during this run. |
staleImage | The number of healthy VMs running an image that diverges from the desired version. |
noHeartbeat | The number of VMs whose liveness heartbeat is stale. |
orphanLogged | The number of VMs found to be orphaned (discovery disabled) where only a log message was emitted. |
deprovisioned | The number of orphaned VMs that were automatically deprovisioned. |
diskGrown | The number of VMs whose boot disks were resized due to disk pressure. |
failed | The number of VMs for which reconciliation failed due to an unexpected error. |
time | The UTC timestamp when the reconciliation summary was generated. |
The service is configured via environment variables.
NOTE
Many variables have a current S2R_DISCOVERY_INGEST_* name and a legacy S2R_F5_* name. The service reads the current name first and falls back to the legacy name for one release cycle to ensure backward compatibility. The documentation lists the current name.
| Name | Type | Default | Description |
|---|---|---|---|
S2R_RELAY_VM_PROVIDER | String | gcp | The cloud provider implementation to use for VM operations. |
S2R_PROJECT_ID | String | — | The default cloud project ID for relay operations. |
S2R_DISCOVERY_INGEST_RELAY_REGION | String | me-west1 | The default cloud region for deploying relay VMs. Falls back to S2R_F5_RELAY_REGION, then S2R_REGION. |
S2R_DISCOVERY_INGEST_RELAY_ZONE | String | <region>-b | The default cloud zone for deploying relay VMs. Falls back to S2R_F5_RELAY_ZONE. |
S2R_DISCOVERY_INGEST_RELAY_MACHINE_TYPE | String | e2-standard-4 | The machine type for relay VMs. Falls back to S2R_F5_RELAY_MACHINE_TYPE. |
S2R_DISCOVERY_INGEST_RELAY_IMAGE_FAMILY | String | debian-12 | The OS image family for relay VMs. Falls back to S2R_F5_RELAY_IMAGE_FAMILY. |
S2R_DISCOVERY_INGEST_RELAY_IMAGE_PROJECT | String | debian-cloud | The cloud project containing the OS image. Falls back to S2R_F5_RELAY_IMAGE_PROJECT. |
S2R_DISCOVERY_INGEST_RELAY_SYSLOG_PORT | Integer | 514 | The TCP/UDP port on the relay VM for listening to syslog traffic. Falls back to S2R_F5_RELAY_SYSLOG_PORT. |
S2R_DISCOVERY_INGEST_RELAY_HEALTH_PORT | Integer | 18080 | The port for the relay VM's health check endpoint. Falls back to S2R_F5_RELAY_HEALTH_PORT. |
S2R_DISCOVERY_INGEST_RELAY_HTTP_TIMEOUT_SECONDS | Integer | 10 | The HTTP timeout for the relay script when forwarding data. Falls back to S2R_F5_RELAY_HTTP_TIMEOUT_SECONDS. |
S2R_DISCOVERY_INGEST_RELAY_QUEUE_MAX_ITEMS | Integer | 10000 | The in-memory queue size for the relay script. Falls back to S2R_F5_RELAY_QUEUE_MAX_ITEMS. |
S2R_DISCOVERY_INGEST_RELAY_FORWARD_WORKERS | Integer | 12 | The number of worker threads for forwarding data from the relay script. Falls back to S2R_F5_RELAY_FORWARD_WORKERS. |
S2R_DISCOVERY_INGEST_RELAY_LOCAL_INGEST_PORT | Integer | 18081 | The local port on the relay VM where the ingest container listens. Falls back to S2R_F5_RELAY_LOCAL_INGEST_PORT. |
S2R_DISCOVERY_INGEST_VM_INGEST_IMAGE | String | <region>-docker.pkg.dev/<proj>/<repo>/s2r-worker:dev | The Docker image for the local ingest container on the relay VM. Falls back to S2R_F5_VM_INGEST_IMAGE. |
S2R_DISCOVERY_INGEST_RELAY_VM_SERVICE_ACCOUNT | String | s2r-worker-sa@<proj>.iam.gserviceaccount.com | The service account email for the relay VM. Falls back to S2R_F5_RELAY_VM_SERVICE_ACCOUNT. |
S2R_DISCOVERY_INGEST_RELAY_BOOTSTRAP_TIMEOUT_SECONDS | Integer | 720 | The maximum time to wait for a new relay VM to become healthy. Falls back to S2R_F5_RELAY_BOOTSTRAP_TIMEOUT_SECONDS. |
S2R_DISCOVERY_INGEST_RELAY_STARTUP_GRACE_SECONDS | Integer | 720 | A grace period after VM creation during which health check failures do not trigger recreation. Falls back to S2R_F5_RELAY_STARTUP_GRACE_SECONDS. |
S2R_DISCOVERY_INGEST_RELAY_DIVERGENCE_GRACE_SECONDS | Integer | 900 (15 min) | The time a relay can run a divergent image before being flagged as stale. Falls back to S2R_F5_RELAY_DIVERGENCE_GRACE_SECONDS. |
S2R_DISCOVERY_INGEST_RELAY_HEARTBEAT_STALE_SECONDS | Integer | 300 (5 min) | The time after which a relay's DB heartbeat is considered stale. Falls back to S2R_F5_RELAY_HEARTBEAT_STALE_SECONDS. |
S2R_DISCOVERY_INGEST_RELAY_CONFIG_REFRESH_SECONDS | Integer | 60 | How often the relay VM should refresh its configuration from the central object store. Falls back to S2R_F5_RELAY_CONFIG_REFRESH_SECONDS. |
S2R_INGEST_DEPROVISION_ON_DISCOVERY_DISABLED | Boolean | false | If true, automatically deprovisions relay VMs whose associated discovery source is disabled. |
S2R_DISCOVERY_INGEST_RELAY_DISK_WARN_PERCENT | Integer | 75 | The disk usage percentage at which to log a S2R-RELAY-DISK-PRESSURE warning. Falls back to S2R_F5_RELAY_DISK_WARN_PERCENT. |
S2R_DISCOVERY_INGEST_RELAY_DISK_GROW_PERCENT | Integer | 85 | The disk usage percentage at which to trigger an automatic disk resize. Falls back to S2R_F5_RELAY_DISK_GROW_PERCENT. |
S2R_DISCOVERY_INGEST_RELAY_DISK_MAX_GB | Integer | 200 | The maximum size (in GiB) to which a relay VM's boot disk can be automatically grown. Falls back to S2R_F5_RELAY_DISK_MAX_GB. |
S2R_DISCOVERY_INGEST_RELAY_DISK_AUTO_EXTEND | Boolean | true | Master switch to enable or disable automatic disk extension. |
The service emits structured log messages to indicate specific conditions or failures. These can be used for alerting and diagnostics.
| Log Message / Status | Condition | Meaning and Action
| --- | --- |
| recreating status | A relay VM was found to be unhealthy and an asynchronous recreation task has been dispatched. | The system is attempting to self-heal. The process involves deleting the old VM and creating a new one, which can take several minutes. The recreation has a 15-minute timeout.
| stale-image status | A relay is running a container image that does not match the desired version, and the divergence has persisted beyond the grace period. | The relay's self-healing mechanism may have failed. The system will continue to flag this until the relay's container is updated. The relay is otherwise healthy and forwarding traffic.
| S2R-INGEST-ORPHAN | A relay VM exists for a discovery source that is currently disabled, and auto-deprovisioning is turned off. | This is an informational warning. The relay VM is left running but is considered "orphaned." To remove it, either re-enable the discovery source or enable auto-deprovisioning via S2R_INGEST_DEPROVISION_ON_DISCOVERY_DISABLED.
| S2R-RELAY-DIVERGENCE | A relay is running a container image that does not match the desired version. | This warning indicates a version mismatch that has persisted beyond the configured grace period. The relay's self-heal mechanism should eventually correct this.
| S2R-RELAY-NO-HEARTBEAT | A relay has not sent a liveness heartbeat to the database within the configured staleness threshold. | The relay VM may be offline, or its internal container may be stuck or unable to reach the database. This is a high-priority signal that ingest may have stopped. The system will eventually mark the relay as unhealthy and recreate it if it cannot recover.
| S2R-RELAY-DISK-PRESSURE | A relay's boot disk usage has exceeded the warning threshold (relayDiskWarnPercent). | This is an early warning that the disk is filling up. If auto-extend is enabled, the system will resize the disk if usage reaches the relayDiskGrowPercent threshold. If not, manual intervention may be required to free up space or resize the disk.
| S2R-RELAY-DISK-GROW | The service has initiated an automatic resize of a relay's boot disk. | This is an informational message. The system is proactively managing disk space. The relay's internal scripts will handle extending the filesystem onto the newly allocated space.
| S2R-RELAY-DISK-GROW-BLOCKED | An attempt to resize a disk was blocked. | The log message will contain a reason, such as at-max-size, unsupported-on-platform, resize-failed, or filesystem-grow-failed. This indicates that automatic disk management has hit a limit and manual intervention may be required.