Skip to content

Commit

Permalink
fix: fix all golangci-lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Lindamood authored and cep21 committed Jan 19, 2024
1 parent 6dabe1d commit cd576eb
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 76 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ issues:
- linters:
- gosec
text: "G404"
- linters:
- gosec
text: "G114"
4 changes: 2 additions & 2 deletions circuit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,11 @@ type closeOnFirstErrorOpener struct {
isOpened bool
}

func (o *closeOnFirstErrorOpener) ShouldOpen(ctx context.Context, _ time.Time) bool {
func (o *closeOnFirstErrorOpener) ShouldOpen(_ context.Context, _ time.Time) bool {
o.isOpened = true
return true
}
func (o *closeOnFirstErrorOpener) Prevent(ctx context.Context, _ time.Time) bool {
func (o *closeOnFirstErrorOpener) Prevent(_ context.Context, _ time.Time) bool {
return o.isOpened
}

Expand Down
44 changes: 22 additions & 22 deletions closers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ type neverOpens struct{}

var _ ClosedToOpen = neverOpens{}

func (c neverOpens) Prevent(ctx context.Context, now time.Time) bool {
func (c neverOpens) Prevent(_ context.Context, _ time.Time) bool {
return false
}

func (c neverOpens) Success(ctx context.Context, now time.Time, duration time.Duration) {}
func (c neverOpens) ErrFailure(ctx context.Context, now time.Time, duration time.Duration) {}
func (c neverOpens) ErrTimeout(ctx context.Context, now time.Time, duration time.Duration) {}
func (c neverOpens) ErrBadRequest(ctx context.Context, now time.Time, duration time.Duration) {}
func (c neverOpens) ErrInterrupt(ctx context.Context, now time.Time, duration time.Duration) {}
func (c neverOpens) ErrConcurrencyLimitReject(ctx context.Context, now time.Time) {}
func (c neverOpens) ErrShortCircuit(ctx context.Context, now time.Time) {}
func (c neverOpens) Opened(ctx context.Context, now time.Time) {}
func (c neverOpens) Closed(ctx context.Context, now time.Time) {}
func (c neverOpens) Success(_ context.Context, _ time.Time, _ time.Duration) {}
func (c neverOpens) ErrFailure(_ context.Context, _ time.Time, _ time.Duration) {}
func (c neverOpens) ErrTimeout(_ context.Context, _ time.Time, _ time.Duration) {}
func (c neverOpens) ErrBadRequest(_ context.Context, _ time.Time, _ time.Duration) {}
func (c neverOpens) ErrInterrupt(_ context.Context, _ time.Time, _ time.Duration) {}
func (c neverOpens) ErrConcurrencyLimitReject(_ context.Context, _ time.Time) {}
func (c neverOpens) ErrShortCircuit(_ context.Context, _ time.Time) {}
func (c neverOpens) Opened(_ context.Context, _ time.Time) {}
func (c neverOpens) Closed(_ context.Context, _ time.Time) {}

func (c neverOpens) ShouldOpen(ctx context.Context, now time.Time) bool {
func (c neverOpens) ShouldOpen(_ context.Context, _ time.Time) bool {
return false
}

Expand All @@ -63,19 +63,19 @@ type neverCloses struct{}

var _ OpenToClosed = neverCloses{}

func (c neverCloses) Allow(ctx context.Context, now time.Time) bool {
func (c neverCloses) Allow(_ context.Context, _ time.Time) bool {
return false
}

func (c neverCloses) Success(ctx context.Context, now time.Time, duration time.Duration) {}
func (c neverCloses) ErrFailure(ctx context.Context, now time.Time, duration time.Duration) {}
func (c neverCloses) ErrTimeout(ctx context.Context, now time.Time, duration time.Duration) {}
func (c neverCloses) ErrBadRequest(ctx context.Context, now time.Time, duration time.Duration) {}
func (c neverCloses) ErrInterrupt(ctx context.Context, now time.Time, duration time.Duration) {}
func (c neverCloses) ErrConcurrencyLimitReject(ctx context.Context, now time.Time) {}
func (c neverCloses) ErrShortCircuit(ctx context.Context, now time.Time) {}
func (c neverCloses) Opened(ctx context.Context, now time.Time) {}
func (c neverCloses) Closed(ctx context.Context, now time.Time) {}
func (c neverCloses) ShouldClose(ctx context.Context, now time.Time) bool {
func (c neverCloses) Success(_ context.Context, _ time.Time, _ time.Duration) {}
func (c neverCloses) ErrFailure(_ context.Context, _ time.Time, _ time.Duration) {}
func (c neverCloses) ErrTimeout(_ context.Context, _ time.Time, _ time.Duration) {}
func (c neverCloses) ErrBadRequest(_ context.Context, _ time.Time, _ time.Duration) {}
func (c neverCloses) ErrInterrupt(_ context.Context, _ time.Time, _ time.Duration) {}
func (c neverCloses) ErrConcurrencyLimitReject(_ context.Context, _ time.Time) {}
func (c neverCloses) ErrShortCircuit(_ context.Context, _ time.Time) {}
func (c neverCloses) Opened(_ context.Context, _ time.Time) {}
func (c neverCloses) Closed(_ context.Context, _ time.Time) {}
func (c neverCloses) ShouldClose(_ context.Context, _ time.Time) bool {
return false
}
22 changes: 11 additions & 11 deletions closers/hystrix/closer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ func (s *Closer) MarshalJSON() ([]byte, error) {
var _ json.Marshaler = &Closer{}

// Opened circuit. It should now check to see if it should ever allow various requests in an attempt to become closed
func (s *Closer) Opened(ctx context.Context, now time.Time) {
func (s *Closer) Opened(_ context.Context, now time.Time) {
s.concurrentSuccessfulAttempts.Set(0)
s.reopenCircuitCheck.SleepStart(now)
}

// Closed circuit. It can turn off now.
func (s *Closer) Closed(ctx context.Context, now time.Time) {
func (s *Closer) Closed(_ context.Context, now time.Time) {
s.concurrentSuccessfulAttempts.Set(0)
s.reopenCircuitCheck.SleepStart(now)
}
Expand All @@ -96,43 +96,43 @@ func (s *Closer) Closed(ctx context.Context, now time.Time) {
// The circuit is currently closed. Check and return true if this request should be allowed. This will signal
// the circuit in a "half-open" state, allowing that one request.
// If any requests are allowed, the circuit moves into a half open state.
func (s *Closer) Allow(ctx context.Context, now time.Time) (shouldAllow bool) {
func (s *Closer) Allow(_ context.Context, now time.Time) (shouldAllow bool) {
return s.reopenCircuitCheck.Check(now)
}

// Success any time runFunc was called and appeared healthy
func (s *Closer) Success(ctx context.Context, now time.Time, duration time.Duration) {
func (s *Closer) Success(_ context.Context, _ time.Time, _ time.Duration) {
s.concurrentSuccessfulAttempts.Add(1)
}

// ErrBadRequest is ignored
func (s *Closer) ErrBadRequest(ctx context.Context, now time.Time, duration time.Duration) {
func (s *Closer) ErrBadRequest(_ context.Context, _ time.Time, _ time.Duration) {
}

// ErrInterrupt is ignored
func (s *Closer) ErrInterrupt(ctx context.Context, now time.Time, duration time.Duration) {
func (s *Closer) ErrInterrupt(_ context.Context, _ time.Time, _ time.Duration) {
}

// ErrConcurrencyLimitReject is ignored
func (s *Closer) ErrConcurrencyLimitReject(ctx context.Context, now time.Time) {
func (s *Closer) ErrConcurrencyLimitReject(_ context.Context, _ time.Time) {
}

// ErrShortCircuit is ignored
func (s *Closer) ErrShortCircuit(ctx context.Context, now time.Time) {
func (s *Closer) ErrShortCircuit(_ context.Context, _ time.Time) {
}

// ErrFailure resets the consecutive Successful count
func (s *Closer) ErrFailure(ctx context.Context, now time.Time, duration time.Duration) {
func (s *Closer) ErrFailure(_ context.Context, _ time.Time, _ time.Duration) {
s.concurrentSuccessfulAttempts.Set(0)
}

// ErrTimeout resets the consecutive Successful count
func (s *Closer) ErrTimeout(ctx context.Context, now time.Time, duration time.Duration) {
func (s *Closer) ErrTimeout(_ context.Context, _ time.Time, _ time.Duration) {
s.concurrentSuccessfulAttempts.Set(0)
}

// ShouldClose is true if we have enough successful attempts in a row.
func (s *Closer) ShouldClose(ctx context.Context, now time.Time) bool {
func (s *Closer) ShouldClose(_ context.Context, _ time.Time) bool {
return s.concurrentSuccessfulAttempts.Get() >= s.closeOnCurrentCount.Get()
}

Expand Down
5 changes: 5 additions & 0 deletions closers/hystrix/closer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func TestCloser_MarshalJSON(t *testing.T) {
}

func TestCloser_NoPanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Fatal("Expected no panic")
}
}()
ctx := context.Background()
c := Closer{}
wg := sync.WaitGroup{}
Expand Down
22 changes: 11 additions & 11 deletions closers/hystrix/opener.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,54 +98,54 @@ func (e *Opener) MarshalJSON() ([]byte, error) {
var _ json.Marshaler = &Opener{}

// Closed resets the error and attempt count
func (e *Opener) Closed(ctx context.Context, now time.Time) {
func (e *Opener) Closed(_ context.Context, now time.Time) {
e.errorsCount.Reset(now)
e.legitimateAttemptsCount.Reset(now)
}

// Opened resets the error and attempt count
func (e *Opener) Opened(ctx context.Context, now time.Time) {
func (e *Opener) Opened(_ context.Context, now time.Time) {
e.errorsCount.Reset(now)
e.legitimateAttemptsCount.Reset(now)
}

// Success increases the number of correct attempts
func (e *Opener) Success(ctx context.Context, now time.Time, duration time.Duration) {
func (e *Opener) Success(_ context.Context, now time.Time, _ time.Duration) {
e.legitimateAttemptsCount.Inc(now)
}

// Prevent never returns true
func (e *Opener) Prevent(ctx context.Context, now time.Time) (shouldAllow bool) {
func (e *Opener) Prevent(_ context.Context, _ time.Time) (shouldAllow bool) {
return false
}

// ErrBadRequest is ignored
func (e *Opener) ErrBadRequest(ctx context.Context, now time.Time, duration time.Duration) {}
func (e *Opener) ErrBadRequest(_ context.Context, _ time.Time, _ time.Duration) {}

// ErrInterrupt is ignored
func (e *Opener) ErrInterrupt(ctx context.Context, now time.Time, duration time.Duration) {}
func (e *Opener) ErrInterrupt(_ context.Context, _ time.Time, _ time.Duration) {}

// ErrFailure increases error count for the circuit
func (e *Opener) ErrFailure(ctx context.Context, now time.Time, duration time.Duration) {
func (e *Opener) ErrFailure(_ context.Context, now time.Time, _ time.Duration) {
e.legitimateAttemptsCount.Inc(now)
e.errorsCount.Inc(now)
}

// ErrTimeout increases error count for the circuit
func (e *Opener) ErrTimeout(ctx context.Context, now time.Time, duration time.Duration) {
func (e *Opener) ErrTimeout(_ context.Context, now time.Time, _ time.Duration) {
e.legitimateAttemptsCount.Inc(now)
e.errorsCount.Inc(now)
}

// ErrConcurrencyLimitReject is ignored
func (e *Opener) ErrConcurrencyLimitReject(ctx context.Context, now time.Time) {}
func (e *Opener) ErrConcurrencyLimitReject(_ context.Context, _ time.Time) {}

// ErrShortCircuit is ignored
func (e *Opener) ErrShortCircuit(ctx context.Context, now time.Time) {}
func (e *Opener) ErrShortCircuit(_ context.Context, _ time.Time) {}

// ShouldOpen returns true if rolling count >= threshold and
// error % is high enough.
func (e *Opener) ShouldOpen(ctx context.Context, now time.Time) bool {
func (e *Opener) ShouldOpen(_ context.Context, now time.Time) bool {
attemptCount := e.legitimateAttemptsCount.RollingSumAt(now)
if attemptCount == 0 || attemptCount < e.requestVolumeThreshold.Get() {
// not enough requests. Will not open circuit
Expand Down
22 changes: 11 additions & 11 deletions closers/simplelogic/closers.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,51 +41,51 @@ var defaultConfigConsecutiveErrOpener = ConfigConsecutiveErrOpener{
}

// Closed resets the consecutive error count
func (c *ConsecutiveErrOpener) Closed(ctx context.Context, _ time.Time) {
func (c *ConsecutiveErrOpener) Closed(_ context.Context, _ time.Time) {
c.consecutiveCount.Set(0)
}

// Prevent always returns false
func (c *ConsecutiveErrOpener) Prevent(ctx context.Context, now time.Time) bool {
func (c *ConsecutiveErrOpener) Prevent(_ context.Context, _ time.Time) bool {
return false
}

// Success resets the consecutive error count
func (c *ConsecutiveErrOpener) Success(ctx context.Context, now time.Time, duration time.Duration) {
func (c *ConsecutiveErrOpener) Success(_ context.Context, _ time.Time, _ time.Duration) {
c.consecutiveCount.Set(0)
}

// ErrBadRequest is ignored
func (c *ConsecutiveErrOpener) ErrBadRequest(ctx context.Context, now time.Time, duration time.Duration) {
func (c *ConsecutiveErrOpener) ErrBadRequest(_ context.Context, _ time.Time, _ time.Duration) {
}

// ErrInterrupt is ignored
func (c *ConsecutiveErrOpener) ErrInterrupt(ctx context.Context, now time.Time, duration time.Duration) {
func (c *ConsecutiveErrOpener) ErrInterrupt(_ context.Context, _ time.Time, _ time.Duration) {
}

// ErrConcurrencyLimitReject is ignored
func (c *ConsecutiveErrOpener) ErrConcurrencyLimitReject(ctx context.Context, now time.Time) {}
func (c *ConsecutiveErrOpener) ErrConcurrencyLimitReject(_ context.Context, _ time.Time) {}

// ErrShortCircuit is ignored
func (c *ConsecutiveErrOpener) ErrShortCircuit(ctx context.Context, now time.Time) {}
func (c *ConsecutiveErrOpener) ErrShortCircuit(_ context.Context, _ time.Time) {}

// ErrFailure increments the consecutive error counter
func (c *ConsecutiveErrOpener) ErrFailure(ctx context.Context, now time.Time, duration time.Duration) {
func (c *ConsecutiveErrOpener) ErrFailure(_ context.Context, _ time.Time, _ time.Duration) {
c.consecutiveCount.Add(1)
}

// ErrTimeout increments the consecutive error counter
func (c *ConsecutiveErrOpener) ErrTimeout(ctx context.Context, now time.Time, duration time.Duration) {
func (c *ConsecutiveErrOpener) ErrTimeout(_ context.Context, _ time.Time, _ time.Duration) {
c.consecutiveCount.Add(1)
}

// Opened resets the error counter
func (c *ConsecutiveErrOpener) Opened(ctx context.Context, now time.Time) {
func (c *ConsecutiveErrOpener) Opened(_ context.Context, _ time.Time) {
c.consecutiveCount.Set(0)
}

// ShouldOpen returns true if enough consecutive errors have returned
func (c *ConsecutiveErrOpener) ShouldOpen(ctx context.Context, now time.Time) bool {
func (c *ConsecutiveErrOpener) ShouldOpen(_ context.Context, _ time.Time) bool {
return c.consecutiveCount.Get() >= c.closeThreshold.Get()
}

Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,6 @@ func ExampleConfig_custommetrics() {
func ExampleError_checking() {
x := errors.New("an error")
if _, ok := x.(circuit.Error); ok {
// this error is a circuit library error, not the result of runFunc or fallbackFunc
fmt.Println("this error is a circuit library error, not the result of runFunc or fallbackFunc")
}
}
2 changes: 1 addition & 1 deletion faststats/timedcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestTimedCheck(t *testing.T) {
}
}

func TestTimedCheckRaces(t *testing.T) {
func TestTimedCheckRaces(_ *testing.T) {
x := TimedCheck{}
x.SetSleepDuration(time.Nanosecond * 100)
endTime := time.Now().Add(time.Millisecond * 50)
Expand Down
14 changes: 7 additions & 7 deletions metrics/responsetimeslo/responsetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (r *Tracker) Var() expvar.Var {
}

// Success adds a healthy check if duration <= maximum healthy time
func (r *Tracker) Success(ctx context.Context, now time.Time, duration time.Duration) {
func (r *Tracker) Success(_ context.Context, _ time.Time, duration time.Duration) {
if duration.Nanoseconds() <= r.MaximumHealthyTime.Get() {
r.healthy()
return
Expand All @@ -120,33 +120,33 @@ func (r *Tracker) healthy() {
}

// ErrFailure is always a failure
func (r *Tracker) ErrFailure(ctx context.Context, now time.Time, duration time.Duration) {
func (r *Tracker) ErrFailure(_ context.Context, _ time.Time, _ time.Duration) {
r.failure()
}

// ErrTimeout is always a failure
func (r *Tracker) ErrTimeout(ctx context.Context, now time.Time, duration time.Duration) {
func (r *Tracker) ErrTimeout(_ context.Context, _ time.Time, _ time.Duration) {
r.failure()
}

// ErrConcurrencyLimitReject is always a failure
func (r *Tracker) ErrConcurrencyLimitReject(ctx context.Context, now time.Time) {
func (r *Tracker) ErrConcurrencyLimitReject(_ context.Context, _ time.Time) {
// Your endpoint could be healthy, but because we can't process commands fast enough, you're considered unhealthy.
// This one could honestly go either way, but generally if a service cannot process commands fast enough, it's not
// doing what you want.
r.failure()
}

// ErrShortCircuit is always a failure
func (r *Tracker) ErrShortCircuit(ctx context.Context, now time.Time) {
func (r *Tracker) ErrShortCircuit(_ context.Context, _ time.Time) {
// We had to end the request early. It's possible the endpoint we want is healthy, but because we had to trip
// our circuit, due to past misbehavior, it is still end endpoint's fault we cannot satisfy this request, so it
// fails the SLO.
r.failure()
}

// ErrBadRequest is ignored
func (r *Tracker) ErrBadRequest(ctx context.Context, now time.Time, duration time.Duration) {}
func (r *Tracker) ErrBadRequest(_ context.Context, _ time.Time, _ time.Duration) {}

// SetConfigThreadSafe updates the configuration stored in the tracker
func (r *Tracker) SetConfigThreadSafe(config Config) {
Expand All @@ -164,7 +164,7 @@ func (r *Tracker) Config() Config {
}

// ErrInterrupt is only a failure if healthy time has passed
func (r *Tracker) ErrInterrupt(ctx context.Context, now time.Time, duration time.Duration) {
func (r *Tracker) ErrInterrupt(_ context.Context, _ time.Time, duration time.Duration) {
// If it is interrupted, but past the healthy time. Then it is as good as unhealthy
if duration.Nanoseconds() > r.MaximumHealthyTime.Get() {
r.failure()
Expand Down
Loading

0 comments on commit cd576eb

Please sign in to comment.