martin-helmich/prometheus-nginxlog-exporter

View on GitHub
main.go

Summary

Maintainability
C
1 day
Test Coverage

Function main has 83 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func main() {
    var opts config.StartupFlags
    var cfg = config.Config{
        Listen: config.ListenConfig{
            Port:            4040,
Severity: Major
Found in main.go - About 2 hrs to fix

    Function processSource has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
    Open

    func processSource(logger *log.Logger, nsCfg *config.NamespaceConfig, t tail.Follower, parser parser.Parser, metrics *metrics.Collection, hasCounterOnlyLabels bool) error {
        relabelings := relabeling.NewRelabelings(nsCfg.RelabelConfigs)
        relabelings = append(relabelings, relabeling.DefaultRelabelings...)
        relabelings = relabeling.UniqueRelabelings(relabelings)
    
    
    Severity: Minor
    Found in main.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

    Function processSource has 56 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func processSource(logger *log.Logger, nsCfg *config.NamespaceConfig, t tail.Follower, parser parser.Parser, metrics *metrics.Collection, hasCounterOnlyLabels bool) error {
        relabelings := relabeling.NewRelabelings(nsCfg.RelabelConfigs)
        relabelings = append(relabelings, relabeling.DefaultRelabelings...)
        relabelings = relabeling.UniqueRelabelings(relabelings)
    
    
    Severity: Minor
    Found in main.go - About 1 hr to fix

      Function processNamespace has 55 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func processNamespace(logger *log.Logger, nsCfg *config.NamespaceConfig, metrics *metrics.Collection, stopChan <-chan bool, stopHandlers *sync.WaitGroup) error {
          var followers []tail.Follower
      
          logParser := parser.NewParser(nsCfg)
      
      
      Severity: Minor
      Found in main.go - About 1 hr to fix

        Function processSource has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        func processSource(logger *log.Logger, nsCfg *config.NamespaceConfig, t tail.Follower, parser parser.Parser, metrics *metrics.Collection, hasCounterOnlyLabels bool) error {
        Severity: Minor
        Found in main.go - About 45 mins to fix

          Function processNamespace has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          func processNamespace(logger *log.Logger, nsCfg *config.NamespaceConfig, metrics *metrics.Collection, stopChan <-chan bool, stopHandlers *sync.WaitGroup) error {
          Severity: Minor
          Found in main.go - About 35 mins to fix

            Function observeMetrics has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            func observeMetrics(logger *log.Logger, fields map[string]string, name string, extractor func(map[string]string, string) (float64, bool, error), parseErrors prometheus.Counter) (float64, bool) {
            Severity: Minor
            Found in main.go - About 35 mins to fix

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

              func floatFromFieldsMulti(fields map[string]string, name string) (float64, bool, error) {
                  f, ok, err := floatFromFields(fields, name)
                  if err == nil {
                      return f, ok, nil
                  }
              Severity: Major
              Found in main.go - About 35 mins to fix

                Function processNamespace has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                Open

                func processNamespace(logger *log.Logger, nsCfg *config.NamespaceConfig, metrics *metrics.Collection, stopChan <-chan bool, stopHandlers *sync.WaitGroup) error {
                    var followers []tail.Follower
                
                    logParser := parser.NewParser(nsCfg)
                
                
                Severity: Minor
                Found in main.go - About 25 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

                There are no issues that match your filters.

                Category
                Status