Skip to content

Commit be72a5d

Browse files
authored
Merge pull request #4 from NETWAYS/chore/update-golanglint
Update golanglint
2 parents fa16f81 + ea93c8d commit be72a5d

File tree

13 files changed

+94
-84
lines changed

13 files changed

+94
-84
lines changed

.golangci.yml

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
run:
22
timeout: 5m
3-
skip-files:
4-
- '(.+)_test\.go'
5-
3+
tests: false
64
linters:
7-
disable-all: false
8-
enable:
9-
- funlen
10-
- dogsled
11-
- dupl
12-
# - lll
13-
- whitespace
14-
- wsl
15-
- exportloopref
16-
disable:
17-
- scopelint
18-
- bodyclose
19-
- contextcheck
20-
- nilerr
21-
- noctx
22-
- rowserrcheck
23-
- sqlclosecheck
24-
- structcheck
25-
- unparam
26-
presets:
27-
- bugs
28-
- unused
29-
# - style
30-
fast: false
5+
enable-all: true
6+
disable:
7+
- cyclop
8+
- depguard
9+
- exhaustivestruct
10+
- exhaustruct
11+
- forbidigo
12+
- forcetypeassert
13+
- gci
14+
- gochecknoglobals
15+
- gochecknoinits
16+
- godox
17+
- goerr113
18+
- gofumpt
19+
- gomnd
20+
- lll
21+
- musttag
22+
- nakedret
23+
- nlreturn
24+
- nolintlint
25+
- nonamedreturns
26+
- tagliatelle
27+
- varnamelen
28+
- wrapcheck
29+
linters-settings:
30+
estif:
31+
min-complexity: 4
32+
maligned:
33+
suggest-new: true

cmd/alert.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package cmd
22

33
import (
44
"fmt"
5+
"strings"
6+
57
"github.com/NETWAYS/check_prometheus/internal/alert"
68
"github.com/NETWAYS/go-check"
79
"github.com/NETWAYS/go-check/perfdata"
810
"github.com/NETWAYS/go-check/result"
911
"github.com/spf13/cobra"
10-
"strings"
1112
)
1213

