From 1cb71fe922274eb242f34b6e57854ff0af2281f7 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Fri, 3 Feb 2023 12:44:07 +0100 Subject: [PATCH 1/2] Refactor to use strings.Builder --- cmd/health.go | 11 ++++++----- cmd/pipeline.go | 14 ++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cmd/health.go b/cmd/health.go index 266cc7c..5f41dd0 100644 --- a/cmd/health.go +++ b/cmd/health.go @@ -10,6 +10,7 @@ import ( "github.com/spf13/cobra" "net/http" "net/url" + "strings" ) // To store the CLI parameters @@ -142,7 +143,6 @@ var healthCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { var ( output string - summary string rc int stat logstash.Stat thresholds HealthThreshold @@ -247,11 +247,12 @@ var healthCmd = &cobra.Command{ } // Generate summary for subchecks - summary += fmt.Sprintf("\n \\_[%s] Heap usage at %.2f%%", heapstatus, stat.Jvm.Mem.HeapUsedPercent) - summary += fmt.Sprintf("\n \\_[%s] Open file descriptors at %.2f%%", fdstatus, fileDescriptorsPercent) - summary += fmt.Sprintf("\n \\_[%s] CPU usage at %.2f%%", cpustatus, stat.Process.CPU.Percent) + var summary strings.Builder + summary.WriteString(fmt.Sprintf("\n \\_[%s] Heap usage at %.2f%%", heapstatus, stat.Jvm.Mem.HeapUsedPercent)) + summary.WriteString(fmt.Sprintf("\n \\_[%s] Open file descriptors at %.2f%%", fdstatus, fileDescriptorsPercent)) + summary.WriteString(fmt.Sprintf("\n \\_[%s] CPU usage at %.2f%%", cpustatus, stat.Process.CPU.Percent)) - check.ExitRaw(rc, output, summary, "|", perfList.String()) + check.ExitRaw(rc, output, summary.String(), "|", perfList.String()) }, } diff --git a/cmd/pipeline.go b/cmd/pipeline.go index eae0b9a..ed30b57 100644 --- a/cmd/pipeline.go +++ b/cmd/pipeline.go @@ -10,6 +10,7 @@ import ( "github.com/spf13/cobra" "net/http" "net/url" + "strings" ) // To store the CLI parameters @@ -64,7 +65,6 @@ var pipelineCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { var ( output string - summary string rc int pp logstash.Pipeline thresholds PipelineThreshold @@ -102,19 +102,21 @@ var pipelineCmd = &cobra.Command{ states := make([]int, 0, len(pp.Pipelines)) // Check status for each pipeline + var summary strings.Builder + for name, pipe := range pp.Pipelines { inflightEvents := pipe.Events.In - pipe.Events.Out - summary += "\n \\_" + summary.WriteString("\n \\_") if thresholds.inflightEventsCrit.DoesViolate(float64(inflightEvents)) { states = append(states, check.Critical) - summary += fmt.Sprintf("[CRITICAL] inflight_events_%s:%d;", name, inflightEvents) + summary.WriteString(fmt.Sprintf("[CRITICAL] inflight_events_%s:%d;", name, inflightEvents)) } else if thresholds.inflightEventsWarn.DoesViolate(float64(inflightEvents)) { states = append(states, check.Warning) - summary += fmt.Sprintf("[WARNING] inflight_events_%s:%d;", name, inflightEvents) + summary.WriteString(fmt.Sprintf("[WARNING] inflight_events_%s:%d;", name, inflightEvents)) } else { states = append(states, check.OK) - summary += fmt.Sprintf("[OK] inflight_events_%s:%d;", name, inflightEvents) + summary.WriteString(fmt.Sprintf("[OK] inflight_events_%s:%d;", name, inflightEvents)) } // Generate perfdata for each event @@ -155,7 +157,7 @@ var pipelineCmd = &cobra.Command{ output = "Inflight events status unknown" } - check.ExitRaw(rc, output, summary, "|", perfList.String()) + check.ExitRaw(rc, output, summary.String(), "|", perfList.String()) }, } From c51ecc319526f6a7424ad018fb6284397516aabc Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Fri, 3 Feb 2023 13:02:46 +0100 Subject: [PATCH 2/2] Update golangci-lint config --- .golangci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9145d76..490bbe9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,7 +11,6 @@ linters: - funlen - dogsled - dupl - # - lll - whitespace - wsl - exportloopref @@ -25,8 +24,8 @@ linters: - sqlclosecheck - structcheck - unparam + - musttag presets: - bugs - unused - # - style fast: false