Skip to content

Commit 1812ec8

Browse files
committed
Update build
* Update minimum Go to 1.24.0. * Update build to Go 1.25. * Update golangci-lint. * Fixup linting issues. Signed-off-by: SuperQ <superq@gmail.com>
1 parent 12564c9 commit 1812ec8

10 files changed

Lines changed: 53 additions & 29 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
name: Verify
5252
runs-on: ubuntu-latest
5353
container:
54-
image: quay.io/prometheus/golang-builder:1.23-base
54+
image: quay.io/prometheus/golang-builder:1.25-base
5555
steps:
5656
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5757
- run: make build

.github/workflows/golangci-lint.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@ jobs:
2525
steps:
2626
- name: Checkout repository
2727
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28+
with:
29+
persist-credentials: false
2830
- name: Install Go
29-
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
31+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
3032
with:
31-
go-version: 1.23.x
33+
go-version: 1.25.x
3234
- name: Install snmp_exporter/generator dependencies
3335
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
3436
if: github.repository == 'prometheus/snmp_exporter'
37+
- name: Get golangci-lint version
38+
id: golangci-lint-version
39+
run: echo "version=$(make print-golangci-lint-version)" >> $GITHUB_OUTPUT
3540
- name: Lint
36-
uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0
41+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
3742
with:
3843
args: --verbose
39-
version: v1.63.4
44+
version: ${{ steps.golangci-lint-version.outputs.version }}

.golangci.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
---
1+
version: "2"
22
linters:
33
enable:
44
- misspell
55
- sloglint
6-
7-
issues:
8-
exclude-rules:
9-
- path: _test.go
10-
linters:
11-
- errcheck
6+
exclusions:
7+
generated: lax
8+
presets:
9+
- comments
10+
- common-false-positives
11+
- legacy
12+
- std-error-handling
13+
rules:
14+
- linters:
15+
- errcheck
16+
path: _test.go
17+
formatters:
18+
exclusions:
19+
generated: lax

.promu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
go:
22
# This must match .circle/config.yml.
3-
version: 1.23
3+
version: 1.25
44
repository:
55
path: github.com/prometheus-community/fortigate_exporter
66
build:

Makefile.common

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
6161
SKIP_GOLANGCI_LINT :=
6262
GOLANGCI_LINT :=
6363
GOLANGCI_LINT_OPTS ?=
64-
GOLANGCI_LINT_VERSION ?= v1.63.4
64+
GOLANGCI_LINT_VERSION ?= v2.4.0
65+
GOLANGCI_FMT_OPTS ?=
6566
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
6667
# windows isn't included here because of the path separator being different.
6768
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
@@ -138,7 +139,7 @@ common-deps:
138139
update-go-deps:
139140
@echo ">> updating Go dependencies"
140141
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
141-
$(GO) get -d $$m; \
142+
$(GO) get $$m; \
142143
done
143144
$(GO) mod tidy
144145

@@ -156,9 +157,13 @@ $(GOTEST_DIR):
156157
@mkdir -p $@
157158

158159
.PHONY: common-format
159-
common-format:
160+
common-format: $(GOLANGCI_LINT)
160161
@echo ">> formatting code"
161162
$(GO) fmt $(pkgs)
163+
ifdef GOLANGCI_LINT
164+
@echo ">> formatting code with golangci-lint"
165+
$(GOLANGCI_LINT) fmt $(GOLANGCI_FMT_OPTS)
166+
endif
162167

163168
.PHONY: common-vet
164169
common-vet:
@@ -248,8 +253,8 @@ $(PROMU):
248253
cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
249254
rm -r $(PROMU_TMP)
250255

251-
.PHONY: proto
252-
proto:
256+
.PHONY: common-proto
257+
common-proto:
253258
@echo ">> generating code from proto files"
254259
@./scripts/genproto.sh
255260

@@ -261,6 +266,10 @@ $(GOLANGCI_LINT):
261266
| sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
262267
endif
263268

269+
.PHONY: common-print-golangci-lint-version
270+
common-print-golangci-lint-version:
271+
@echo $(GOLANGCI_LINT_VERSION)
272+
264273
.PHONY: precheck
265274
precheck::
266275

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/prometheus-community/fortigate_exporter
22

3-
go 1.22.0
3+
go 1.24.0
44

55
require (
66
github.com/google/go-jsonnet v0.20.0

pkg/http/forti_token_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (c *fortiTokenClient) Get(path string, query string, obj interface{}) error
7777
return err
7878
}
7979
if resp.StatusCode != 200 {
80-
return fmt.Errorf("Response code was %d, expected 200 (path: %q)", resp.StatusCode, path)
80+
return fmt.Errorf("response code was %d, expected 200 (path: %q)", resp.StatusCode, path)
8181
}
8282

8383
b, err := io.ReadAll(resp.Body)

pkg/probe/firewall_load_balance.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@ func probeFirewallLoadBalance(c http.FortiHTTP, meta *TargetMetadata) ([]prometh
133133
}
134134

135135
realServerRTTValue := math.NaN()
136-
if "<1" == realServer.RTT {
136+
switch realServer.RTT {
137+
case "<1":
137138
realServerRTTValue = 0.001
138-
} else if "" == realServer.RTT {
139+
case "":
139140
// NaN
140-
} else {
141+
default:
141142
if realServerRTTValueInMs, err := strconv.ParseFloat(realServer.RTT, 64); err != nil {
142143
log.Printf("Failed to parse RTT value: %v", err)
143144
} else {

pkg/probe/probe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (p *ProbeCollector) Probe(ctx context.Context, target map[string]string, hc
6767
}
6868

6969
if tgt.Scheme != "https" && tgt.Scheme != "http" {
70-
return false, fmt.Errorf("Unsupported scheme %q", tgt.Scheme)
70+
return false, fmt.Errorf("unsupported scheme %q", tgt.Scheme)
7171
}
7272

7373
// Filter anything else than scheme and hostname

pkg/probe/system_sdn_connector.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ func probeSystemSDNConnector(c http.FortiHTTP, meta *TargetMetadata) ([]promethe
5656
m := []prometheus.Metric{}
5757
for _, r := range res {
5858
for _, sdnConn := range r.Results {
59-
if sdnConn.Status == "Disabled" {
59+
switch sdnConn.Status {
60+
case "Disabled":
6061
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(0), r.VDOM, sdnConn.Name, sdnConn.Type))
61-
} else if sdnConn.Status == "Down" {
62+
case "Down":
6263
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(1), r.VDOM, sdnConn.Name, sdnConn.Type))
63-
} else if sdnConn.Status == "Unknown" {
64+
case "Unknown":
6465
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(2), r.VDOM, sdnConn.Name, sdnConn.Type))
65-
} else if sdnConn.Status == "Up" {
66+
case "Up":
6667
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(3), r.VDOM, sdnConn.Name, sdnConn.Type))
67-
} else if sdnConn.Status == "Updating" {
68+
case "Updating":
6869
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsStatus, prometheus.GaugeValue, float64(4), r.VDOM, sdnConn.Name, sdnConn.Type))
6970
}
7071
m = append(m, prometheus.MustNewConstMetric(SDNConnectorsLastUpdate, prometheus.GaugeValue, float64(sdnConn.LastUpdate), r.VDOM, sdnConn.Name, sdnConn.Type))

0 commit comments

Comments
 (0)