You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- 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.
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
-
991
894
## Testing
992
895
993
896
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