plish timer fallbacker (#31)
* plish timer fallbacker
* plish timer fallbacker
Co-authored-by: Evan <evanljp@outlook.com>
diff --git a/docs/en/setup/plugins/fallbacker_timer-fallbacker.md b/docs/en/setup/plugins/fallbacker_timer-fallbacker.md
index 29f5ebd..f78bd8c 100755
--- a/docs/en/setup/plugins/fallbacker_timer-fallbacker.md
+++ b/docs/en/setup/plugins/fallbacker_timer-fallbacker.md
@@ -3,11 +3,12 @@
This is a timer fallback trigger to process the forward failure data.
## DefaultConfig
```yaml
-# The forwarder max retry times.
-max_times: 3
-# The latency_factor is the standard retry duration, and the time for each retry is expanded by 2 times until the number
-# of retries reaches the maximum.(Time unit is millisecond.)
-latency_factor: 2000
-# The max retry latency time.(Time unit is millisecond.)
-max_latency_time: 5000
+# The forwarder max attempt times.
+max_attempts: 3
+# The exponential_backoff is the standard retry duration, and the time for each retry is expanded
+# by 2 times until the number of retries reaches the maximum.(Time unit is millisecond.)
+exponential_backoff: 2000
+# The max backoff time used in retrying, which would override the latency time when the latency time
+# with exponential increasing larger than it.(Time unit is millisecond.)
+max_backoff: 5000
```
diff --git a/plugins/fallbacker/timer/timer_fallbacker.go b/plugins/fallbacker/timer/timer_fallbacker.go
index 06e4a95..6614588 100644
--- a/plugins/fallbacker/timer/timer_fallbacker.go
+++ b/plugins/fallbacker/timer/timer_fallbacker.go
@@ -30,9 +30,9 @@
// Fallbacker is a timer fallbacker when forward fails.
type Fallbacker struct {
config.CommonFields
- MaxTimes int `mapstructure:"max_times"`
- LatencyFactor int `mapstructure:"latency_factor"`
- MaxLatencyTIme int `mapstructure:"max_latency_time"`
+ MaxAttempts int `mapstructure:"max_attempts"`
+ ExponentialBackoff int `mapstructure:"exponential_backoff"`
+ MaxBackoff int `mapstructure:"max_backoff"`
}
func (t *Fallbacker) Name() string {
@@ -45,24 +45,25 @@
func (t *Fallbacker) DefaultConfig() string {
return `
-# The forwarder max retry times.
-max_times: 3
-# The latency_factor is the standard retry duration, and the time for each retry is expanded by 2 times until the number
-# of retries reaches the maximum.(Time unit is millisecond.)
-latency_factor: 2000
-# The max retry latency time.(Time unit is millisecond.)
-max_latency_time: 5000
+# The forwarder max attempt times.
+max_attempts: 3
+# The exponential_backoff is the standard retry duration, and the time for each retry is expanded
+# by 2 times until the number of retries reaches the maximum.(Time unit is millisecond.)
+exponential_backoff: 2000
+# The max backoff time used in retrying, which would override the latency time when the latency time
+# with exponential increasing larger than it.(Time unit is millisecond.)
+max_backoff: 5000
`
}
func (t *Fallbacker) FallBack(batch event.BatchEvents, forward api.ForwardFunc) bool {
- currentLatency := t.LatencyFactor
- for i := 1; i < t.MaxTimes; i++ {
+ currentLatency := t.ExponentialBackoff
+ for i := 1; i < t.MaxAttempts; i++ {
time.Sleep(time.Duration(currentLatency) * time.Millisecond)
if err := forward(batch); err != nil {
currentLatency *= 2
- if currentLatency > t.MaxLatencyTIme {
- currentLatency = t.MaxLatencyTIme
+ if currentLatency > t.MaxBackoff {
+ currentLatency = t.MaxBackoff
}
} else {
return true
diff --git a/plugins/fallbacker/timer/timer_fallbacker_test.go b/plugins/fallbacker/timer/timer_fallbacker_test.go
index d294eb3..6c33f88 100644
--- a/plugins/fallbacker/timer/timer_fallbacker_test.go
+++ b/plugins/fallbacker/timer/timer_fallbacker_test.go
@@ -63,21 +63,21 @@
wantCount: 2,
},
{
- name: "test-recach-max_times",
+ name: "test-recach-max_attempts",
args: plugin.Config{
- "max_times": 5,
- "latency_factor": 200,
- "max_latency_time": 3000,
+ "max_attempts": 5,
+ "exponential_backoff": 200,
+ "max_backoff": 3000,
},
want: true,
wantCount: 4,
},
{
- name: "test-unrecach-max_times",
+ name: "test-unrecach-max_attempts",
args: plugin.Config{
- "max_times": 10,
- "latency_factor": 20,
- "max_latency_time": 30000000,
+ "max_attempts": 10,
+ "exponential_backoff": 20,
+ "max_backoff": 30000000,
},
want: true,
wantCount: 4,