docker/swarmkit

View on GitHub
manager/state/raft/raft.go

Summary

Maintainability
F
1 wk
Test Coverage

File raft.go has 1512 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package raft

import (
    "context"
    "fmt"
Severity: Major
Found in manager/state/raft/raft.go - About 3 days to fix

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

    func (n *Node) Run(ctx context.Context) error {
        ctx = log.WithLogger(ctx, logrus.WithField("raft_id", fmt.Sprintf("%x", n.Config.ID)))
        ctx, cancel := context.WithCancel(ctx)
    
        for _, node := range n.bootstrapMembers {
    Severity: Minor
    Found in manager/state/raft/raft.go - About 2 days 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

    Node has 65 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type Node struct {
        raftNode  raft.Node
        cluster   *membership.Cluster
        transport *transport.Transport
    
    
    Severity: Major
    Found in manager/state/raft/raft.go - About 1 day to fix

      Method Node.Run has 133 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (n *Node) Run(ctx context.Context) error {
          ctx = log.WithLogger(ctx, logrus.WithField("raft_id", fmt.Sprintf("%x", n.Config.ID)))
          ctx, cancel := context.WithCancel(ctx)
      
          for _, node := range n.bootstrapMembers {
      Severity: Major
      Found in manager/state/raft/raft.go - About 4 hrs to fix

        Method Node.Join has 75 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (n *Node) Join(ctx context.Context, req *api.JoinRequest) (*api.JoinResponse, error) {
            nodeInfo, err := ca.RemoteNode(ctx)
            if err != nil {
                return nil, err
            }
        Severity: Minor
        Found in manager/state/raft/raft.go - About 2 hrs to fix

          Method Node.Join has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
          Open

          func (n *Node) Join(ctx context.Context, req *api.JoinRequest) (*api.JoinResponse, error) {
              nodeInfo, err := ca.RemoteNode(ctx)
              if err != nil {
                  return nil, err
              }
          Severity: Minor
          Found in manager/state/raft/raft.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 Node.processInternalRaftRequest has 59 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (n *Node) processInternalRaftRequest(ctx context.Context, r *api.InternalRaftRequest, cb func()) (proto.Message, error) {
              n.stopMu.RLock()
              if !n.IsMember() {
                  n.stopMu.RUnlock()
                  return nil, ErrStopped
          Severity: Minor
          Found in manager/state/raft/raft.go - About 1 hr to fix

            Method Node.JoinAndStart has 58 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (n *Node) JoinAndStart(ctx context.Context) (err error) {
                ctx, cancel := n.WithContext(ctx)
                defer func() {
                    cancel()
                    if err != nil {
            Severity: Minor
            Found in manager/state/raft/raft.go - About 1 hr to fix

              Method Node.Join has 12 return statements (exceeds 4 allowed).
              Open

              func (n *Node) Join(ctx context.Context, req *api.JoinRequest) (*api.JoinResponse, error) {
                  nodeInfo, err := ca.RemoteNode(ctx)
                  if err != nil {
                      return nil, err
                  }
              Severity: Major
              Found in manager/state/raft/raft.go - About 1 hr to fix

                Method Node.processInternalRaftRequest has 11 return statements (exceeds 4 allowed).
                Open

                func (n *Node) processInternalRaftRequest(ctx context.Context, r *api.InternalRaftRequest, cb func()) (proto.Message, error) {
                    n.stopMu.RLock()
                    if !n.IsMember() {
                        n.stopMu.RUnlock()
                        return nil, ErrStopped
                Severity: Major
                Found in manager/state/raft/raft.go - About 1 hr to fix

                  Method Node.JoinAndStart has 8 return statements (exceeds 4 allowed).
                  Open

                  func (n *Node) JoinAndStart(ctx context.Context) (err error) {
                      ctx, cancel := n.WithContext(ctx)
                      defer func() {
                          cancel()
                          if err != nil {
                  Severity: Major
                  Found in manager/state/raft/raft.go - About 50 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                        if atomic.LoadUint32(&n.signalledLeadership) == 1 {
                                            atomic.StoreUint32(&n.signalledLeadership, 0)
                                            n.leadershipBroadcast.Publish(IsFollower)
                                        }
                    Severity: Major
                    Found in manager/state/raft/raft.go - About 45 mins to fix

                      Method Node.reportNewAddress has 7 return statements (exceeds 4 allowed).
                      Open

                      func (n *Node) reportNewAddress(ctx context.Context, id uint64) error {
                          // too early
                          if !n.IsMember() {
                              return nil
                          }
                      Severity: Major
                      Found in manager/state/raft/raft.go - About 45 mins to fix

                        Method Node.registerNode has 7 return statements (exceeds 4 allowed).
                        Open

                        func (n *Node) registerNode(node *api.RaftMember) error {
                            if n.cluster.IsIDRemoved(node.RaftID) {
                                return nil
                            }
                        
                        
                        Severity: Major
                        Found in manager/state/raft/raft.go - About 45 mins to fix

                          Method Node.ProcessRaftMessage has 7 return statements (exceeds 4 allowed).
                          Open

                          func (n *Node) ProcessRaftMessage(ctx context.Context, msg *api.ProcessRaftMessageRequest) (*api.ProcessRaftMessageResponse, error) {
                              if msg == nil || msg.Message == nil {
                                  n.processRaftMessageLogger(ctx, msg).Debug("received empty message")
                                  return &api.ProcessRaftMessageResponse{}, nil
                              }
                          Severity: Major
                          Found in manager/state/raft/raft.go - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                            } else if !wasLeader && rd.SoftState.RaftState == raft.StateLeader {
                                                // Node just became a leader.
                                                wasLeader = true
                                            }
                            Severity: Major
                            Found in manager/state/raft/raft.go - About 45 mins to fix

                              Method Node.LeaderConn has 6 return statements (exceeds 4 allowed).
                              Open

                              func (n *Node) LeaderConn(ctx context.Context) (*grpc.ClientConn, error) {
                                  cc, err := n.getLeaderConn()
                                  if err == nil {
                                      return cc, nil
                                  }
                              Severity: Major
                              Found in manager/state/raft/raft.go - About 40 mins to fix

                                Method Node.ChangesBetween has 6 return statements (exceeds 4 allowed).
                                Open

                                func (n *Node) ChangesBetween(from, to api.Version) ([]state.Change, error) {
                                    n.stopMu.RLock()
                                    defer n.stopMu.RUnlock()
                                
                                    if from.Index > to.Index {
                                Severity: Major
                                Found in manager/state/raft/raft.go - About 40 mins to fix

                                  Method Node.saveToStorage has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                      ctx context.Context,
                                      raftConfig *api.RaftConfig,
                                      hardState raftpb.HardState,
                                      entries []raftpb.Entry,
                                      snapshot raftpb.Snapshot,
                                  Severity: Minor
                                  Found in manager/state/raft/raft.go - About 35 mins to fix

                                    Method Node.StreamRaftMessage has 5 return statements (exceeds 4 allowed).
                                    Open

                                    func (n *Node) StreamRaftMessage(stream api.Raft_StreamRaftMessageServer) error {
                                        // recvdMsg is the current messasge received from the stream.
                                        // assembledMessage is where the data from recvdMsg is appended to.
                                        var recvdMsg, assembledMessage *api.StreamRaftMessageRequest
                                        var err error
                                    Severity: Major
                                    Found in manager/state/raft/raft.go - About 35 mins to fix

                                      Method Node.saveToStorage has 5 return statements (exceeds 4 allowed).
                                      Open

                                      func (n *Node) saveToStorage(
                                          ctx context.Context,
                                          raftConfig *api.RaftConfig,
                                          hardState raftpb.HardState,
                                          entries []raftpb.Entry,
                                      Severity: Major
                                      Found in manager/state/raft/raft.go - About 35 mins to fix

                                        Method Node.TransferLeadership has 5 return statements (exceeds 4 allowed).
                                        Open

                                        func (n *Node) TransferLeadership(ctx context.Context) error {
                                            ctx, cancelTransfer := context.WithTimeout(ctx, n.reqTimeout())
                                            defer cancelTransfer()
                                        
                                            n.stopMu.RLock()
                                        Severity: Major
                                        Found in manager/state/raft/raft.go - About 35 mins to fix

                                          There are no issues that match your filters.

                                          Category
                                          Status