docker/swarmkit

View on GitHub
manager/dispatcher/dispatcher.go

Summary

Maintainability
F
1 wk
Test Coverage

File dispatcher.go has 1119 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package dispatcher

import (
    "context"
    "fmt"
Severity: Major
Found in manager/dispatcher/dispatcher.go - About 2 days to fix

    Method Dispatcher.processUpdates has a Cognitive Complexity of 86 (exceeds 20 allowed). Consider refactoring.
    Open

    func (d *Dispatcher) processUpdates(ctx context.Context) {
        var (
            taskUpdates        map[string]*api.TaskStatus
            nodeUpdates        map[string]nodeUpdate
            unpublishedVolumes map[string][]string
    Severity: Minor
    Found in manager/dispatcher/dispatcher.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 Dispatcher.Assignments has a Cognitive Complexity of 83 (exceeds 20 allowed). Consider refactoring.
    Open

    func (d *Dispatcher) Assignments(r *api.AssignmentsRequest, stream api.Dispatcher_AssignmentsServer) error {
        d.rpcRW.RLock()
        defer d.rpcRW.RUnlock()
    
        dctx, err := d.isRunningLocked()
    Severity: Minor
    Found in manager/dispatcher/dispatcher.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 Dispatcher.Tasks has a Cognitive Complexity of 49 (exceeds 20 allowed). Consider refactoring.
    Open

    func (d *Dispatcher) Tasks(r *api.TasksRequest, stream api.Dispatcher_TasksServer) error {
        d.rpcRW.RLock()
        defer d.rpcRW.RUnlock()
    
        dctx, err := d.isRunningLocked()
    Severity: Minor
    Found in manager/dispatcher/dispatcher.go - About 5 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 Dispatcher.Assignments has 148 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (d *Dispatcher) Assignments(r *api.AssignmentsRequest, stream api.Dispatcher_AssignmentsServer) error {
        d.rpcRW.RLock()
        defer d.rpcRW.RUnlock()
    
        dctx, err := d.isRunningLocked()
    Severity: Major
    Found in manager/dispatcher/dispatcher.go - About 4 hrs to fix

      Method Dispatcher.processUpdates has 127 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (d *Dispatcher) processUpdates(ctx context.Context) {
          var (
              taskUpdates        map[string]*api.TaskStatus
              nodeUpdates        map[string]nodeUpdate
              unpublishedVolumes map[string][]string
      Severity: Major
      Found in manager/dispatcher/dispatcher.go - About 4 hrs to fix

        Method Dispatcher.Session has 125 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (d *Dispatcher) Session(r *api.SessionRequest, stream api.Dispatcher_SessionServer) error {
            d.rpcRW.RLock()
            defer d.rpcRW.RUnlock()
        
            dctx, err := d.isRunningLocked()
        Severity: Major
        Found in manager/dispatcher/dispatcher.go - About 4 hrs to fix

          Method Dispatcher.Session has a Cognitive Complexity of 41 (exceeds 20 allowed). Consider refactoring.
          Open

          func (d *Dispatcher) Session(r *api.SessionRequest, stream api.Dispatcher_SessionServer) error {
              d.rpcRW.RLock()
              defer d.rpcRW.RUnlock()
          
              dctx, err := d.isRunningLocked()
          Severity: Minor
          Found in manager/dispatcher/dispatcher.go - About 3 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 Dispatcher.Run has 106 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (d *Dispatcher) Run(ctx context.Context) error {
              ctx = log.WithModule(ctx, "dispatcher")
              log.G(ctx).Info("dispatcher starting")
          
              d.taskUpdatesLock.Lock()
          Severity: Major
          Found in manager/dispatcher/dispatcher.go - About 3 hrs to fix

            Method Dispatcher.Tasks has 104 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (d *Dispatcher) Tasks(r *api.TasksRequest, stream api.Dispatcher_TasksServer) error {
                d.rpcRW.RLock()
                defer d.rpcRW.RUnlock()
            
                dctx, err := d.isRunningLocked()
            Severity: Major
            Found in manager/dispatcher/dispatcher.go - About 3 hrs to fix

              Method Dispatcher.markNodesUnknown has a Cognitive Complexity of 33 (exceeds 20 allowed). Consider refactoring.
              Open

              func (d *Dispatcher) markNodesUnknown(ctx context.Context) error {
                  log := log.G(ctx).WithField("method", "(*Dispatcher).markNodesUnknown")
                  var nodes []*api.Node
                  var err error
                  d.store.View(func(tx store.ReadTx) {
              Severity: Minor
              Found in manager/dispatcher/dispatcher.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 Dispatcher.Run has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring.
              Open

              func (d *Dispatcher) Run(ctx context.Context) error {
                  ctx = log.WithModule(ctx, "dispatcher")
                  log.G(ctx).Info("dispatcher starting")
              
                  d.taskUpdatesLock.Lock()
              Severity: Minor
              Found in manager/dispatcher/dispatcher.go - About 1 hr 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 Dispatcher.Assignments has 15 return statements (exceeds 4 allowed).
              Open

              func (d *Dispatcher) Assignments(r *api.AssignmentsRequest, stream api.Dispatcher_AssignmentsServer) error {
                  d.rpcRW.RLock()
                  defer d.rpcRW.RUnlock()
              
                  dctx, err := d.isRunningLocked()
              Severity: Major
              Found in manager/dispatcher/dispatcher.go - About 1 hr to fix

                Method Dispatcher.UpdateTaskStatus has 57 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (d *Dispatcher) UpdateTaskStatus(ctx context.Context, r *api.UpdateTaskStatusRequest) (*api.UpdateTaskStatusResponse, error) {
                    d.rpcRW.RLock()
                    defer d.rpcRW.RUnlock()
                
                    dctx, err := d.isRunningLocked()
                Severity: Minor
                Found in manager/dispatcher/dispatcher.go - About 1 hr to fix

                  Method Dispatcher.processUpdates has 12 return statements (exceeds 4 allowed).
                  Open

                  func (d *Dispatcher) processUpdates(ctx context.Context) {
                      var (
                          taskUpdates        map[string]*api.TaskStatus
                          nodeUpdates        map[string]nodeUpdate
                          unpublishedVolumes map[string][]string
                  Severity: Major
                  Found in manager/dispatcher/dispatcher.go - About 1 hr to fix

                    Method Dispatcher.Session has 12 return statements (exceeds 4 allowed).
                    Open

                    func (d *Dispatcher) Session(r *api.SessionRequest, stream api.Dispatcher_SessionServer) error {
                        d.rpcRW.RLock()
                        defer d.rpcRW.RUnlock()
                    
                        dctx, err := d.isRunningLocked()
                    Severity: Major
                    Found in manager/dispatcher/dispatcher.go - About 1 hr to fix

                      Method Dispatcher.markNodesUnknown has 54 lines of code (exceeds 50 allowed). Consider refactoring.
                      Open

                      func (d *Dispatcher) markNodesUnknown(ctx context.Context) error {
                          log := log.G(ctx).WithField("method", "(*Dispatcher).markNodesUnknown")
                          var nodes []*api.Node
                          var err error
                          d.store.View(func(tx store.ReadTx) {
                      Severity: Minor
                      Found in manager/dispatcher/dispatcher.go - About 1 hr to fix

                        Method Dispatcher.Tasks has 10 return statements (exceeds 4 allowed).
                        Open

                        func (d *Dispatcher) Tasks(r *api.TasksRequest, stream api.Dispatcher_TasksServer) error {
                            d.rpcRW.RLock()
                            defer d.rpcRW.RUnlock()
                        
                            dctx, err := d.isRunningLocked()
                        Severity: Major
                        Found in manager/dispatcher/dispatcher.go - About 1 hr to fix

                          Method Dispatcher.markNodesUnknown has 8 return statements (exceeds 4 allowed).
                          Open

                          func (d *Dispatcher) markNodesUnknown(ctx context.Context) error {
                              log := log.G(ctx).WithField("method", "(*Dispatcher).markNodesUnknown")
                              var nodes []*api.Node
                              var err error
                              d.store.View(func(tx store.ReadTx) {
                          Severity: Major
                          Found in manager/dispatcher/dispatcher.go - About 50 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                                    if assignments.addOrUpdateTask(readTx, v.Task) {
                                                        oneModification()
                                                    }
                            Severity: Major
                            Found in manager/dispatcher/dispatcher.go - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                                      if assignments.removeTask(readTx, v.Task) {
                                                          oneModification()
                                                      }
                              Severity: Major
                              Found in manager/dispatcher/dispatcher.go - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                                    if oldTask, exists := tasksMap[v.Task.ID]; exists {
                                                        // States ASSIGNED and below are set by the orchestrator/scheduler,
                                                        // not the agent, so tasks in these states need to be sent to the
                                                        // agent even if nothing else has changed.
                                                        if equality.TasksEqualStable(oldTask, v.Task) && v.Task.Status.State > api.TaskStateAssigned {
                                Severity: Major
                                Found in manager/dispatcher/dispatcher.go - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                                              if status.NodeID == nodeID {
                                                                  if assignments.addOrUpdateVolume(readTx, vol) {
                                                                      oneModification()
                                                                  }
                                                              }
                                  Severity: Major
                                  Found in manager/dispatcher/dispatcher.go - About 45 mins to fix

                                    Method Dispatcher.register has 5 return statements (exceeds 4 allowed).
                                    Open

                                    func (d *Dispatcher) register(ctx context.Context, nodeID string, description *api.NodeDescription) (string, error) {
                                        logLocal := log.G(ctx).WithField("method", "(*Dispatcher).register")
                                        // prevent register until we're ready to accept it
                                        dctx, err := d.isRunningLocked()
                                        if err != nil {
                                    Severity: Major
                                    Found in manager/dispatcher/dispatcher.go - About 35 mins to fix

                                      Method Dispatcher.UpdateTaskStatus has 5 return statements (exceeds 4 allowed).
                                      Open

                                      func (d *Dispatcher) UpdateTaskStatus(ctx context.Context, r *api.UpdateTaskStatusRequest) (*api.UpdateTaskStatusResponse, error) {
                                          d.rpcRW.RLock()
                                          defer d.rpcRW.RUnlock()
                                      
                                          dctx, err := d.isRunningLocked()
                                      Severity: Major
                                      Found in manager/dispatcher/dispatcher.go - About 35 mins to fix

                                        Method Dispatcher.Run has 5 return statements (exceeds 4 allowed).
                                        Open

                                        func (d *Dispatcher) Run(ctx context.Context) error {
                                            ctx = log.WithModule(ctx, "dispatcher")
                                            log.G(ctx).Info("dispatcher starting")
                                        
                                            d.taskUpdatesLock.Lock()
                                        Severity: Major
                                        Found in manager/dispatcher/dispatcher.go - About 35 mins to fix

                                          Method Dispatcher.moveTasksToOrphaned has 5 return statements (exceeds 4 allowed).
                                          Open

                                          func (d *Dispatcher) moveTasksToOrphaned(nodeID string) error {
                                              err := d.store.Batch(func(batch *store.Batch) error {
                                                  var (
                                                      tasks []*api.Task
                                                      err   error
                                          Severity: Major
                                          Found in manager/dispatcher/dispatcher.go - About 35 mins to fix

                                            Similar blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                            func (d *Dispatcher) isRunningLocked() (context.Context, error) {
                                                d.mu.Lock()
                                                if !d.isRunning() {
                                                    d.mu.Unlock()
                                                    return nil, status.Errorf(codes.Aborted, "dispatcher is stopped")
                                            Severity: Minor
                                            Found in manager/dispatcher/dispatcher.go and 1 other location - About 45 mins to fix
                                            ca/server.go on lines 591..600

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 116.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            There are no issues that match your filters.

                                            Category
                                            Status