Loading…
Loading…
Provides read-only access to F5 traffic logs for suggesting potential operation mappings. Fetches traffic candidates for a service version within a time
The F5TrafficAutoSuggestRepository is a read-only component that provides access to the F5 traffic log table (s2r_traffic_log). Its primary purpose is to support the "F5 traffic auto-suggestion" feature, which helps API publishers discover and map live traffic events to their service operations.
This repository is used by a higher-level service layer to fetch candidate traffic events that may correspond to a specific service. It does not modify the traffic log data; all writes to the log are handled by a separate ingestion pipeline.
The repository's queries are designed to be secure in a multi-tenant environment. All data access is strictly scoped to the tenant associated with the current request, preventing an API publisher from viewing traffic belonging to another tenant.
The repository provides methods to query the traffic log based on service identifiers and time windows. The core logic revolves around fetching potential matches, validating user selections, and providing metadata for scoring and filtering.
flowchart TD
subgraph "API Publisher"
A[Triggers auto-suggestion for a service version]
end
subgraph "Service Layer"
A --> B[Calls `findTrafficForService`]
end
subgraph "F5TrafficAutoSuggestRepository"
B --> C{Query `s2r_traffic_log`};
subgraph "SQL Query Logic"
C -- "WHERE" --> D["`observed_at` within `sinceHours`"];
C -- "AND" --> E["(`service_id` matches OR <br> `environment` + `service_key` match)"];
C -- "AND" --> F["Tenant ID matches current session"];
C -- "ORDER BY" --> G["`observed_at` DESC"];
C -- "LIMIT" --> H["`hardLimit`"];
end
end
C --> I[Returns `List<F5TrafficEventRow>`];
subgraph "Service Layer"
I --> J[Presents traffic candidates to publisher];
endThe findTrafficForService method is the main entry point for discovering traffic. It constructs a query to find relevant log entries based on a combination of resolved and unresolved service identifiers.
The query searches the s2r_traffic_log table for rows that match either of the following conditions:
service_id column in the log matches the ID of the target service. This finds traffic that was recorded after the log ingestion pipeline had already associated the traffic with a known service.environment and service_key columns in the log match the target service's attributes. This finds traffic that was not yet resolved to a specific service_id at the time of ingestion.The search is constrained to a specific time window and a maximum number of results to protect system performance. The results are returned newest-first.
Once an API publisher selects traffic events from the suggested candidates, a "confirm endpoint" in the service layer uses the findById and findByIds methods to retrieve the full details of those specific events. This step validates that the selected event IDs are legitimate and accessible to the current tenant before they are persisted as mapping evidence.
To prevent duplicate mappings, the evidenceExistsForCorrelation method is used by the confirmation endpoint. It checks if a s2r_mapping_evidence record already exists for a given service version and a traffic event's correlation_id. This makes the confirmation process idempotent, meaning that confirming the same traffic event multiple times has no additional effect after the first time.
IMPORTANT
All queries executed by this repository are strictly scoped to the current tenant's data. This is enforced by appending a TENANT_SCOPE_SQL clause to every SQL statement. This security measure ensures that even if a caller provides the UUID of a traffic event or service belonging to another tenant, the query will return no results, as if the object does not exist.
This repository exposes several public methods for querying traffic log data.
Fetches a list of candidate F5 traffic events for a given service within a specified time window. The results are ordered from newest to oldest.
The service layer that calls this method may apply additional filtering, such as a per-operation cap, on the returned results.
Parameters
| Parameter | Type | Description |
|---|---|---|
serviceId | UUID | The ID of the service for which to find traffic. |
environment | String | The service's environment (e.g., dev, stg, prd). Used for matching unresolved traffic. |
serviceKey | String | The service's canonical key. Used with environment to match unresolved traffic. |
sinceHours | int | The look-back window in hours. The value is clamped to a minimum of 1 and a maximum of 720 (30 days). |
hardLimit | int | The maximum total number of rows to return. The value is clamped to a minimum of 1 and a maximum of 5,000 to protect against excessively high traffic volumes. |
Returns
A List<F5TrafficEventRow> containing the matching traffic events, or an empty list if none are found.
Fetches a single F5 traffic event by its unique ID. This is typically used to validate a candidate selected by a user.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | UUID | The unique ID of the traffic event to fetch. |
Returns
An Optional<F5TrafficEventRow> containing the event if found and accessible by the tenant, otherwise an empty Optional.
Fetches a list of F5 traffic events for a given list of unique IDs in a single query.
Parameters
| Parameter | Type | Description |
|---|---|---|
ids | List<UUID> | A list of unique IDs of traffic events to fetch. |
Returns
A List<F5TrafficEventRow> containing the events that were found and are accessible. The list is sorted by observed_at desc, not by the input order of IDs. Returns an empty list if the input ids list is null or empty.
Looks up a service's environment, service_key, and direction. The service layer uses this information to construct the traffic query.
Parameters
| Parameter | Type | Description |
|---|---|---|
serviceId | UUID | The unique ID of the service to look up. |
Returns
An Optional<ServiceScope> containing the service's scope details, or an empty Optional if not found.
Returns the set of defined operations for a given service version. The service layer uses this information to bucket traffic candidates by operation and to calculate confidence scores.
Parameters
| Parameter | Type | Description |
|---|---|---|
serviceVersionId | UUID | The unique ID of the service version to look up. |
Returns
A List<OperationSignal> containing the details for each operation.
Checks if a mapping evidence record already exists for a given service version and correlation ID.
Parameters
| Parameter | Type | Description |
|---|---|---|
serviceVersionId | UUID | The ID of the service version. |
correlationId | String | The correlation ID from the traffic event. If null or blank, returns false. |
Returns
true if evidence already exists, false otherwise.
The repository methods return data in the form of the following record types.
Represents a single traffic event from the s2r_traffic_log table.
| Field | Type | Description |
|---|---|---|
id | UUID | The unique identifier of the traffic log entry. |
service_id | UUID | The resolved service ID, if available at time of ingestion. |
environment | String | The environment where the traffic was observed. |
service_key | String | The service key associated with the traffic. |
soap_operation_name | String | The SOAP operation name, if applicable. |
soap_action | String | The SOAP action header value, if applicable. |
waf_policy_name | String | The name of the Web Application Firewall policy applied. |
front_virtual_server | String | The name of the front-end virtual server that received the request. |
back_virtual_server | String | The name of the back-end virtual server that handled the request. |
frontend_host | String | The host name from the original request. |
frontend_uri | String | The URI path from the original request. |
backend_host | String | The host name of the backend service. |
backend_uri | String | The URI path sent to the backend service. |
request_method | String | The HTTP request method (e.g., POST, GET). |
request_payload | String | The request body. |
response_payload | String | The response body. |
result_code | String | A platform-specific result code for the transaction. |
http_status | Integer | The HTTP status code of the response. |
observed_at | OffsetDateTime | The timestamp when the traffic was observed. |
Contains identifying attributes for a service.
| Field | Type | Description |
|---|---|---|
id | UUID | The unique ID of the service. |
environment | String | The environment where the service is deployed. |
serviceKey | String | The canonical key for the service. |
direction | String | The direction of the service (e.g., inbound/outbound). |
Contains identifying attributes for a single service operation.
| Field | Type | Description |
|---|---|---|
operationId | UUID | The unique ID of the operation. |
soapAction | String | The SOAPAction header associated with the operation. |
soapOperationName | String | The name of the SOAP operation. |
restMethod | String | The HTTP method for the equivalent REST operation. |
restPath | String | The URI path for the equivalent REST operation. |
If a query for a specific id using findById or findByIds returns no results, it can mean one of two things:
Due to the strict tenant scoping, the system intentionally returns an empty result in the second case to avoid leaking information that the object exists.
The findTrafficForService method sanitizes its sinceHours and hardLimit parameters to protect system stability:
sinceHours is clamped to the range [1, 720]. A value of 0 or less will be treated as 1. A value greater than 720 (30 days) will be treated as 720.hardLimit is clamped to the range [1, 5000]. A value of 0 or less will be treated as 1. A value greater than 5000 will be treated as 5000.If you provide values outside these ranges, the query will execute with the clamped value, not the one you provided.