docker/swarmkit

View on GitHub
agent/agent.go

Summary

Maintainability
D
2 days
Test Coverage

Method Agent.run has a Cognitive Complexity of 85 (exceeds 20 allowed). Consider refactoring.
Open

func (a *Agent) run(ctx context.Context) {
    ctx, cancel := context.WithCancel(ctx)
    defer cancel()
    defer close(a.closed) // full shutdown.

Severity: Minor
Found in agent/agent.go - About 1 day to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method Agent.run has 168 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (a *Agent) run(ctx context.Context) {
    ctx, cancel := context.WithCancel(ctx)
    defer cancel()
    defer close(a.closed) // full shutdown.

Severity: Major
Found in agent/agent.go - About 5 hrs to fix

    Method Agent.handleSessionMessage has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
    Open

    func (a *Agent) handleSessionMessage(ctx context.Context, message *api.SessionMessage, nti *api.NodeTLSInfo) error {
        seen := map[api.Peer]struct{}{}
        for _, manager := range message.Managers {
            if manager.Peer.Addr == "" {
                continue
    Severity: Minor
    Found in agent/agent.go - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method Agent.handleSessionMessage has 51 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (a *Agent) handleSessionMessage(ctx context.Context, message *api.SessionMessage, nti *api.NodeTLSInfo) error {
        seen := map[api.Peer]struct{}{}
        for _, manager := range message.Managers {
            if manager.Peer.Addr == "" {
                continue
    Severity: Minor
    Found in agent/agent.go - About 1 hr to fix

      Method Agent.run has 6 return statements (exceeds 4 allowed).
      Open

      func (a *Agent) run(ctx context.Context) {
          ctx, cancel := context.WithCancel(ctx)
          defer cancel()
          defer close(a.closed) // full shutdown.
      
      
      Severity: Major
      Found in agent/agent.go - About 40 mins to fix

        Method Agent.withSession has 5 return statements (exceeds 4 allowed).
        Open

        func (a *Agent) withSession(ctx context.Context, fn func(session *session) error) error {
            response := make(chan error, 1)
            select {
            case a.sessionq <- sessionOperation{
                fn:       fn,
        Severity: Major
        Found in agent/agent.go - About 35 mins to fix

          Method Agent.Leave has 5 return statements (exceeds 4 allowed).
          Open

          func (a *Agent) Leave(ctx context.Context) error {
              select {
              case <-a.started:
              default:
                  return errAgentNotStarted
          Severity: Major
          Found in agent/agent.go - About 35 mins to fix

            There are no issues that match your filters.

            Category
            Status