1
0
mirror of https://github.com/nginxinc/nginx-prometheus-exporter.git synced 2025-07-31 21:04:21 +03:00

Enable more linters (#622)

This commit is contained in:
Luca Comellini
2024-02-22 10:27:54 -08:00
committed by GitHub
parent e848697cec
commit d620391f71
9 changed files with 41 additions and 38 deletions

View File

@ -20,9 +20,6 @@ jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
@ -34,8 +31,6 @@ jobs:
- name: Lint Code
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v4.0.0
with:
only-new-issues: true
actionlint:
name: Actionlint

View File

@ -31,10 +31,15 @@ linters-settings:
errcheck:
exclude-functions:
- (github.com/go-kit/log.Logger).Log
govet:
check-shadowing: true
enable-all: true
linters:
enable:
- asciicheck
- bidichk
- dupword
- errcheck
- errorlint
- gofmt
@ -44,18 +49,23 @@ linters:
- gosimple
- govet
- ineffassign
- loggercheck
- makezero
- misspell
- nilerr
- noctx
- perfsprint
- predeclared
- promlinter
- revive
- staticcheck
- tagalign
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
disable-all: true
issues:

View File

@ -25,20 +25,10 @@ repos:
- id: requirements-txt-fixer
- id: fix-byte-order-marker
- repo: local
hooks:
- id: golang-diff
name: create-go-diff
entry: bash -c 'git diff -p origin/main > /tmp/diff.patch'
language: system
types: [go]
pass_filenames: false
- repo: https://github.com/golangci/golangci-lint
rev: v1.56.2
hooks:
- id: golangci-lint
args: [--new-from-patch=/tmp/diff.patch]
- id: golangci-lint-full
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.2
@ -55,4 +45,4 @@ repos:
hooks:
- id: yamllint
ci:
skip: [golang-diff, golangci-lint, yamllint]
skip: [golangci-lint-full, yamllint]

View File

@ -16,8 +16,8 @@ Reading: %d Writing: %d Waiting: %d
// NginxClient allows you to fetch NGINX metrics from the stub_status page.
type NginxClient struct {
apiEndpoint string
httpClient *http.Client
apiEndpoint string
}
// StubStats represents NGINX stub_status metrics.

View File

@ -9,8 +9,10 @@ func TestMergeLabels(t *testing.T) {
t.Parallel()
tests := []struct {
name string
mapA, mapB, want map[string]string
mapA map[string]string
mapB map[string]string
want map[string]string
name string
}{
{
name: "base case",
@ -32,7 +34,9 @@ func TestMergeLabels(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := MergeLabels(tt.mapA, tt.mapB); !reflect.DeepEqual(got, tt.want) {
t.Errorf("mergeLabels() = %v, want %v", got, tt.want)
}

View File

@ -11,11 +11,11 @@ import (
// NginxCollector collects NGINX metrics. It implements prometheus.Collector interface.
type NginxCollector struct {
upMetric prometheus.Gauge
logger log.Logger
nginxClient *client.NginxClient
metrics map[string]*prometheus.Desc
upMetric prometheus.Gauge
mutex sync.Mutex
logger log.Logger
}
// NewNginxCollector creates an NginxCollector.

View File

@ -33,11 +33,11 @@ type LabelUpdater interface {
// NginxPlusCollector collects NGINX Plus metrics. It implements prometheus.Collector interface.
type NginxPlusCollector struct {
upMetric prometheus.Gauge
logger log.Logger
cacheZoneMetrics map[string]*prometheus.Desc
workerMetrics map[string]*prometheus.Desc
nginxClient *plusclient.NginxClient
totalMetrics map[string]*prometheus.Desc
serverZoneMetrics map[string]*prometheus.Desc
upstreamMetrics map[string]*prometheus.Desc
upstreamServerMetrics map[string]*prometheus.Desc
streamServerZoneMetrics map[string]*prometheus.Desc
streamZoneSyncMetrics map[string]*prometheus.Desc
streamUpstreamMetrics map[string]*prometheus.Desc
@ -47,21 +47,21 @@ type NginxPlusCollector struct {
limitRequestMetrics map[string]*prometheus.Desc
limitConnectionMetrics map[string]*prometheus.Desc
streamLimitConnectionMetrics map[string]*prometheus.Desc
cacheZoneMetrics map[string]*prometheus.Desc
upMetric prometheus.Gauge
mutex sync.Mutex
variableLabelNames VariableLabelNames
upstreamServerMetrics map[string]*prometheus.Desc
upstreamMetrics map[string]*prometheus.Desc
streamUpstreamServerPeerLabels map[string][]string
serverZoneMetrics map[string]*prometheus.Desc
upstreamServerLabels map[string][]string
streamUpstreamServerLabels map[string][]string
serverZoneLabels map[string][]string
streamServerZoneLabels map[string][]string
upstreamServerPeerLabels map[string][]string
streamUpstreamServerPeerLabels map[string][]string
cacheZoneLabels map[string][]string
variableLabelsMutex sync.RWMutex
logger log.Logger
workerLabels map[string][]string
workerMetrics map[string]*prometheus.Desc
cacheZoneLabels map[string][]string
totalMetrics map[string]*prometheus.Desc
variableLabelNames VariableLabelNames
variableLabelsMutex sync.RWMutex
mutex sync.Mutex
}
// UpdateUpstreamServerPeerLabels updates the Upstream Server Peer Labels

View File

@ -67,7 +67,7 @@ func parseUnixSocketAddress(address string) (string, string, error) {
addressPartsLength := len(addressParts)
if addressPartsLength > 3 || addressPartsLength < 1 {
return "", "", fmt.Errorf("address for unix domain socket has wrong format")
return "", "", errors.New("address for unix domain socket has wrong format")
}
unixSocketPath := addressParts[1]
@ -103,7 +103,7 @@ func main() {
// convert deprecated flags to new format
for i, arg := range os.Args {
if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") && len(arg) > 2 {
newArg := fmt.Sprintf("-%s", arg)
newArg := "-" + arg
fmt.Printf("the flag format is deprecated and will be removed in a future release, please use the new format: %s\n", newArg)
os.Args[i] = newArg
}
@ -261,8 +261,8 @@ func registerCollector(logger log.Logger, transport *http.Transport,
}
type userAgentRoundTripper struct {
agent string
rt http.RoundTripper
agent string
}
func (rt *userAgentRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {

View File

@ -38,7 +38,9 @@ func TestParsePositiveDuration(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := parsePositiveDuration(tt.testInput)
if (err != nil) != tt.wantErr {
t.Errorf("parsePositiveDuration() error = %v, wantErr %v", err, tt.wantErr)
@ -91,7 +93,9 @@ func TestParseUnixSocketAddress(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
socketPath, requestPath, err := parseUnixSocketAddress(tt.testInput)
if (err != nil) != tt.wantErr {
t.Errorf("parseUnixSocketAddress() error = %v, wantErr %v", err, tt.wantErr)