Showing 1,008 of 1,820 total issues
Method Scheduler.scheduleNTasksOnNodes
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
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)
- Read upRead up
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 Updater.rollbackUpdate
has 5 return statements (exceeds 4 allowed). Open
Open
func (u *Updater) rollbackUpdate(ctx context.Context, serviceID, message string) {
log.G(ctx).Debugf("starting rollback of service %s", serviceID)
err := u.store.Update(func(tx store.Tx) error {
service := store.GetService(tx, serviceID)
Method Dispatcher.register
has 5 return statements (exceeds 4 allowed). Open
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 {
Method RaftDEKManager.GetKeys
has 5 return statements (exceeds 4 allowed). Open
Open
func (r *RaftDEKManager) GetKeys() raft.EncryptionKeys {
var newKeys, originalKeys raft.EncryptionKeys
err := r.kw.ViewAndUpdateHeaders(func(h ca.PEMKeyHeaders) (ca.PEMKeyHeaders, error) {
data, ok := h.(RaftDEKData)
if !ok {
Method Allocator.reallocateNode
has 5 return statements (exceeds 4 allowed). Open
Open
func (a *Allocator) reallocateNode(ctx context.Context, nodeID string) error {
var (
node *api.Node
)
a.store.View(func(tx store.ReadTx) {
Method Cluster.UpdateMember
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *Cluster) UpdateMember(id uint64, m *api.RaftMember) error {
c.mu.Lock()
defer c.mu.Unlock()
if c.removed[id] {
Method testSuite.TestServiceUpdatePort
has 5 return statements (exceeds 4 allowed). Open
Open
func (suite *testSuite) TestServiceUpdatePort() {
s := store.NewMemoryStore(nil)
suite.NotNil(s)
defer s.Close()
Method Transport.AddPeer
has 5 return statements (exceeds 4 allowed). Open
Open
func (t *Transport) AddPeer(id uint64, addr string) error {
t.mu.Lock()
defer t.mu.Unlock()
if t.stopped {
return errors.New("transport stopped")
Method testSuite.TestAllocateServiceConflictingUserDefinedPorts
has 5 return statements (exceeds 4 allowed). Open
Open
func (suite *testSuite) TestAllocateServiceConflictingUserDefinedPorts() {
s := store.NewMemoryStore(nil)
suite.NotNil(s)
defer s.Close()
Function Parse
has 5 return statements (exceeds 4 allowed). Open
Open
func Parse(env []string) ([]Constraint, error) {
exprs := []Constraint{}
for _, e := range env {
found := false
// each expr is in the form of "key op value"
Method Node.TransferLeadership
has 5 return statements (exceeds 4 allowed). Open
Open
func (n *Node) TransferLeadership(ctx context.Context) error {
ctx, cancelTransfer := context.WithTimeout(ctx, n.reqTimeout())
defer cancelTransfer()
n.stopMu.RLock()
Function CheckValuesOnNodes
has 5 return statements (exceeds 4 allowed). Open
Open
func CheckValuesOnNodes(t *testing.T, clockSource *fakeclock.FakeClock, checkNodes map[uint64]*TestNode, ids []string, values []*api.Node) {
iteration := 0
for checkNodeID, node := range checkNodes {
assert.NoError(t, testutils.PollFunc(clockSource, func() error {
var err error
Method Batch.Update
has 5 return statements (exceeds 4 allowed). Open
Open
func (batch *Batch) Update(cb func(Tx) error) error {
if batch.err != nil {
return batch.err
}
Function WaitForCluster
has 5 return statements (exceeds 4 allowed). Open
Open
func WaitForCluster(t *testing.T, clockSource *fakeclock.FakeClock, nodes map[uint64]*TestNode) {
err := testutils.PollFunc(clockSource, func() error {
var prev *etcdraft.Status
var leadNode *TestNode
nodeLoop:
Method portSpace.allocate
has 5 return statements (exceeds 4 allowed). Open
Open
func (ps *portSpace) allocate(p *api.PortConfig) (err error) {
if p.PublishedPort != 0 {
// If it falls in the dynamic port range check out
// from dynamic port space first.
if p.PublishedPort >= dynamicPortStart && p.PublishedPort <= dynamicPortEnd {
Method Node.saveToStorage
has 5 return statements (exceeds 4 allowed). Open
Open
func (n *Node) saveToStorage(
ctx context.Context,
raftConfig *api.RaftConfig,
hardState raftpb.HardState,
entries []raftpb.Entry,
Method SecretDriver.Get
has 5 return statements (exceeds 4 allowed). Open
Open
func (d *SecretDriver) Get(spec *api.SecretSpec, task *api.Task) ([]byte, bool, error) {
if spec == nil {
return nil, false, fmt.Errorf("secret spec is nil")
}
if task == nil {
Method Manager.IsStateDirty
has 5 return statements (exceeds 4 allowed). Open
Open
func (m *Manager) IsStateDirty() (bool, error) {
var (
storeSnapshot *api.StoreSnapshot
err error
)
Method Node.StreamRaftMessage
has 5 return statements (exceeds 4 allowed). Open
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
Method controller.Logs
has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring. Open
Open
func (r *controller) Logs(ctx context.Context, publisher exec.LogPublisher, options api.LogSubscriptionOptions) error {
if err := r.checkClosed(); err != nil {
return err
}
- Read upRead up
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"