Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error_rate greater 0.5 #118

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ var ErrorDelay = fmt.Errorf("Service delay automatically injected")

// Injector allows errors and ratelmiting to be injected to a service
type Injector struct {
logger hclog.Logger
errorPercentage float64
errorCode int
errorType string
errorDelay time.Duration
rateLimitRPS float64
rateLimitBurst int
rateLimitCode int
logger hclog.Logger
errorPercentage float64
errorTriggerThreshold float64
errorCode int
errorType string
errorDelay time.Duration
rateLimitRPS float64
rateLimitBurst int
rateLimitCode int

limiter *rate.Limiter
requestCount int
Expand Down Expand Up @@ -76,7 +77,9 @@ func (e *Injector) Do() *Response {
}

// calculate if we need to throw an error or continue as normal
if e.requestCount%int(1/e.errorPercentage) == 0 {
e.errorTriggerThreshold += e.errorPercentage
if e.errorTriggerThreshold >= 1 {
e.errorTriggerThreshold -= 1
e.logger.Info("Injecting error", "request_count", e.requestCount, "error_percentage", e.errorPercentage, "error_type", e.errorType)

// is our error a delay or a timeout
Expand Down