Skip to content

Comments

Add Circuit breaker support#1534

Merged
niveathika merged 16 commits intomasterfrom
circuit-breaker
Feb 8, 2026
Merged

Add Circuit breaker support#1534
niveathika merged 16 commits intomasterfrom
circuit-breaker

Conversation

@niveathika
Copy link
Contributor

Purpose

Fixes ballerina-platform/ballerina-library#8382

Examples

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests
  • Updated the spec
  • Checked native-image compatibility

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds circuit breaker support to the FTP library to prevent cascade failures when the FTP server is experiencing issues. The circuit breaker implementation follows the classic three-state pattern (CLOSED, OPEN, HALF_OPEN) and uses a sliding window of time buckets to track failure rates.

Changes:

  • Added circuit breaker implementation with configurable failure thresholds and sliding window tracking
  • Integrated circuit breaker checks into FTP client operations to fail fast when the server is unavailable
  • Added new CircuitBreakerOpenError error type as a subtype of ServiceUnavailableError
  • Added comprehensive configuration options for circuit breaker behavior including failure categories
  • Updated documentation and added test coverage

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
native/src/main/java/io/ballerina/stdlib/ftp/util/FtpUtil.java Added CircuitBreakerOpenError to ErrorType enum
native/src/main/java/io/ballerina/stdlib/ftp/util/FtpConstants.java Added circuit breaker constants for configuration
native/src/main/java/io/ballerina/stdlib/ftp/client/circuitbreaker/*.java Core circuit breaker implementation including state machine, health tracking, failure categorization, and configuration
native/src/main/java/io/ballerina/stdlib/ftp/client/FtpClient.java Integrated circuit breaker checks before operations and outcome recording after operations
ballerina/error.bal Added CircuitBreakerOpenError type definition
ballerina/commons.bal Added FailureCategory enum, RollingWindow and CircuitBreakerConfig types
ballerina/client_endpoint.bal Added circuitBreaker configuration field to ClientConfiguration
docs/spec/spec.md Added circuit breaker documentation including configuration, state machine, and usage examples
changelog.md Added circuit breaker feature to changelog
ballerina/tests/circuit_breaker_test.bal Added tests for circuit breaker configuration validation and basic functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@niveathika
Copy link
Contributor Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Feb 3, 2026

@niveathika I've opened a new pull request, #1535, to work on those changes. Once the pull request is ready, I'll request review from you.

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

❌ Patch coverage is 63.74408% with 153 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.64%. Comparing base (ebe3428) to head (9d506b3).
⚠️ Report is 18 commits behind head on master.

Files with missing lines Patch % Lines
.../ftp/client/circuitbreaker/FailureCategorizer.java 0.00% 83 Missing ⚠️
...dlib/ftp/client/circuitbreaker/CircuitBreaker.java 74.31% 18 Missing and 10 partials ⚠️
...tdlib/ftp/client/circuitbreaker/CircuitHealth.java 72.13% 12 Missing and 5 partials ⚠️
...java/io/ballerina/stdlib/ftp/client/FtpClient.java 83.09% 6 Missing and 6 partials ⚠️
...tp/client/circuitbreaker/CircuitBreakerConfig.java 89.28% 2 Missing and 4 partials ⚠️
...lib/ftp/client/circuitbreaker/FailureCategory.java 60.00% 3 Missing and 1 partial ⚠️
...io/ballerina/stdlib/ftp/client/FtpRetryHelper.java 75.00% 1 Missing and 1 partial ⚠️
...erina/stdlib/ftp/client/circuitbreaker/Bucket.java 94.44% 1 Missing ⚠️

❌ Your project status has failed because the head coverage (78.64%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1534      +/-   ##
============================================
- Coverage     80.38%   78.64%   -1.75%     
- Complexity      831      914      +83     
============================================
  Files            63       70       +7     
  Lines          3712     4125     +413     
  Branches        621      717      +96     
============================================
+ Hits           2984     3244     +260     
- Misses          461      587     +126     
- Partials        267      294      +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 14 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@niveathika
Copy link
Contributor Author

@copilot open a new pull request to apply changes based on the comments in this thread. Only fix the unresolved comments

Copy link
Contributor

Copilot AI commented Feb 3, 2026

@niveathika I've opened a new pull request, #1536, to work on those changes. Once the pull request is ready, I'll request review from you.

@niveathika niveathika force-pushed the circuit-breaker branch 2 times, most recently from 4b822fe to 205305d Compare February 5, 2026 04:15
Copilot AI and others added 3 commits February 6, 2026 05:21
…tter concurrency

Co-authored-by: niveathika <27669465+niveathika@users.noreply.github.com>
…it-breaker-pattern

Replace synchronized blocks with StampedLock in CircuitBreaker
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ niveathika
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 6, 2026

@niveathika niveathika merged commit 87f197d into master Feb 8, 2026
5 of 12 checks passed
@niveathika niveathika deleted the circuit-breaker branch February 12, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip GraalVM Check This will skip the GraalVM compatibility check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add circuit breaker for ftp module

4 participants