1314
func generateOutput(rl alert.Rule, cfg AlertConfig) (output string) {
@@ -78,7 +79,7 @@ inactive = 0`,
7879
// We use the Rules endpoint since it contains
7980
// the state of inactive Alert Rules, unlike the Alert endpoint
8081
// Search requested Alert in all Groups and all Rules
81-
alerts, err := c.Api.Rules(ctx)
82+
alerts, err := c.API.Rules(ctx)
8283
if err != nil {
8384
check.ExitError(err)
8485
}
@@ -89,7 +90,7 @@ inactive = 0`,
8990
// Set initial capacity to reduce memory allocations
9091
var l int
9192
for _, rl := range rules {
92-
l = l * len(rl.AlertingRule.Alerts)
93+
l *= len(rl.AlertingRule.Alerts)
9394
}
9495
rStates := make([]int, 0, l)
9596

cmd/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ type Config struct {
2828
CertFile string
2929
KeyFile string
3030
Hostname string
31+
Port int
3132
Info bool
3233
Insecure bool
3334
PReady bool
34-
Port int
3535
Secure bool
3636
}
3737

@@ -95,20 +95,20 @@ func (c *Config) NewClient() *client.Client {
9595

9696
// Using a Bearer Token for authentication
9797
if c.Bearer != "" {
98-
var t config.Secret = config.Secret(c.Bearer)
98+
var t = config.Secret(c.Bearer)
9999
rt = config.NewAuthorizationCredentialsRoundTripper("Bearer", t, rt)
100100
}
101101

102102
// Using a BasicAuth for authentication
103103
if c.BasicAuth != "" {
104104
s := strings.Split(c.BasicAuth, ":")
105105
if len(s) != 2 {
106-
check.ExitError(fmt.Errorf("Specify the user name and password for server authentication <user:password>"))
106+
check.ExitError(fmt.Errorf("specify the user name and password for server authentication <user:password>"))
107107
}
108108

109-
var u string = s[0]
109+
var u = s[0]
110110

111-
var p config.Secret = config.Secret(s[1])
111+
var p = config.Secret(s[1])
112112

113113
rt = config.NewBasicAuthRoundTripper(u, p, "", rt)
114114
}

cmd/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
func TestConfig(t *testing.T) {
88
c := cliConfig.NewClient()
99
expected := "http://localhost:9090"
10-
if c.Url != "http://localhost:9090" {
11-
t.Error("\nActual: ", c.Url, "\nExpected: ", expected)
10+
if c.URL != "http://localhost:9090" {
11+
t.Error("\nActual: ", c.URL, "\nExpected: ", expected)
1212
}
1313
}

cmd/health.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
56
"github.com/NETWAYS/go-check"
67
"github.com/NETWAYS/go-check/perfdata"
78
"github.com/spf13/cobra"
@@ -53,7 +54,7 @@ Ready: Checks the readiness of an endpoint, which returns OK if the Prometheus s
5354

5455
if cliConfig.Info {
5556
// Displays various build information properties about the Prometheus server
56-
info, err := c.Api.Buildinfo(ctx)
57+
info, err := c.API.Buildinfo(ctx)
5758
if err != nil {
5859
check.ExitError(err)
5960
}

cmd/health_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestHealth_ConnectionRefused(t *testing.T) {
1515
out, _ := cmd.CombinedOutput()
1616

1717
actual := string(out)
18-
expected := "[UNKNOWN] - Could not get status: Get \"http://localhost:9999/-/healthy\": dial"
18+
expected := "[UNKNOWN] - could not get status: Get \"http://localhost:9999/-/healthy\": dial"
1919

2020
if !strings.Contains(actual, expected) {
2121
t.Error("\nActual: ", actual, "\nExpected: ", expected)
@@ -133,7 +133,7 @@ func TestHealthCmd(t *testing.T) {
133133
w.Write([]byte(`Access Denied!`))
134134
})),
135135
args: []string{"run", "../main.go", "--user", "passwordmissing", "health"},
136-
expected: "[UNKNOWN] - Specify the user name and password for server authentication <user:password> (*errors.errorString)\nexit status 3\n",
136+
expected: "[UNKNOWN] - specify the user name and password for server authentication <user:password> (*errors.errorString)\nexit status 3\n",
137137
},
138138
}
139139

cmd/query.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package cmd
22

33
import (
44
"fmt"
5+
"strings"
6+
"time"
7+
58
"github.com/NETWAYS/go-check"
69
"github.com/NETWAYS/go-check/perfdata"
710
goresult "github.com/NETWAYS/go-check/result"
811
"github.com/prometheus/common/model"
912
"github.com/spf13/cobra"
10-
"strings"
11-
"time"
1213
)
1314

1415
type QueryConfig struct {
@@ -54,7 +55,7 @@ Note: Time range values e.G. 'go_memstats_alloc_bytes_total[0s]' only the latest
5455
| value_go_gc_duration_seconds_count_localhost:9090_prometheus=1599 value_go_gc_duration_seconds_count_node-exporter:9100_node-exporter=79610`,
5556
PreRun: func(cmd *cobra.Command, args []string) {
5657
if cliQueryConfig.Warning == "" || cliQueryConfig.Critical == "" {
57-
check.ExitError(fmt.Errorf("Please specify warning and critical thresholds"))
58+
check.ExitError(fmt.Errorf("please specify warning and critical thresholds"))
5859
}
5960
},
6061
Run: func(cmd *cobra.Command, args []string) {
@@ -89,26 +90,26 @@ Note: Time range values e.G. 'go_memstats_alloc_bytes_total[0s]' only the latest
8990
ctx, cancel := cliConfig.timeoutContext()
9091
defer cancel()
9192

92-
result, warnings, err := c.Api.Query(ctx, cliQueryConfig.RawQuery, time.Now())
93+
result, warnings, err := c.API.Query(ctx, cliQueryConfig.RawQuery, time.Now())
9394

9495
if err != nil {
9596
if strings.Contains(err.Error(), "unmarshalerDecoder: unexpected value type \"string\"") {
96-
err = fmt.Errorf("String value results are not supported")
97+
err = fmt.Errorf("string value results are not supported")
9798
}
9899
check.ExitError(err)
99100
}
100101

101102
switch result.Type() {
102103
default:
103-
check.ExitError(fmt.Errorf("None value results are not supported"))
104+
check.ExitError(fmt.Errorf("none value results are not supported"))
104105
// Scalar - a simple numeric floating point value
105106
case model.ValScalar:
106-
check.ExitError(fmt.Errorf("Scalar value results are not supported"))
107+
check.ExitError(fmt.Errorf("scalar value results are not supported"))
107108
case model.ValNone:
108-
check.ExitError(fmt.Errorf("None value results are not supported"))
109+
check.ExitError(fmt.Errorf("none value results are not supported"))
109110
case model.ValString:
110111
// String - a simple string value; currently unused
111-
check.ExitError(fmt.Errorf("String value results are not supported"))
112+
check.ExitError(fmt.Errorf("string value results are not supported"))
112113
case model.ValVector:
113114
// Instant vector - a set of time series containing a single sample for each time series, all sharing the same timestamp
114115
vectorVal := result.(model.Vector)
@@ -175,9 +176,7 @@ Note: Time range values e.G. 'go_memstats_alloc_bytes_total[0s]' only the latest
175176
states = mStates
176177
}
177178

178-
// The worst state of all metrics determines the final return state. Example:
179-
// OK, OK, OK > OK
180-
// Critical, OK, OK > Critical
179+
// The worst state of all metrics determines the final return state.
181180
worstState := goresult.WorstState(states...)
182181
if worstState == check.OK {
183182
summary.WriteString(fmt.Sprintf("%d Metrics OK", metricsCounter))

cmd/query_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestQueryCmd(t *testing.T) {
7979
w.Write([]byte(`{"status":"success","data":{"resultType":"scalar","result":[1670339013.992,"1"]}}`))
8080
})),
8181
args: []string{"run", "../main.go", "query", "--query", "1"},
82-
expected: "[UNKNOWN] - Scalar value results are not supported (*errors.errorString)\nexit status 3\n",
82+
expected: "[UNKNOWN] - scalar value results are not supported (*errors.errorString)\nexit status 3\n",
8383
},
8484
{
8585
name: "query-string",
@@ -88,7 +88,7 @@ func TestQueryCmd(t *testing.T) {
8888
w.Write([]byte(`{"status":"success","data":{"resultType":"string","result":[1670339013.992,"up"]}}`))
8989
})),
9090
args: []string{"run", "../main.go", "query", "--query", "up"},
91-
expected: "[UNKNOWN] - String value results are not supported (*errors.errorString)\nexit status 3\n",
91+
expected: "[UNKNOWN] - string value results are not supported (*errors.errorString)\nexit status 3\n",
9292
},
9393
{
9494
name: "query-matrix-exists",

cmd/root.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package cmd
22

33
import (
4+
"os"
5+
46
"github.com/NETWAYS/go-check"
57
"github.com/spf13/cobra"
6-
"os"
78
)
89

910
var Timeout = 30
@@ -66,7 +67,7 @@ func init() {
6667
rootCmd.SetHelpTemplate(help + Copyright)
6768
}
6869

69-
func Usage(cmd *cobra.Command, strings []string) {
70+
func Usage(cmd *cobra.Command, _ []string) {
7071
_ = cmd.Usage()
7172

7273
os.Exit(3)

internal/alert/alert.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@ package alert
22

33
import (
44
"fmt"
5+
"strconv"
6+
"strings"
7+
58
"github.com/NETWAYS/go-check"
69
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
710
"github.com/prometheus/common/model"
8-
"strconv"
9-
"strings"
1011
)
1112

12-
// Internal representation of Prometheus Rules
13-
// Alert attribute will be used when iterating over multiple AlertingRules
13+
// Internal representation of Prometheus Rules.
14+
// Alert attribute will be used when iterating over multiple AlertingRules.
1415
type Rule struct {
1516
AlertingRule v1.AlertingRule
1617
Alert *v1.Alert
1718
}
1819

1920
func FlattenRules(groups []v1.RuleGroup) []Rule {
2021
// Flattens a list of RuleGroup containing a list of Rules into
21-
// a list of internal Alertingrules
22+
// a list of internal Alertingrules.
2223
var l int
23-
// Set initial capacity to reduce memory allocations
24+
// Set initial capacity to reduce memory allocations.
2425
for _, grp := range groups {
25-
l = l + len(grp.Rules)
26+
l += len(grp.Rules)
2627
}
2728

2829
rules := make([]Rule, 0, l)
@@ -31,8 +32,8 @@ func FlattenRules(groups []v1.RuleGroup) []Rule {
3132

3233
for _, grp := range groups {
3334
for _, rl := range grp.Rules {
34-
// For now we only care about AlertingRules
35-
// since RecodingRules can simply be queried
35+
// For now we only care about AlertingRules,
36+
// since RecodingRules can simply be queried.
3637
if _, ok := rl.(v1.AlertingRule); ok {
3738
r.AlertingRule = rl.(v1.AlertingRule)
3839
rules = append(rules, r)

0 commit comments

Comments
 (0)