xmidt-org/caduceus

View on GitHub

Showing 44 of 44 total issues

Function caduceus has 150 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func caduceus(arguments []string) int {
    beginCaduceus := time.Now()

    var (
        f = pflag.NewFlagSet(applicationName, pflag.ContinueOnError)
Severity: Major
Found in main.go - About 5 hrs to fix

    Function authenticationMiddleware has 148 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func authenticationMiddleware(v *viper.Viper, logger *zap.Logger, registry xmetrics.Registry) (*alice.Chain, error) {
        if registry == nil {
            return nil, errors.New("nil registry")
        }
    
    
    Severity: Major
    Found in primaryHandler.go - About 4 hrs to fix

      Function Metrics has 120 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func Metrics() []xmetrics.Metric {
          return []xmetrics.Metric{
              {
                  Name: IncomingQueueDepth,
                  Help: "The depth of the queue behind the incoming handlers.",
      Severity: Major
      Found in metrics.go - About 3 hrs to fix

        Method CaduceusOutboundSender.send has 87 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (obs *CaduceusOutboundSender) send(urls *ring.Ring, secret, acceptType string, msg *wrp.Message) {
            defer func() {
                if r := recover(); nil != r {
                    obs.droppedPanic.Add(1.0)
                    obs.logger.Error("goroutine send() panicked", zap.String("id", obs.id), zap.Any("panic", r))
        Severity: Major
        Found in outboundSender.go - About 2 hrs to fix

          File outboundSender.go has 519 lines of code (exceeds 500 allowed). Consider refactoring.
          Open

          // SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
          // SPDX-License-Identifier: Apache-2.0
          package main
          
          import (
          Severity: Minor
          Found in outboundSender.go - About 2 hrs to fix

            Method CaduceusOutboundSender.Update has 72 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (obs *CaduceusOutboundSender) Update(wh ancla.InternalWebhook) (err error) {
            
                // Validate the failure URL, if present
                if "" != wh.Webhook.FailureURL {
                    if _, err = url.ParseRequestURI(wh.Webhook.FailureURL); nil != err {
            Severity: Minor
            Found in outboundSender.go - About 1 hr to fix

              Function authenticationMiddleware has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring.
              Open

              func authenticationMiddleware(v *viper.Viper, logger *zap.Logger, registry xmetrics.Registry) (*alice.Chain, error) {
                  if registry == nil {
                      return nil, errors.New("nil registry")
                  }
              
              
              Severity: Minor
              Found in primaryHandler.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 ServerHandler.ServeHTTP has 67 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (sh *ServerHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {
                  eventType := unknownEventType
                  // find time difference, add to metric after function finishes
                  defer func(s time.Time) {
                      sh.recordQueueLatencyToHistogram(s, eventType)
              Severity: Minor
              Found in http.go - About 1 hr to fix

                Function getDoErrReason has 13 return statements (exceeds 4 allowed).
                Open

                func getDoErrReason(err error) string {
                    var d *net.DNSError
                    if err == nil {
                        return noErrReason
                    } else if errors.Is(err, context.DeadlineExceeded) {
                Severity: Major
                Found in httpClient.go - About 1 hr to fix

                  Method CaduceusOutboundSender.Queue has 56 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func (obs *CaduceusOutboundSender) Queue(msg *wrp.Message) {
                      obs.mutex.RLock()
                      deliverUntil := obs.deliverUntil
                      dropUntil := obs.dropUntil
                      events := obs.events
                  Severity: Minor
                  Found in outboundSender.go - About 1 hr to fix

                    Method OutboundSenderFactory.New has 54 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func (osf OutboundSenderFactory) New() (obs OutboundSender, err error) {
                        if _, err = url.ParseRequestURI(osf.Listener.Webhook.Config.URL); nil != err {
                            return
                        }
                    
                    
                    Severity: Minor
                    Found in outboundSender.go - About 1 hr to fix

                      Function caduceus has 11 return statements (exceeds 4 allowed).
                      Open

                      func caduceus(arguments []string) int {
                          beginCaduceus := time.Now()
                      
                          var (
                              f = pflag.NewFlagSet(applicationName, pflag.ContinueOnError)
                      Severity: Major
                      Found in main.go - About 1 hr to fix

                        Function authenticationMiddleware has 10 return statements (exceeds 4 allowed).
                        Open

                        func authenticationMiddleware(v *viper.Viper, logger *zap.Logger, registry xmetrics.Registry) (*alice.Chain, error) {
                            if registry == nil {
                                return nil, errors.New("nil registry")
                            }
                        
                        
                        Severity: Major
                        Found in primaryHandler.go - About 1 hr to fix

                          Function NewPrimaryHandler has 7 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          func NewPrimaryHandler(l *zap.Logger, v *viper.Viper, registry xmetrics.Registry, sw *ServerHandler, webhookSvc ancla.Service, router *mux.Router, prevVersionSupport bool) (*mux.Router, error) {
                          Severity: Major
                          Found in primaryHandler.go - About 50 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                } else if errors.Is(err, &net.ParseError{}) {
                                    return parseAddrErrReason
                                } else if errors.Is(err, net.InvalidAddrError("")) {
                                    return invalidAddrReason
                                } else if errors.As(err, &d) {
                            Severity: Major
                            Found in httpClient.go - About 45 mins to fix

                              Method OutboundSenderFactory.New has 6 return statements (exceeds 4 allowed).
                              Open

                              func (osf OutboundSenderFactory) New() (obs OutboundSender, err error) {
                                  if _, err = url.ParseRequestURI(osf.Listener.Webhook.Config.URL); nil != err {
                                      return
                                  }
                              
                              
                              Severity: Major
                              Found in outboundSender.go - About 40 mins to fix

                                Method CaduceusOutboundSender.queueOverflow has 6 return statements (exceeds 4 allowed).
                                Open

                                func (obs *CaduceusOutboundSender) queueOverflow() {
                                    obs.mutex.Lock()
                                    if time.Now().Before(obs.dropUntil) {
                                        obs.mutex.Unlock()
                                        return
                                Severity: Major
                                Found in outboundSender.go - About 40 mins to fix

                                  Method ServerHandler.ServeHTTP has 6 return statements (exceeds 4 allowed).
                                  Open

                                  func (sh *ServerHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {
                                      eventType := unknownEventType
                                      // find time difference, add to metric after function finishes
                                      defer func(s time.Time) {
                                          sh.recordQueueLatencyToHistogram(s, eventType)
                                  Severity: Major
                                  Found in http.go - About 40 mins to fix

                                    Method CaduceusOutboundSender.Update has 6 return statements (exceeds 4 allowed).
                                    Open

                                    func (obs *CaduceusOutboundSender) Update(wh ancla.InternalWebhook) (err error) {
                                    
                                        // Validate the failure URL, if present
                                        if "" != wh.Webhook.FailureURL {
                                            if _, err = url.ParseRequestURI(wh.Webhook.FailureURL); nil != err {
                                    Severity: Major
                                    Found in outboundSender.go - About 40 mins to fix

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

                                          caduceusSenderWrapper := &CaduceusSenderWrapper{
                                              sender:              swf.Sender,
                                              numWorkersPerSender: swf.NumWorkersPerSender,
                                              queueSizePerSender:  swf.QueueSizePerSender,
                                              deliveryRetries:     swf.DeliveryRetries,
                                      Severity: Minor
                                      Found in senderWrapper.go and 1 other location - About 35 mins to fix
                                      senderWrapper.go on lines 127..139

                                      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 103.

                                      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

                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language