Loading…
Loading…
Describes the automated service that periodically refreshes the master discovery table from observed traffic for F5 and generic API gateways.
The Master Discovery Refresh Service is a background process responsible for populating and maintaining the s2r_master_discovery materialized table. This table serves as a pre-computed cache of all discovered API services, which allows the user-facing API to respond quickly without performing expensive data computations in the request path.
The service operates on a configurable schedule. In each run, it queries live traffic data from API gateways, processes this data through a series of enrichment and aggregation steps, and then "upserts" the results into the master discovery table.
It supports two main sources of traffic data:
gateway_type) and specific gateway instance (connector_instance_id).The service can also be triggered manually for a specific F5 instance or generic gateway scope, which is useful for bootstrapping a new gateway or forcing an immediate refresh.
The service's primary function is a scheduled job that orchestrates the refresh process for all configured gateways. To prevent data corruption from concurrent writes, the service uses a locking mechanism at multiple levels: a global lock for the entire scheduled cycle, and per-instance or per-scope locks for individual refresh operations.
The scheduledRefresh method is the main entry point, triggered by an internal scheduler.
flowchart TD
A[Scheduler triggers refresh] --> B{Service enabled?};
B -- No --> Z[Stop];
B -- Yes --> C{Acquire global cycle lock};
C -- Failure (already running) --> Z;
C -- Success --> D[Find all enabled F5 instances];
D --> E[For each F5 instance...];
E --> F["Run F5 Refresh Logic (see below)"];
F --> E;
E -- All F5 instances processed --> G[Find generic gateway scopes with traffic];
G --> H[For each generic scope...];
H --> I["Run Generic Refresh Logic (see below)"];
I --> H;
H -- All generic scopes processed --> J[Release global cycle lock];The cycle performs the following high-level steps:
s2r.master-discovery.refresh.enabled) and if a refresh cycle is already running. If not, it proceeds.refreshInstance method. Errors during the refresh of one instance are logged but do not stop the cycle from processing other instances.refreshGenericVendors to handle all non-F5 traffic. This method identifies all unique combinations of generic gateway vendors and instances (gateway_type, connector_instance_id) that have observed traffic.refreshGenericVendor method. Errors are isolated per scope.The refreshInstance(UUID instanceId) method processes data for a single F5 gateway instance.
IMPORTANT
This process is serialized per instance. If a scheduled refresh and a manual call to refreshInstance for the same ID occur simultaneously, one will be skipped to prevent race conditions. A debug message is logged: Master discovery refresh already in progress for {instanceId}; skipping duplicate request.
The refresh follows these steps:
f5LearningRepository.computeMasterDiscoveryLive. The computation is capped at a limit of 5,000 rows.serviceUri is empty or simply /.serviceUriCanonical and environment. This step uses environment definitions and a vocabulary of known operation names to correctly group the data.serviceUriCanonical and environment.serviceBackendUrl against the service inventory. If a match is found, the serviceId and serviceStatus fields are populated.discoveryStatus is set to complete or incomplete based on the logic in the isComplete method (see below).s2r_master_discovery table. This operation updates existing rows or inserts new ones.The refreshGenericVendor(String gatewayType, UUID connectorInstanceId) method processes data for a single non-F5 gateway scope. This flow is a streamlined version of the F5 path.
NOTE
This path intentionally skips F5-specific enrichment steps, such as applying topology data or manual overrides. The resulting rows in the master discovery table are marked with source='generic'.
The refresh follows these steps:
gatewayType and connectorInstanceId by calling f5LearningRepository.computeMasterDiscoveryLiveGeneric. The computation is capped at a limit of 5,000 rows.s2r_master_discovery table, scoped to the gatewayType and connectorInstanceId.A discovered service row is marked with a discoveryStatus of complete if it meets a specific set of criteria, indicating that enough information has been gathered to consider it fully identified. A row is considered "complete" if it satisfies all of the following conditions:
serviceUri.environment.serviceBackendUrl or a non-empty list of serviceBackendUrls.frontVirtualServers list AND either a non-empty backVirtualServers list or a non-blank dataPowerDomain.If these conditions are not met, the discoveryStatus is set to incomplete.
A successful refresh for an F5 instance will produce a log message similar to the following, indicating the number of master service rows and associated consumer rows that were updated or inserted.
INFO Master discovery refresh for instance {instanceId}: 42 master rows + 120 consumer rows in 1532ms
Similarly, a successful refresh for a generic gateway scope will produce a log message like this:
INFO Master discovery refresh for generic scope my-vendor/a1b2c3d4-e5f6-7890-1234-567890abcdef: 15 master rows + 35 consumer rows in 890ms (source=generic)
The service's schedule is configured via application properties.
IMPORTANT
The scheduling parameters (initial-delay-ms, delay-ms) are read at service startup. A restart is required for any changes to take effect.
| Parameter | Type | Default | Description |
|---|---|---|---|
s2r.master-discovery.refresh.enabled | Boolean | true | If true, enables the scheduled refresh job. If false, the periodic refresh cycle is disabled. |
s2r.master-discovery.refresh.initial-delay-ms | Long | 180000 | The initial delay in milliseconds after service startup before the first refresh cycle begins. (3 minutes) |
s2r.master-discovery.refresh.delay-ms | Long | 600000 | The fixed delay in milliseconds between the completion of one refresh cycle and the start of the next. (10 minutes) |
NOTE
At startup, the service logs the "active delay" by checking the master_discovery_refresh_delay_ms key in the SystemSettingRepository. While this provides visibility into the intended configuration, the actual schedule is controlled by the s2r.master-discovery.refresh.delay-ms application property, which requires a service restart to change.
While not exposed via HTTP, the service has public methods that can be invoked by other components within the platform for synchronous refreshes.
| Method | Parameters | Return Type | Description |
|---|---|---|---|
refreshInstance(UUID instanceId) | instanceId: The UUID of the F5 instance to refresh. | int | Synchronously triggers a refresh for a single F5 instance. Returns the number of master rows upserted. |
refreshGenericVendor(String gatewayType, UUID connectorInstanceId) | gatewayType: The vendor identifier. <br> connectorInstanceId: The specific gateway instance UUID. Can be null for traffic not attributed to a specific instance of a vendor. | int | Synchronously triggers a refresh for a single generic gateway scope. Returns the number of master rows upserted. |
refreshGenericVendors() | (none) | void | Triggers a refresh for all generic gateway vendors that have observed traffic. |
scheduledRefresh() | (none) | void | The main entry point for the scheduler. Manually calling this method is equivalent to a scheduled run. |
The service logs detailed messages for both successful and failed operations. The following are common warnings and errors.
| Log Message | Trigger | Impact |
|---|---|---|
Master discovery refresh failed for instance {id}: {message} | An unhandled exception occurred during the refreshInstance method for a specific F5 instance. | The refresh for that specific instance is aborted. The error is logged, and the scheduled cycle proceeds to the next instance. |