Skip to content

Commit 0008ee9

Browse files
committed
Update build and cleanup
* Update Go to 1.20. * Update Makefile.common * Update golangci-lint. * Update exporter-toolkit. * Cleanup useless `_` assignment for go-kit/log. * Cleanup deprecated and unused code. Signed-off-by: SuperQ <[email protected]>
1 parent 33b6077 commit 0008ee9

27 files changed

+192
-617
lines changed

.circleci/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
version: 2.1
33
orbs:
4-
prometheus: prometheus/prometheus@0.16.0
4+
prometheus: prometheus/prometheus@0.17.1
55
executors:
66
# This must match .promu.yml.
77
golang:
88
docker:
9-
- image: cimg/go:1.19
9+
- image: cimg/go:1.20
1010
jobs:
1111
test:
1212
executor: golang

.github/workflows/golangci-lint.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ jobs:
1818
- name: Checkout repository
1919
uses: actions/checkout@v3
2020
- name: install Go
21-
uses: actions/setup-go@v2
21+
uses: actions/setup-go@v3
2222
with:
23-
go-version: 1.18.x
23+
go-version: 1.20.x
2424
- name: Install snmp_exporter/generator dependencies
2525
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
2626
if: github.repository == 'prometheus/snmp_exporter'
2727
- name: Lint
28-
uses: golangci/golangci-lint-action@v3.2.0
28+
uses: golangci/golangci-lint-action@v3.4.0
2929
with:
30-
version: v1.45.2
30+
version: v1.51.2

.golangci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ issues:
88
- path: _test.go
99
linters:
1010
- errcheck
11+
12+
linters-settings:
13+
errcheck:
14+
exclude: scripts/errcheck_excludes.txt

.promu.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
go:
22
# This must match .circle/config.yml.
3-
version: 1.19
3+
version: 1.20
44
repository:
55
path: github.com/prometheus-community/elasticsearch_exporter
66
build:

Makefile.common

+9-7
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ 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.49.0
64+
GOLANGCI_LINT_VERSION ?= v1.51.2
6565
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
6666
# windows isn't included here because of the path separator being different.
6767
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
@@ -91,6 +91,8 @@ BUILD_DOCKER_ARCHS = $(addprefix common-docker-,$(DOCKER_ARCHS))
9191
PUBLISH_DOCKER_ARCHS = $(addprefix common-docker-publish-,$(DOCKER_ARCHS))
9292
TAG_DOCKER_ARCHS = $(addprefix common-docker-tag-latest-,$(DOCKER_ARCHS))
9393

94+
SANITIZED_DOCKER_IMAGE_TAG := $(subst +,-,$(DOCKER_IMAGE_TAG))
95+
9496
ifeq ($(GOHOSTARCH),amd64)
9597
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux freebsd darwin windows))
9698
# Only supported on amd64
@@ -205,7 +207,7 @@ common-tarball: promu
205207
.PHONY: common-docker $(BUILD_DOCKER_ARCHS)
206208
common-docker: $(BUILD_DOCKER_ARCHS)
207209
$(BUILD_DOCKER_ARCHS): common-docker-%:
208-
docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" \
210+
docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" \
209211
-f $(DOCKERFILE_PATH) \
210212
--build-arg ARCH="$*" \
211213
--build-arg OS="linux" \
@@ -214,19 +216,19 @@ $(BUILD_DOCKER_ARCHS): common-docker-%:
214216
.PHONY: common-docker-publish $(PUBLISH_DOCKER_ARCHS)
215217
common-docker-publish: $(PUBLISH_DOCKER_ARCHS)
216218
$(PUBLISH_DOCKER_ARCHS): common-docker-publish-%:
217-
docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)"
219+
docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)"
218220

219221
DOCKER_MAJOR_VERSION_TAG = $(firstword $(subst ., ,$(shell cat VERSION)))
220222
.PHONY: common-docker-tag-latest $(TAG_DOCKER_ARCHS)
221223
common-docker-tag-latest: $(TAG_DOCKER_ARCHS)
222224
$(TAG_DOCKER_ARCHS): common-docker-tag-latest-%:
223-
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:latest"
224-
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)"
225+
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:latest"
226+
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)"
225227

