docker/swarmkit

View on GitHub
manager/scheduler/scheduler.go

Summary

Maintainability
F
4 days
Test Coverage

Method Scheduler.applySchedulingDecisions has a Cognitive Complexity of 95 (exceeds 20 allowed). Consider refactoring.
Open

func (s *Scheduler) applySchedulingDecisions(ctx context.Context, schedulingDecisions map[string]schedulingDecision) (successful, failed []schedulingDecision) {
    // applySchedulingDecisions is the only place where we make store
    // transactions in the scheduler. the scheduler is responsible for freeing
    // volumes that are no longer in use. this means that volumes should be
    // freed in this function. sometimes, there are no scheduling decisions to
Severity: Minor
Found in manager/scheduler/scheduler.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

File scheduler.go has 684 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package scheduler

import (
    "context"
    "sync"
Severity: Minor
Found in manager/scheduler/scheduler.go - About 6 hrs to fix

    Method Scheduler.Run has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring.
    Open

    func (s *Scheduler) Run(pctx context.Context) error {
        ctx := log.WithModule(pctx, "scheduler")
        defer close(s.doneChan)
    
        s.pipeline.AddFilter(&VolumesFilter{vs: s.volumes})
    Severity: Minor
    Found in manager/scheduler/scheduler.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 Scheduler.applySchedulingDecisions has 103 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (s *Scheduler) applySchedulingDecisions(ctx context.Context, schedulingDecisions map[string]schedulingDecision) (successful, failed []schedulingDecision) {
        // applySchedulingDecisions is the only place where we make store
        // transactions in the scheduler. the scheduler is responsible for freeing
        // volumes that are no longer in use. this means that volumes should be
        // freed in this function. sometimes, there are no scheduling decisions to
    Severity: Major
    Found in manager/scheduler/scheduler.go - About 3 hrs to fix

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

      func (s *Scheduler) scheduleNTasksOnSubtree(ctx context.Context, n int, taskGroup map[string]*api.Task, tree *decisionTree, schedulingDecisions map[string]schedulingDecision, nodeLess func(a *NodeInfo, b *NodeInfo) bool) int {
          if tree.next == nil {
              nodes := tree.orderedNodes(s.pipeline.Process, nodeLess)
              if len(nodes) == 0 {
                  return 0
      Severity: Minor
      Found in manager/scheduler/scheduler.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 Scheduler.Run has 84 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (s *Scheduler) Run(pctx context.Context) error {
          ctx := log.WithModule(pctx, "scheduler")
          defer close(s.doneChan)
      
          s.pipeline.AddFilter(&VolumesFilter{vs: s.volumes})
      Severity: Major
      Found in manager/scheduler/scheduler.go - About 2 hrs to fix

        Method Scheduler.scheduleNTasksOnNodes has 53 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (s *Scheduler) scheduleNTasksOnNodes(ctx context.Context, n int, taskGroup map[string]*api.Task, nodes []NodeInfo, schedulingDecisions map[string]schedulingDecision, nodeLess func(a *NodeInfo, b *NodeInfo) bool) int {
            tasksScheduled := 0
            failedConstraints := make(map[int]bool) // key is index in nodes slice
            nodeIter := 0
            nodeCount := len(nodes)
        Severity: Minor
        Found in manager/scheduler/scheduler.go - About 1 hr to fix

          Method Scheduler.scheduleNTasksOnSubtree has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          func (s *Scheduler) scheduleNTasksOnSubtree(ctx context.Context, n int, taskGroup map[string]*api.Task, tree *decisionTree, schedulingDecisions map[string]schedulingDecision, nodeLess func(a *NodeInfo, b *NodeInfo) bool) int {
          Severity: Minor
          Found in manager/scheduler/scheduler.go - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if time.Since(debouncingStarted) > maxLatency {
                                    commitDebounceTimer.Stop()
                                    commitDebounceTimer = nil
                                    commitDebounceTimeout = nil
                                    schedule()
            Severity: Major
            Found in manager/scheduler/scheduler.go - About 45 mins to fix

              Method Scheduler.scheduleNTasksOnNodes has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              func (s *Scheduler) scheduleNTasksOnNodes(ctx context.Context, n int, taskGroup map[string]*api.Task, nodes []NodeInfo, schedulingDecisions map[string]schedulingDecision, nodeLess func(a *NodeInfo, b *NodeInfo) bool) int {
              Severity: Minor
              Found in manager/scheduler/scheduler.go - About 45 mins to fix

                Method Scheduler.updateTask has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                Open

                func (s *Scheduler) updateTask(ctx context.Context, t *api.Task) bool {
                    // Ignore all tasks that have not reached PENDING
                    // state.
                    if t.Status.State < api.TaskStatePending {
                        return false
                Severity: Minor
                Found in manager/scheduler/scheduler.go - About 45 mins 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 Scheduler.updateTask has 6 return statements (exceeds 4 allowed).
                Open

                func (s *Scheduler) updateTask(ctx context.Context, t *api.Task) bool {
                    // Ignore all tasks that have not reached PENDING
                    // state.
                    if t.Status.State < api.TaskStatePending {
                        return false
                Severity: Major
                Found in manager/scheduler/scheduler.go - About 40 mins to fix

                  Method Scheduler.applySchedulingDecisions has 6 return statements (exceeds 4 allowed).
                  Open

                  func (s *Scheduler) applySchedulingDecisions(ctx context.Context, schedulingDecisions map[string]schedulingDecision) (successful, failed []schedulingDecision) {
                      // applySchedulingDecisions is the only place where we make store
                      // transactions in the scheduler. the scheduler is responsible for freeing
                      // volumes that are no longer in use. this means that volumes should be
                      // freed in this function. sometimes, there are no scheduling decisions to
                  Severity: Major
                  Found in manager/scheduler/scheduler.go - About 40 mins to fix

                    Method Scheduler.scheduleNTasksOnNodes has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                    Open

                    func (s *Scheduler) scheduleNTasksOnNodes(ctx context.Context, n int, taskGroup map[string]*api.Task, nodes []NodeInfo, schedulingDecisions map[string]schedulingDecision, nodeLess func(a *NodeInfo, b *NodeInfo) bool) int {
                        tasksScheduled := 0
                        failedConstraints := make(map[int]bool) // key is index in nodes slice
                        nodeIter := 0
                        nodeCount := len(nodes)
                    Severity: Minor
                    Found in manager/scheduler/scheduler.go - About 35 mins 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 Scheduler.scheduleTaskGroup has 5 return statements (exceeds 4 allowed).
                    Open

                    func (s *Scheduler) scheduleTaskGroup(ctx context.Context, taskGroup map[string]*api.Task, schedulingDecisions map[string]schedulingDecision) {
                        // Pick at task at random from taskGroup to use for constraint
                        // evaluation. It doesn't matter which one we pick because all the
                        // tasks in the group are equal in terms of the fields the constraint
                        // filters consider.
                    Severity: Major
                    Found in manager/scheduler/scheduler.go - About 35 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status