From 9f0e30c06ba13f7c63d2d9ec202a5ba36425cd4c Mon Sep 17 00:00:00 2001 From: DeshDeepakKant Date: Tue, 21 Jan 2025 22:17:05 +0530 Subject: [PATCH 1/4] docs(circuit-breaker): Add comprehensive KMesh Circuit Breaker user guide - Implement detailed documentation for Circuit Breaker feature - Include technical implementation details - Provide configuration examples and best practices - Cover troubleshooting and monitoring aspects Signed-off-by: Desh Deepak Kant Closes #103 Signed-off-by: DeshDeepakKant --- content/en/docs/userguide/circuit_breaker.md | 253 +++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 content/en/docs/userguide/circuit_breaker.md diff --git a/content/en/docs/userguide/circuit_breaker.md b/content/en/docs/userguide/circuit_breaker.md new file mode 100644 index 0000000..1359d51 --- /dev/null +++ b/content/en/docs/userguide/circuit_breaker.md @@ -0,0 +1,253 @@ +--- +draft: false +linktitle: Circuit Breaker +menu: + docs: + parent: user guide + weight: 22 +title: Use Circuit Breaker +toc: true +type: docs +--- + +### Preparation + +1. Ensure KMesh is installed in your Kubernetes cluster (see [Quick Start Guide](https://kmesh.net/en/docs/setup/quickstart/)) + +2. Deploy a sample microservice application + +3. Verify the default namespace is managed by KMesh + +### Circuit Breaker Configuration + +##### Deploy a Sample Application + +Let's use a simple microservice setup to demonstrate circuit breaking: + +```bash +kubectl apply -f - <active_connections >= cbs->max_connections) { + // Reject connection + return -1; + } + // Bind socket to cluster + return 0; +} +``` + +### Advanced Configuration Example + +```yaml +apiVersion: kmesh.net/v1alpha1 +kind: CircuitBreaker +metadata: + name: complex-service-circuit-breaker +spec: + services: + - name: service-a + rules: + - priority: HIGH + maxConnections: 50 + - name: service-b + rules: + - priority: MEDIUM + maxConnections: 100 +``` + +### Troubleshooting + +##### Common Issues +- Unexpected connection rejections +- High error rates +- Performance degradation + +##### Debugging Steps + +```bash +# Check circuit breaker configuration +kubectl describe circuitbreaker sample-service-circuit-breaker + +# View detailed logs +kubectl logs -n kmesh -l app=kmesh circuit-breaker -c circuit-breaker + +# Check cluster status +kmesh get clusters +``` + +### Best Practices + +1. Start with conservative limits +2. Gradually adjust based on service performance +3. Monitor circuit breaker metrics +4. Use priority-based configurations + +### Performance Considerations + +- Kernel-native implementation +- Minimal overhead +- Lock-free atomic updates +- eBPF map-based tracking + +### Cleanup + +Remove the circuit breaker and sample application: + +```bash +kubectl delete circuitbreaker sample-service-circuit-breaker +kubectl delete deployment sample-service +kubectl delete service sample-service +``` + +### Limitations + +- Currently focuses on TCP connections +- Kernel version dependencies +- Per-cluster granularity + +### Sample Code Snippet + +```go +// Circuit Breaker Configuration Example +circuitBreaker := &CircuitBreakers{ + Priority: RoutingPriority_HIGH, + MaxConnections: 100, + MaxPendingRequests: 50, + MaxRequests: 200, + MaxRetries: 3, +} +``` \ No newline at end of file From 27bda7ecfe7e81f766c8af46284d2653847127ae Mon Sep 17 00:00:00 2001 From: DeshDeepakKant Date: Thu, 23 Jan 2025 19:27:07 +0530 Subject: [PATCH 2/4] docs: add circuit breaker user guide with Fortio testing Signed-off-by: DeshDeepakKant --- content/en/docs/userguide/circuit_breaker.md | 311 ++++++++----------- 1 file changed, 137 insertions(+), 174 deletions(-) diff --git a/content/en/docs/userguide/circuit_breaker.md b/content/en/docs/userguide/circuit_breaker.md index 1359d51..ea883df 100644 --- a/content/en/docs/userguide/circuit_breaker.md +++ b/content/en/docs/userguide/circuit_breaker.md @@ -1,253 +1,216 @@ --- draft: false -linktitle: Circuit Breaker +linktitle: Circuit Breaker menu: docs: parent: user guide weight: 22 -title: Use Circuit Breaker +title: Circuit Breaker toc: true type: docs --- -### Preparation +This task shows you how to configure circuit breakers in KMesh using Fortio for load testing. -1. Ensure KMesh is installed in your Kubernetes cluster (see [Quick Start Guide](https://kmesh.net/en/docs/setup/quickstart/)) +### Before you begin -2. Deploy a sample microservice application +- Install KMesh + Please refer [quickstart](https://kmesh.net/en/docs/setup/quickstart/) and change into ads mode -3. Verify the default namespace is managed by KMesh -### Circuit Breaker Configuration +### Deploy the test applications -##### Deploy a Sample Application - -Let's use a simple microservice setup to demonstrate circuit breaking: - -```bash -kubectl apply -f - <active_connections >= cbs->max_connections) { - // Reject connection - return -1; - } - // Bind socket to cluster - return 0; -} -``` +#### 4.2 Circuit Breaker Test +```bash +# Heavy load to trigger circuit breaker +kubectl exec -it deploy/fortio -- \ +fortio load -c 5 -qps 100 -t 30s http://test-service -### Advanced Configuration Example +# Verify circuit breaker status +kubectl get destinationrule test-circuit-breaker -o yaml -```yaml -apiVersion: kmesh.net/v1alpha1 -kind: CircuitBreaker -metadata: - name: complex-service-circuit-breaker -spec: - services: - - name: service-a - rules: - - priority: HIGH - maxConnections: 50 - - name: service-b - rules: - - priority: MEDIUM - maxConnections: 100 +# Simulate service failure +kubectl scale deployment test-service --replicas=0 ``` +#### 4.3 Recovery Test +```bash +# Restore service +kubectl scale deployment test-service --replicas=1 -### Troubleshooting - -##### Common Issues -- Unexpected connection rejections -- High error rates -- Performance degradation +# Test recovery +kubectl exec -it deploy/fortio -- \ +fortio load -c 2 -qps 20 -t 30s http://test-service +``` -##### Debugging Steps +### Analyzing Results +#### 6.1 Fortio Results ```bash -# Check circuit breaker configuration -kubectl describe circuitbreaker sample-service-circuit-breaker +# View test results +kubectl logs deploy/fortio -# View detailed logs -kubectl logs -n kmesh -l app=kmesh circuit-breaker -c circuit-breaker - -# Check cluster status -kmesh get clusters +# Get detailed metrics +kubectl exec -it deploy/fortio -- /usr/bin/fortio report ``` -### Best Practices +#### 6.2 System Metrics +```bash +# Check pod status +kubectl get pods -w -1. Start with conservative limits -2. Gradually adjust based on service performance -3. Monitor circuit breaker metrics -4. Use priority-based configurations +# View circuit breaker configuration +kubectl get destinationrule test-circuit-breaker -o yaml +``` -### Performance Considerations +### Understanding what happened -- Kernel-native implementation -- Minimal overhead -- Lock-free atomic updates -- eBPF map-based tracking +The circuit breaker configuration: +- Limits concurrent HTTP requests +- Ejects hosts after 3 consecutive errors +- Keeps circuit open for 30 seconds +- Monitors service health every 5 seconds -### Cleanup +When the service is overloaded: +1. Circuit breaker trips after threshold breach +2. Subsequent requests are blocked +3. Service recovers after baseEjectionTime +4. Normal traffic flow resumes -Remove the circuit breaker and sample application: +### Clean up +Remove test components: ```bash -kubectl delete circuitbreaker sample-service-circuit-breaker -kubectl delete deployment sample-service -kubectl delete service sample-service +kubectl delete -f sample-app.yaml +kubectl delete -f fortio.yaml +kubectl delete -f circuit-breaker.yaml ``` -### Limitations +### Troubleshooting -- Currently focuses on TCP connections -- Kernel version dependencies -- Per-cluster granularity +If you encounter issues: +1. Check pod status: +```bash +kubectl get pods +kubectl describe pod +``` -### Sample Code Snippet +2. Check circuit breaker configuration: +```bash +kubectl get destinationrule +kubectl describe destinationrule test-circuit-breaker +``` -```go -// Circuit Breaker Configuration Example -circuitBreaker := &CircuitBreakers{ - Priority: RoutingPriority_HIGH, - MaxConnections: 100, - MaxPendingRequests: 50, - MaxRequests: 200, - MaxRetries: 3, -} +3. View application logs: +```bash +kubectl logs deploy/test-service +kubectl logs deploy/fortio ``` \ No newline at end of file From 6bea74657cfbcd45141ec5484b1f2345f28a1cc3 Mon Sep 17 00:00:00 2001 From: DeshDeepakKant Date: Fri, 24 Jan 2025 03:50:54 +0530 Subject: [PATCH 3/4] updated circuit-breaker.yaml Signed-off-by: DeshDeepakKant --- content/en/docs/userguide/circuit_breaker.md | 21 +++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/content/en/docs/userguide/circuit_breaker.md b/content/en/docs/userguide/circuit_breaker.md index ea883df..0d7475d 100644 --- a/content/en/docs/userguide/circuit_breaker.md +++ b/content/en/docs/userguide/circuit_breaker.md @@ -83,21 +83,18 @@ spec: Apply the circuit breaker configuration: ```yaml # circuit-breaker.yaml -apiVersion: networking.istio.io/v1alpha3 -kind: DestinationRule +apiVersion: kmesh.net/v1alpha1 +kind: CircuitBreaker metadata: name: test-circuit-breaker spec: - host: test-service - trafficPolicy: - connectionPool: - http: - http1MaxPendingRequests: 1 - maxRequestsPerConnection: 1 - outlierDetection: - consecutive5xxErrors: 3 - interval: 5s - baseEjectionTime: 30s + service: test-service + rules: + - priority: HIGH + maxConnections: 10 + maxPendingRequests: 5 + maxRequests: 20 + maxRetries: 3 ``` Apply the configurations: From 0a17ca54bee2ffbe9e634a5b9f623a9dc0182ec7 Mon Sep 17 00:00:00 2001 From: DeshDeepakKant Date: Sun, 9 Feb 2025 01:08:06 +0530 Subject: [PATCH 4/4] Fix: Update circuit breaker documentation (removed rate-limit.md) Signed-off-by: DeshDeepakKant --- content/en/docs/userguide/circuit_breaker.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/content/en/docs/userguide/circuit_breaker.md b/content/en/docs/userguide/circuit_breaker.md index 0d7475d..9c437df 100644 --- a/content/en/docs/userguide/circuit_breaker.md +++ b/content/en/docs/userguide/circuit_breaker.md @@ -148,6 +148,22 @@ kubectl exec -it deploy/fortio -- \ fortio load -c 2 -qps 20 -t 30s http://test-service ``` +### Sample Test Results + +#### Without Circuit Breaker +``` +IP addresses distribution: 10.96.230.153:80: 5 +Code 200 : 3000 (100.0 %) +``` + +#### With Circuit Breaker +``` +IP addresses distribution: 10.96.230.153:80: 5 +Code 200 : 1914 (63.8%) +Code 503 : 1086 (36.2%) +``` + + ### Analyzing Results #### 6.1 Fortio Results @@ -210,4 +226,4 @@ kubectl describe destinationrule test-circuit-breaker ```bash kubectl logs deploy/test-service kubectl logs deploy/fortio -``` \ No newline at end of file +```