226228
.PHONY: common-docker-manifest
227229
common-docker-manifest:
228-
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" $(foreach ARCH,$(DOCKER_ARCHS),$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$(ARCH):$(DOCKER_IMAGE_TAG))
229-
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)"
230+
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)" $(foreach ARCH,$(DOCKER_ARCHS),$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$(ARCH):$(SANITIZED_DOCKER_IMAGE_TAG))
231+
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)"
230232

231233
.PHONY: promu
232234
promu: $(PROMU)

collector/cluster_health.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package collector
1616
import (
1717
"encoding/json"
1818
"fmt"
19-
"io/ioutil"
19+
"io"
2020
"net/http"
2121
"net/url"
2222
"path"
@@ -245,7 +245,7 @@ func (c *ClusterHealth) fetchAndDecodeClusterHealth() (clusterHealthResponse, er
245245
defer func() {
246246
err = res.Body.Close()
247247
if err != nil {
248-
_ = level.Warn(c.logger).Log(
248+
level.Warn(c.logger).Log(
249249
"msg", "failed to close http.Client",
250250
"err", err,
251251
)
@@ -256,7 +256,7 @@ func (c *ClusterHealth) fetchAndDecodeClusterHealth() (clusterHealthResponse, er
256256
return chr, fmt.Errorf("HTTP Request failed with code %d", res.StatusCode)
257257
}
258258

259-
bts, err := ioutil.ReadAll(res.Body)
259+
bts, err := io.ReadAll(res.Body)
260260
if err != nil {
261261
c.jsonParseFailures.Inc()
262262
return chr, err
@@ -283,7 +283,7 @@ func (c *ClusterHealth) Collect(ch chan<- prometheus.Metric) {
283283
clusterHealthResp, err := c.fetchAndDecodeClusterHealth()
284284
if err != nil {
285285
c.up.Set(0)
286-
_ = level.Warn(c.logger).Log(
286+
level.Warn(c.logger).Log(
287287
"msg", "failed to fetch and decode cluster health",
288288
"err", err,
289289
)

collector/cluster_info.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package collector
1616
import (
1717
"context"
1818
"encoding/json"
19-
"io/ioutil"
19+
"io"
2020
"net/http"
2121
"net/url"
2222

@@ -83,7 +83,7 @@ func (c *ClusterInfoCollector) Update(ctx context.Context, ch chan<- prometheus.
8383
return err
8484
}
8585
defer resp.Body.Close()
86-
b, err := ioutil.ReadAll(resp.Body)
86+
b, err := io.ReadAll(resp.Body)
8787
if err != nil {
8888
return err
8989
}

collector/cluster_settings.go

+2-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package collector
1616
import (
1717
"context"
1818
"encoding/json"
19-
"io/ioutil"
19+
"io"
2020
"net/http"
2121
"net/url"
2222
"strconv"
@@ -87,15 +87,6 @@ type clusterSettingsAllocation struct {
8787
Enabled string `json:"enable"`
8888
}
8989

90-
// ClusterSettings information struct
91-
type ClusterSettings struct {
92-
logger log.Logger
93-
client *http.Client
94-
url *url.URL
95-
96-
maxShardsPerNode prometheus.Gauge
97-
}
98-
9990
func (c *ClusterSettingsCollector) Update(ctx context.Context, ch chan<- prometheus.Metric) error {
10091
u := c.u.ResolveReference(&url.URL{Path: "_cluster/settings"})
10192
q := u.Query()
@@ -112,7 +103,7 @@ func (c *ClusterSettingsCollector) Update(ctx context.Context, ch chan<- prometh
112103
return err
113104
}
114105
defer resp.Body.Close()
115-
b, err := ioutil.ReadAll(resp.Body)
106+
b, err := io.ReadAll(resp.Body)
116107
if err != nil {
117108
return err
118109
}

collector/collector.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323
"sync"
2424
"time"
2525

26+
"github.com/alecthomas/kingpin/v2"
2627
"github.com/go-kit/log"
2728
"github.com/go-kit/log/level"
2829
"github.com/prometheus/client_golang/prometheus"
29-
"gopkg.in/alecthomas/kingpin.v2"
3030
)
3131

3232
const (
@@ -184,13 +184,13 @@ func execute(ctx context.Context, name string, c Collector, ch chan<- prometheus
184184

185185
if err != nil {
186186
if IsNoDataError(err) {
187-
_ = level.Debug(logger).Log("msg", "collector returned no data", "name", name, "duration_seconds", duration.Seconds(), "err", err)
187+
level.Debug(logger).Log("msg", "collector returned no data", "name", name, "duration_seconds", duration.Seconds(), "err", err)
188188
} else {
189-
_ = level.Error(logger).Log("msg", "collector failed", "name", name, "duration_seconds", duration.Seconds(), "err", err)
189+
level.Error(logger).Log("msg", "collector failed", "name", name, "duration_seconds", duration.Seconds(), "err", err)
190190
}
191191
success = 0
192192
} else {
193-
_ = level.Debug(logger).Log("msg", "collector succeeded", "name", name, "duration_seconds", duration.Seconds())
193+
level.Debug(logger).Log("msg", "collector succeeded", "name", name, "duration_seconds", duration.Seconds())
194194
success = 1
195195
}
196196
ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, duration.Seconds(), name)

collector/data_stream.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package collector
1616
import (
1717
"encoding/json"
1818
"fmt"
19-
"io/ioutil"
19+
"io"
2020
"net/http"
2121
"net/url"
2222
"path"
@@ -125,7 +125,7 @@ func (ds *DataStream) fetchAndDecodeDataStreamStats() (DataStreamStatsResponse,
125125
defer func() {
126126
err = res.Body.Close()
127127
if err != nil {
128-
_ = level.Warn(ds.logger).Log(
128+
level.Warn(ds.logger).Log(
129129
"msg", "failed to close http.Client",
130130
"err", err,
131131
)
@@ -136,7 +136,7 @@ func (ds *DataStream) fetchAndDecodeDataStreamStats() (DataStreamStatsResponse,
136136
return dsr, fmt.Errorf("HTTP Request failed with code %d", res.StatusCode)
137137
}
138138

139-
bts, err := ioutil.ReadAll(res.Body)
139+
bts, err := io.ReadAll(res.Body)
140140
if err != nil {
141141
ds.jsonParseFailures.Inc()
142142
return dsr, err
@@ -162,7 +162,7 @@ func (ds *DataStream) Collect(ch chan<- prometheus.Metric) {
162162
dataStreamStatsResp, err := ds.fetchAndDecodeDataStreamStats()
163163
if err != nil {
164164
ds.up.Set(0)
165-
_ = level.Warn(ds.logger).Log(
165+
level.Warn(ds.logger).Log(
166166
"msg", "failed to fetch and decode data stream stats",
167167
"err", err,
168168
)

collector/ilm_indices.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package collector
1616
import (
1717
"encoding/json"
1818
"fmt"
19-
"io/ioutil"
19+
"io"
2020
"net/http"
2121
"net/url"
2222
"path"
@@ -120,7 +120,7 @@ func (i *IlmIndiciesCollector) fetchAndDecodeIlm() (IlmResponse, error) {
120120
defer func() {
121121
err = res.Body.Close()
122122
if err != nil {
123-
_ = level.Warn(i.logger).Log(
123+
level.Warn(i.logger).Log(
124124
"msg", "failed to close http.Client",
125125
"err", err,
126126
)
@@ -131,7 +131,7 @@ func (i *IlmIndiciesCollector) fetchAndDecodeIlm() (IlmResponse, error) {
131131
return ir, fmt.Errorf("HTTP Request failed with code %d", res.StatusCode)
132132
}
133133

134-
bts, err := ioutil.ReadAll(res.Body)
134+
bts, err := io.ReadAll(res.Body)
135135
if err != nil {
136136
i.jsonParseFailures.Inc()
137137
return ir, err
@@ -164,7 +164,7 @@ func (i *IlmIndiciesCollector) Collect(ch chan<- prometheus.Metric) {
164164
ilmResp, err := i.fetchAndDecodeIlm()
165165
if err != nil {
166166
i.up.Set(0)
167-
_ = level.Warn(i.logger).Log(
167+
level.Warn(i.logger).Log(
168168
"msg", "failed to fetch and decode ILM stats",
169169
"err", err,
170170
)

collector/ilm_status.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package collector
1616
import (
1717
"encoding/json"
1818
"fmt"
19-
"io/ioutil"
19+
"io"
2020
"net/http"
2121
"net/url"
2222
"path"
@@ -113,15 +113,15 @@ func (im *IlmStatusCollector) fetchAndDecodeIlm() (*IlmStatusResponse, error) {
113113
return nil, fmt.Errorf("HTTP Request failed with code %d", res.StatusCode)
114114
}
115115

116-
body, err := ioutil.ReadAll(res.Body)
116+
body, err := io.ReadAll(res.Body)
117117
if err != nil {
118-
_ = level.Warn(im.logger).Log("msg", "failed to read response body", "err", err)
118+
level.Warn(im.logger).Log("msg", "failed to read response body", "err", err)
119119
return nil, err
120120
}
121121

122122
err = res.Body.Close()
123123
if err != nil {
124-
_ = level.Warn(im.logger).Log("msg", "failed to close response body", "err", err)
124+
level.Warn(im.logger).Log("msg", "failed to close response body", "err", err)
125125
return nil, err
126126
}
127127

@@ -147,7 +147,7 @@ func (im *IlmStatusCollector) Collect(ch chan<- prometheus.Metric) {
147147
indicesIlmsResponse, err := im.fetchAndDecodeIlm()
148148
if err != nil {
149149
im.up.Set(0)
150-
_ = level.Warn(im.logger).Log(
150+
level.Warn(im.logger).Log(
151151
"msg", "failed to fetch and decode cluster ilm status",
152152
"err", err,
153153
)

collector/indices.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/go-kit/log/level"
2121
"github.com/prometheus-community/elasticsearch_exporter/pkg/clusterinfo"
2222
"github.com/prometheus/client_golang/prometheus"
23-
"io/ioutil"
23+
"io"
2424
"net/http"
2525
"net/url"
2626
"path"
@@ -1065,14 +1065,14 @@ func NewIndices(logger log.Logger, client *http.Client, url *url.URL, shards boo
10651065

10661066
// start go routine to fetch clusterinfo updates and save them to lastClusterinfo
10671067
go func() {
1068-
_ = level.Debug(logger).Log("msg", "starting cluster info receive loop")
1068+
level.Debug(logger).Log("msg", "starting cluster info receive loop")
10691069
for ci := range indices.clusterInfoCh {
10701070
if ci != nil {
1071-
_ = level.Debug(logger).Log("msg", "received cluster info update", "cluster", ci.ClusterName)
1071+
level.Debug(logger).Log("msg", "received cluster info update", "cluster", ci.ClusterName)
10721072
indices.lastClusterInfo = ci
10731073
}
10741074
}
1075-
_ = level.Debug(logger).Log("msg", "exiting cluster info receive loop")
1075+
level.Debug(logger).Log("msg", "exiting cluster info receive loop")
10761076
}()
10771077
return indices
10781078
}
@@ -1123,7 +1123,7 @@ func (i *Indices) fetchAndDecodeIndexStats() (indexStatsResponse, error) {
11231123
isr.Aliases = map[string][]string{}
11241124
asr, err := i.fetchAndDecodeAliases()
11251125
if err != nil {
1126-
_ = level.Error(i.logger).Log("err", err.Error())
1126+
level.Error(i.logger).Log("err", err.Error())
11271127
return isr, err
11281128
}
11291129

@@ -1172,7 +1172,7 @@ func (i *Indices) queryURL(u *url.URL) ([]byte, error) {
11721172
defer func() {
11731173
err = res.Body.Close()
11741174
if err != nil {
1175-
_ = level.Warn(i.logger).Log(
1175+
level.Warn(i.logger).Log(
11761176
"msg", "failed to close http.Client",
11771177
"err", err,
11781178
)
@@ -1183,7 +1183,7 @@ func (i *Indices) queryURL(u *url.URL) ([]byte, error) {
11831183
return []byte{}, fmt.Errorf("HTTP Request failed with code %d", res.StatusCode)
11841184
}
11851185

1186-
bts, err := ioutil.ReadAll(res.Body)
1186+
bts, err := io.ReadAll(res.Body)
11871187
if err != nil {
11881188
return []byte{}, err
11891189
}
@@ -1204,7 +1204,7 @@ func (i *Indices) Collect(ch chan<- prometheus.Metric) {
12041204
indexStatsResp, err := i.fetchAndDecodeIndexStats()
12051205
if err != nil {
12061206
i.up.Set(0)
1207-
_ = level.Warn(i.logger).Log(
1207+
level.Warn(i.logger).Log(
12081208
"msg", "failed to fetch and decode index stats",
12091209
"err", err,
12101210
)

0 commit comments

Comments
 (0)