dotcloud/docker

View on GitHub
daemon/logger/splunk/splunk.go

Summary

Maintainability
D
2 days
Test Coverage

Function New has 166 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func New(info logger.Info) (logger.Logger, error) {
    hostname, err := info.Hostname()
    if err != nil {
        return nil, fmt.Errorf("%s: cannot access hostname to set source field", driverName)
    }
Severity: Major
Found in daemon/logger/splunk/splunk.go - About 5 hrs to fix

    Function New has a Cognitive Complexity of 42 (exceeds 20 allowed). Consider refactoring.
    Open

    func New(info logger.Info) (logger.Logger, error) {
        hostname, err := info.Hostname()
        if err != nil {
            return nil, fmt.Errorf("%s: cannot access hostname to set source field", driverName)
        }
    Severity: Minor
    Found in daemon/logger/splunk/splunk.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

    File splunk.go has 558 lines of code (exceeds 500 allowed). Consider refactoring.
    Open

    // Package splunk provides the log driver for forwarding server logs to
    // Splunk HTTP Event Collector endpoint.
    package splunk // import "github.com/docker/docker/daemon/logger/splunk"
    
    import (
    Severity: Minor
    Found in daemon/logger/splunk/splunk.go - About 3 hrs to fix

      Method splunkLogger.tryPostMessages has 64 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (l *splunkLogger) tryPostMessages(ctx context.Context, messages []*splunkMessage) error {
          if len(messages) == 0 {
              return nil
          }
          var buffer bytes.Buffer
      Severity: Minor
      Found in daemon/logger/splunk/splunk.go - About 1 hr to fix

        Function New has 14 return statements (exceeds 4 allowed).
        Open

        func New(info logger.Info) (logger.Logger, error) {
            hostname, err := info.Hostname()
            if err != nil {
                return nil, fmt.Errorf("%s: cannot access hostname to set source field", driverName)
            }
        Severity: Major
        Found in daemon/logger/splunk/splunk.go - About 1 hr to fix

          Method splunkLogger.tryPostMessages has 11 return statements (exceeds 4 allowed).
          Open

          func (l *splunkLogger) tryPostMessages(ctx context.Context, messages []*splunkMessage) error {
              if len(messages) == 0 {
                  return nil
              }
              var buffer bytes.Buffer
          Severity: Major
          Found in daemon/logger/splunk/splunk.go - About 1 hr to fix

            Consider simplifying this complex logical expression.
            Open

                if !splunkURL.IsAbs() ||
                    (splunkURL.Scheme != "http" && splunkURL.Scheme != "https") ||
                    (splunkURL.Path != "" && splunkURL.Path != "/") ||
                    splunkURL.RawQuery != "" ||
                    splunkURL.Fragment != "" {
            Severity: Major
            Found in daemon/logger/splunk/splunk.go - About 1 hr to fix

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

              func (l *splunkLogger) postMessages(messages []*splunkMessage, lastChance bool) []*splunkMessage {
                  messagesLen := len(messages)
              
                  ctx, cancel := context.WithTimeout(context.Background(), batchSendTimeout)
                  defer cancel()
              Severity: Minor
              Found in daemon/logger/splunk/splunk.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

              Avoid deeply nested control flow statements.
              Open

                                  if jsonEvent, err := json.Marshal(messages[j]); err != nil {
                                      log.G(ctx).Error(err)
                                  } else {
                                      log.G(ctx).Error(fmt.Errorf("Failed to send a message '%s'", string(jsonEvent)))
                                  }
              Severity: Major
              Found in daemon/logger/splunk/splunk.go - About 45 mins to fix

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

                func (l *splunkLogger) tryPostMessages(ctx context.Context, messages []*splunkMessage) error {
                    if len(messages) == 0 {
                        return nil
                    }
                    var buffer bytes.Buffer
                Severity: Minor
                Found in daemon/logger/splunk/splunk.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

                Function verifySplunkConnection has 5 return statements (exceeds 4 allowed).
                Open

                func verifySplunkConnection(l *splunkLogger) error {
                    req, err := http.NewRequest(http.MethodOptions, l.url, nil)
                    if err != nil {
                        return err
                    }
                Severity: Major
                Found in daemon/logger/splunk/splunk.go - About 35 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status