Skip to content

Commit 321f7ae

Browse files
author
Kate Osborn
committed
Remove circuit breaker API and add backup server to upstream settings
1 parent 75da747 commit 321f7ae

File tree

2 files changed

+3
-100
lines changed

2 files changed

+3
-100
lines changed
-33.2 KB
Loading

docs/proposals/nginx-extensions.md

Lines changed: 3 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ NGINX is highly configurable and offers rich features that can benefit our users
5858
- [Proxy Settings](#proxy-settings)
5959
- [Future Work](#future-work-6)
6060
- [Alternatives](#alternatives-7)
61-
- [Circuit Breaker/ Backup service](#circuit-breaker-backup-service)
62-
- [Options](#options)
6361
- [Testing](#testing)
6462
- [Security Considerations](#security-considerations)
6563
- [Alternatives Considered](#alternatives-considered)
@@ -491,7 +489,7 @@ To identify the set of NGINX directives and parameters NGINX Gateway Fabric shou
491489

492490
| Features | Requires NGINX Plus |
493491
|----------------------------------------------------------------------------------------|---------------------|
494-
| Circuit breaker | |
492+
| Backup server | |
495493
| Load-balancing method | |
496494
| Load-balancing method (least time) | X |
497495
| Limit connections to a server | |
@@ -736,6 +734,7 @@ OSS Features:
736734
- Load-balancing method (all except `least_time`)
737735
- Limit connections to server
738736
- Passive health checks
737+
- Backup server
739738

740739
OSS NGINX directives/parameters:
741740

@@ -748,6 +747,7 @@ OSS NGINX directives/parameters:
748747
- [`max_conns`](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#server)
749748
- [`fail_timeout`](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#server)
750749
- [`max_fails`](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#server)
750+
- [`backup`](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#server)
751751

752752
NGINX Plus Features:
753753

@@ -891,103 +891,6 @@ NGINX directives:
891891

892892
- Direct Policy: If there's no strong use case for the Cluster Operator setting sane defaults for these settings, then we can use a Direct Policy. The Direct Policy could attach to an HTTPRoute or HTTPRoute Rule, and the NGINX contexts would be server and location.
893893

894-
### Circuit Breaker/ Backup service
895-
896-
_Extension type:_ BackendRef/Direct Policy
897-
898-
_Resource type:_ CRD
899-
900-
_Role(s):_ Application Developer
901-
902-
_Extension point:_ Backend
903-
904-
_NGINX context(s):_ upstream
905-
906-
Features:
907-
908-
- Backup service/circuit breaker
909-
910-
NGINX upstream server parameters:
911-
912-
- [`backup`](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#server)
913-
914-
Circuit Breaker also relies on the following NGINX upstream server parameters:
915-
916-
- [`fail_timeout`](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#server)
917-
- [`max_fails`](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#server)
918-
919-
However, these parameters are also used in passive health checks, which is a part of the Upstream Settings Policy. We can either expose these settings in both extensions (not recommended by the Gateway API), or the Circuit Breaker extensions can use the values of these parameters set by the Upstream Settings Policy.
920-
921-
This [NGINX blog post](https://www.nginx.com/blog/microservices-reference-architecture-nginx-circuit-breaker-pattern/) describes the circuit breaker pattern and how to implement it with NGINX plus. The solution involves active health checks, rate-limiting, caching, and the `backup` directive. While this might be a complete solution, it is likely too heavyweight for NGINX Gateway Fabric.
922-
923-
The NGINX Kubernetes projects, NGINX Service Mesh and NGINX Ingress Controller offer alternatives to this solution.
924-
925-
NGINX Ingress Controller supports setting a [backup Service](https://github.com/nginxinc/kubernetes-ingress/tree/release-3.4/examples/custom-resources/backup-directive/virtual-server) that will be used when the primary servers are unavailable. The backup service must be of type ExternalName.
926-
927-
NGINX Service Mesh implements circuit breaking with a [CRD](https://github.com/nginxinc/nginx-service-mesh/blob/main/pkg/apis/specs/v1alpha1/circuit_breaker.go).
928-
929-
Here's an example:
930-
931-
```yaml
932-
apiVersion: specs.smi.nginx.com/v1alpha1
933-
kind: CircuitBreaker
934-
metadata:
935-
name: circuit-breaker-example
936-
namespace: default
937-
spec:
938-
destination:
939-
kind: Service
940-
name: target-svc
941-
namespace: default
942-
errors: 3
943-
timeoutSeconds: 30
944-
fallback:
945-
service: default/target-backup
946-
port: 80
947-
```
948-
949-
The `spec.destination` field is similar to `targetRef` in that it attaches the CircuitBreaker setting to an object. This example configures a circuit breaker that will trip when there are three errors within 30 seconds. If the circuit breaker trips, requests to the destination Service will be routed to the fallback Service. After 30 seconds, the circuit breaker will reset, and the requests will be routed to the destination Service again. This implementation uses the NGINX `max_fails`, `fail_timeout`, and `backup` upstream server parameters.
950-
951-
NGINX Gateway Fabric could choose one of these approaches or design something new. It's difficult to propose an extension type for circuit breaker without more discussion and design. The next section outlines some options.
952-
953-
#### Options
954-
955-
- Add `backup` to Upstream Settings Policy: The `fail_timeout` and `max_fails` directives are also used in passive health checks, which is a part of the Upstream Settings Policy. Including circuit breaking -- or just the `backup` directive -- might make more sense in this Policy. This approach is similar to the NGINX Ingress Controller solution.
956-
- Direct Policy: A Direct Policy, similar to the NGINX Service Mesh example. This Policy would target a Backend and would define a fallback Service. Optionally, this Policy could also include the `fail_timeout` and `max_fails` settings, but this could cause conflicts with the Upstream Settings Policy.
957-
- Custom BackendRef: Allow users to configure a primary and fallback Service via a custom BackendRef that they can reference in an xRoute:
958-
959-
```yaml
960-
apiVersion: gateway.nginx.org/v1alpha1
961-
kind: CircuitBreaker
962-
metadata:
963-
name: circuit-breaker-example
964-
spec:
965-
primary:
966-
service: coffee-primary
967-
port: 80
968-
fallback:
969-
service: coffee-backup
970-
port: 80
971-
---
972-
apiVersion: gateway.networking.k8s.io/v1
973-
kind: HTTPRoute
974-
metadata:
975-
name: custom-backend
976-
spec:
977-
hostnames:
978-
- "example.com"
979-
rules:
980-
- matches:
981-
- path:
982-
type: PathPrefix
983-
value: /
984-
backendRefs:
985-
- group: gateway.nginx.org/v1alpha1
986-
kind: CircuitBreaker
987-
name: circuit-breaker-example
988-
port: 80
989-
```
990-
991894
## Testing
992895

993896
Each extension will be tested with a combination of unit and system tests. The details of the tests are out of scope for this Enhancement Proposal.

0 commit comments

Comments
 (0)