Load Balancer
OCI Load Balancer, API version 20170115. Load balancers, backend sets, health checkers,
backends and listeners are stored and read back the way the OCI SDKs, the OCI CLI and Terraform
expect, and listeners carry traffic: each one binds a host port of its own, forwards HTTP or
TCP to its backends by the backend set's policy, and health checks run so the health operations
report OK, WARNING or CRITICAL. Everything runs in process: no sidecar container.
The real service lives on the iaas.{region}.oraclecloud.com host it shares with Networking
(oci-go-sdk loadbalancer_client.go). floci-oci serves every service on one port, so point the
Load Balancer client at the emulator endpoint as you do for Networking.
Supported operations
| Area | Operations |
|---|---|
| Load balancers | CreateLoadBalancer, GetLoadBalancer, ListLoadBalancers, UpdateLoadBalancer, DeleteLoadBalancer, ChangeLoadBalancerCompartment, UpdateLoadBalancerShape, UpdateNetworkSecurityGroups |
| Backend sets | CreateBackendSet, GetBackendSet, ListBackendSets, UpdateBackendSet, DeleteBackendSet |
| Health checkers | GetHealthChecker, UpdateHealthChecker |
| Backends | CreateBackend, GetBackend, ListBackends, UpdateBackend, DeleteBackend |
| Listeners | CreateListener, UpdateListener, DeleteListener, ListListenerRules |
| Health | GetLoadBalancerHealth, GetBackendSetHealth, GetBackendHealth, ListLoadBalancerHealths |
| Catalogs | ListShapes, ListPolicies, ListProtocols |
| Work requests | GetWorkRequest, ListWorkRequests |
Not emulated: certificates, hostnames, path route sets, rule sets, routing policies and SSL
cipher suites. Their paths answer 501 MethodNotImplemented, and their embedded maps on a load
balancer are always {}. TLS is not emulated either: an sslConfiguration on a listener or a
backend set is a 501.
Data plane
- Each listener gets its own host port from
FLOCI_OCI_SERVICES_LOADBALANCER_LISTENER_BASE_PORT..LISTENER_MAX_PORT(default14080..14179), not the listener'sport: many load balancers may each listen on 80, and the wireipAddressesshape has no port to report. The port is logged when the listener binds:
Load balancer ocid1.loadbalancer.oc1.iad.... listener http (HTTP port 80) is served on host port 14080
A listener keeps its host port across updates. When its port turns out to be taken at bind
time, it moves to another free port of the range, logs it, and stores that one. With
persistent storage it gets the same port back after a restart when that port is still free. Deleting the listener or the load balancer
releases it. When the range is used up, creating a listener is 400 LimitExceeded.
- HTTP and HTTP2 listeners proxy each request to the backend; TCP listeners relay the
connection's bytes. GRPC listeners bind no port (logged).
- Backend choice follows the backend set's policy: ROUND_ROBIN and IP_HASH (by client
address) share traffic by weight; LEAST_CONNECTIONS takes the backend with the fewest open
connections per unit of weight. An offline or drain backend, or one whose health is
CRITICAL, gets no new connection. A backup backend gets traffic only when no other backend
can take it. With no backend left, an HTTP listener answers 502 and a TCP listener closes the
connection.
- Headers: an HTTP listener drops hop-by-hop headers, and the headers a Connection header
names, in both directions, and adds X-Forwarded-For (appended
to), X-Forwarded-Host, X-Forwarded-Port (the listener's port), X-Forwarded-Proto and
X-Real-IP. With isRequestIdEnabled the requestIdHeader (default X-Request-Id) is kept
when the client sent one, generated otherwise, and set on the backend request and on the
response (oci-go-sdk load_balancer.go).
- Idle timeout: connectionConfiguration.idleTimeout when set, otherwise 60 s for HTTP and
300 s for TCP.
- Health checks run every intervalInMillis with the backend set's health checker: an HTTP
GET of urlPath that must answer returnCode with a body matching responseBodyRegex, or a
TCP connect, on port (0 is the backend's port), within timeoutInMillis. The regex is
matched against the first 64 KiB of the body. An HTTP check that runs out of time is aborted,
and the next check of that backend starts only once its connection is closed. A backend turns
CRITICAL after retries failed checks in a row and OK after as many passing ones. Each
GetBackendHealth carries the last check's healthCheckStatus (OK, INVALID_STATUS_CODE,
TIMED_OUT, REGEX_MISMATCH, CONNECT_FAILED, IO_ERROR, OFFLINE).
- Health roll-up follows the oci-go-sdk backend_set_health.go and
load_balancer_health.go rules: a backend set no listener uses, or with more than half its
backends UNKNOWN, is UNKNOWN; all OK is OK; at least half OK is WARNING; fewer is
CRITICAL. A load balancer is CRITICAL when any set is, WARNING when any set is, and OK
when all are.
- Reaching backends: ipAddress is dialled from the floci-oci process. A backend on
127.0.0.1 is the host when floci-oci runs on the host, and the floci-oci container when it
runs in Docker: there, use an address or Compose service name the container can reach, and
publish the listener port range (-p 14080-14179:14080-14179). The ports floci-oci's own
container publishes do not count as taken when a listener picks its port. A host name is resolved once
per connection. Link-local addresses such as 169.254.169.254 are refused.
- Mock mode: FLOCI_OCI_SERVICES_LOADBALANCER_MOCK=true binds no port and runs no check;
health reads UNKNOWN. That is the default in the test suite.
Wire notes
- Every mutation returns no body, CreateLoadBalancer included: only
opc-work-request-id. The work request is alreadySUCCEEDED. Terraform reads the new load balancer's id from the work request'sloadBalancerId, which every Load Balancer work request carries. - Work requests have the Load Balancer shape (
id,loadBalancerId,type,lifecycleState,message,timeAccepted,timeFinished,errorDetails), not the core one.typeis the operation name, such asCreateListener. They are read at/20170115/loadBalancerWorkRequests/{id}and listed per load balancer. - Every list is a bare JSON array. ListLoadBalancers, ListLoadBalancerHealths, the catalogs
and ListWorkRequests paginate with
limit,pageandopc-next-page. - There is no GetListener. Listeners are read from
LoadBalancer.listeners, a map keyed by listener name, as are backend sets inLoadBalancer.backendSets. - Backends are named
ipAddress:port. The name travels URL-encoded in the path (10.0.0.3%3A8080), as Terraform sends it. - Only
protocolis required on a health checker. The defaults areport0 (the backend's port),retries3,timeoutInMillis3000 andintervalInMillis10000 (from oci-go-sdkhealth_checker.go). - GetLoadBalancer and the backend set, backend and health checker reads return the load
balancer's
etag, and every mutation honoursif-match. subnetIdsandnetworkSecurityGroupIdsmust exist in the caller's tenancy and region, or the request is400 RelatedResourceNotAuthorizedOrNotFound. Networking refuses to delete a subnet or NSG a load balancer still uses.- The
flexibleshape needsshapeDetails, withminimumBandwidthInMbpsfrom 10 up tomaximumBandwidthInMbps, and that at most 8000. A fixed shape dropsshapeDetails. - A deleted load balancer stays readable as
DELETED. Its backend sets, backends, listeners and health read as404.
Quickstart
The subnet has to exist first: create one as in the Networking quickstart.
E="--endpoint http://localhost:4599"
TENANCY=ocid1.tenancy.oc1..flocilocaltenancy0000000000000000000000000000000000000000
oci lb load-balancer create $E --compartment-id "$TENANCY" --display-name web \
--shape-name flexible --shape-details '{"minimumBandwidthInMbps":10,"maximumBandwidthInMbps":100}' \
--subnet-ids '["<subnetId>"]' --wait-for-state SUCCEEDED
oci lb backend-set create $E --load-balancer-id <loadBalancerId> --name web \
--policy ROUND_ROBIN --health-checker-protocol HTTP --health-checker-url-path /health \
--wait-for-state SUCCEEDED
oci lb backend create $E --load-balancer-id <loadBalancerId> --backend-set-name web \
--ip-address 10.0.0.3 --port 8080 --wait-for-state SUCCEEDED
oci lb listener create $E --load-balancer-id <loadBalancerId> --name http \
--default-backend-set-name web --port 80 --protocol HTTP --wait-for-state SUCCEEDED
oci lb load-balancer get $E --load-balancer-id <loadBalancerId> --query 'data.listeners'
# The listener's host port is in the floci-oci log ("is served on host port 14080")
curl http://localhost:14080/
oci lb backend-health get $E --load-balancer-id <loadBalancerId> --backend-set-name web \
--backend-name 10.0.0.3:8080
Inferred behavior
These are not stated by the oci-go-sdk or oci-python-sdk models and are floci-oci's choice:
- Mutations answer
204 No Content. The SDKs read only theopc-work-request-idheader. ipAddressesis one entry,127.0.0.1, withisPublicthe opposite ofisPrivate.- The catalogs list the shapes
10Mbps-Micro,10Mbps,100Mbps,400Mbps,8000Mbpsandflexible, the policiesROUND_ROBIN,LEAST_CONNECTIONSandIP_HASH, and the protocolsHTTP,HTTP2,TCPandGRPC. Any other value is400 InvalidParameter. - A health checker without
returnCodegets 200, withoutresponseBodyRegexgets.*, and an HTTP one withouturlPathgets/. - A listener whose
defaultBackendSetNamedoes not exist is400 InvalidParameter. Deleting a backend set a listener uses, a second backend with the sameipAddress:port, a second listener on the same port, a duplicate name and deleting a load balancer withisDeleteProtectionEnabledare all409 Conflict. - Work request ids are the shared
ocid1.coreservicesworkrequestOCIDs. - Data plane: the host port per listener, the 60 s and 300 s idle timeouts, a backend's first
health check deciding its status at once, traffic reaching a backend before its first check,
an
offlinebackend readingCRITICALwithhealthCheckStatusOFFLINE, an empty backend set readingUNKNOWN, a load balancer withOKsets and at most halfUNKNOWNones readingWARNING, the502with no backend left, and the forwarded headers (taken from the Load Balancer documentation, not the SDK models).healthCheckResultsholds one entry, fromsourceIpAddress127.0.0.1, since floci-oci runs one load balancer node.
Notes & limitations
- Not in the data plane: TLS (listeners and backend sets reject
sslConfiguration), session persistence,backendMaxConnectionsandmaxConnections, WebSocket upgrades, GRPC, and the backend TCP proxy protocol. ipModeandipv6SubnetCidrare accepted but have no effect. Reserved IPs are not emulated:reservedIpson create or update is a501.ListLoadBalancersignoresdetail: the full shape is always returned.