Skip to content

Commit 6ba7871

Browse files
committed
Merge branch 'main' into sparsehistogram
2 parents eb59a7b + 2cfd1eb commit 6ba7871

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+242
-221
lines changed

.circleci/config.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ workflows:
4646
client_golang:
4747
jobs:
4848
# Refer to README.md for the currently supported versions.
49-
- test:
50-
name: go-1-16
51-
go_version: "1.16"
52-
run_lint: true
5349
- test:
5450
name: go-1-17
5551
go_version: "1.17"

.github/settings.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
branches:
3+
- name: main
4+
protection:
5+
# Required. Require at least one approving review on a pull request, before merging. Set to null to disable.
6+
required_pull_request_reviews:
7+
# The number of approvals required. (1-6)
8+
required_approving_review_count: 1
9+
# Dismiss approved reviews automatically when a new commit is pushed.
10+
dismiss_stale_reviews: false
11+
# Blocks merge until code owners have reviewed.
12+
require_code_owner_reviews: false
13+
# Specify which users and teams can dismiss pull request reviews. Pass an empty dismissal_restrictions object to disable. User and team dismissal_restrictions are only available for organization-owned repositories. Omit this parameter for personal repositories.
14+
dismissal_restrictions:
15+
users: []
16+
teams: []
17+
# Required. Require status checks to pass before merging. Set to null to disable
18+
required_status_checks:
19+
# Required. Require branches to be up to date before merging.
20+
strict: false
21+
# Required. The list of status checks to require in order to merge into this branch
22+
contexts:
23+
- DCO
24+
- "ci/circleci: go-1-17"
25+
- "ci/circleci: go-1-18"
26+
# Required. Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable.
27+
enforce_admins: false
28+
# Prevent merge commits from being pushed to matching branches
29+
required_linear_history: false
30+
# Required. Restrict who can push to this branch. Team and user restrictions are only available for organization-owned repositories. Set to null to disable.
31+
restrictions:
32+
apps: []
33+
users: []
34+
teams: []

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: golangci-lint
23
on:
34
push:
@@ -25,6 +26,6 @@ jobs:
2526
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
2627
if: github.repository == 'prometheus/snmp_exporter'
2728
- name: Lint
28-
uses: golangci/golangci-lint-action@v3.1.0
29+
uses: golangci/golangci-lint-action@v3.2.0
2930
with:
3031
version: v1.45.2

.golangci.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
1-
# Run only staticcheck for now. Additional linters will be enabled one-by-one.
1+
---
2+
3+
run:
4+
deadline: 5m
5+
6+
output:
7+
sort-results: true
8+
29
linters:
310
enable:
4-
- staticcheck
5-
disable-all: true
11+
- gofumpt
12+
- goimports
13+
- revive
14+
- misspell
15+
16+
issues:
17+
max-same-issues: 0
18+
exclude-rules:
19+
- path: _test.go
20+
linters:
21+
- errcheck
22+
- govet
23+
- structcheck
24+
25+
linters-settings:
26+
errcheck:
27+
exclude: scripts/errcheck_excludes.txt
28+
goimports:
29+
local-prefixes: github.com/prometheus/client_golang
30+
gofumpt:
31+
extra-rules: true

Makefile.common

Lines changed: 11 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,6 @@ GO_VERSION ?= $(shell $(GO) version)
3636
GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
3737
PRE_GO_111 ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.')
3838

39-
GOVENDOR :=
40-
GO111MODULE :=
41-
ifeq (, $(PRE_GO_111))
42-
ifneq (,$(wildcard go.mod))
43-
# Enforce Go modules support just in case the directory is inside GOPATH (and for Travis CI).
44-
GO111MODULE := on
45-
46-
ifneq (,$(wildcard vendor))
47-
# Always use the local vendor/ directory to satisfy the dependencies.
48-
GOOPTS := $(GOOPTS) -mod=vendor
49-
endif
50-
endif
51-
else
52-
ifneq (,$(wildcard go.mod))
53-
ifneq (,$(wildcard vendor))
54-
$(warning This repository requires Go >= 1.11 because of Go modules)
55-
$(warning Some recipes may not work as expected as the current Go runtime is '$(GO_VERSION_NUMBER)')
56-
endif
57-
else
58-
# This repository isn't using Go modules (yet).
59-
GOVENDOR := $(FIRST_GOPATH)/bin/govendor
60-
endif
61-
endif
6239
PROMU := $(FIRST_GOPATH)/bin/promu
6340
pkgs = ./...
6441

@@ -150,58 +127,47 @@ common-check_license:
150127
.PHONY: common-deps
151128
common-deps:
152129
@echo ">> getting dependencies"
153-
ifdef GO111MODULE
154-
GO111MODULE=$(GO111MODULE) $(GO) mod download
155-
else
156-
$(GO) get $(GOOPTS) -t ./...
157-
endif
130+
$(GO) mod download
158131

159132
.PHONY: update-go-deps
160133
update-go-deps:
161134
@echo ">> updating Go dependencies"
162135
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
163136
$(GO) get -d $$m; \
164137
done
165-
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
166-
ifneq (,$(wildcard vendor))
167-
GO111MODULE=$(GO111MODULE) $(GO) mod vendor
168-
endif
138+
$(GO) mod tidy
169139

170140
.PHONY: common-test-short
171141
common-test-short: $(GOTEST_DIR)
172142
@echo ">> running short tests"
173-
GO111MODULE=$(GO111MODULE) $(GOTEST) -short $(GOOPTS) $(pkgs)
143+
$(GOTEST) -short $(GOOPTS) $(pkgs)
174144

175145
.PHONY: common-test
176146
common-test: $(GOTEST_DIR)
177147
@echo ">> running all tests"
178-
GO111MODULE=$(GO111MODULE) $(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
148+
$(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
179149

180150
$(GOTEST_DIR):
181151
@mkdir -p $@
182152

183153
.PHONY: common-format
184154
common-format:
185155
@echo ">> formatting code"
186-
GO111MODULE=$(GO111MODULE) $(GO) fmt $(pkgs)
156+
$(GO) fmt $(pkgs)
187157

188158
.PHONY: common-vet
189159
common-vet:
190160
@echo ">> vetting code"
191-
GO111MODULE=$(GO111MODULE) $(GO) vet $(GOOPTS) $(pkgs)
161+
$(GO) vet $(GOOPTS) $(pkgs)
192162

193163
.PHONY: common-lint
194164
common-lint: $(GOLANGCI_LINT)
195165
ifdef GOLANGCI_LINT
196166
@echo ">> running golangci-lint"
197-
ifdef GO111MODULE
198167
# 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
199168
# Otherwise staticcheck might fail randomly for some reason not yet explained.
200-
GO111MODULE=$(GO111MODULE) $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
201-
GO111MODULE=$(GO111MODULE) $(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
202-
else
203-
$(GOLANGCI_LINT) run $(pkgs)
204-
endif
169+
$(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
170+
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
205171
endif
206172

207173
.PHONY: common-yamllint
@@ -218,28 +184,15 @@ endif
218184
common-staticcheck: lint
219185

220186
.PHONY: common-unused
221-
common-unused: $(GOVENDOR)
222-
ifdef GOVENDOR
223-
@echo ">> running check for unused packages"
224-
@$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
225-
else
226-
ifdef GO111MODULE
187+
common-unused:
227188
@echo ">> running check for unused/missing packages in go.mod"
228-
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
229-
ifeq (,$(wildcard vendor))
189+
$(GO) mod tidy
230190
@git diff --exit-code -- go.sum go.mod
231-
else
232-
@echo ">> running check for unused packages in vendor/"
233-
GO111MODULE=$(GO111MODULE) $(GO) mod vendor
234-
@git diff --exit-code -- go.sum go.mod vendor/
235-
endif
236-
endif
237-
endif
238191

239192
.PHONY: common-build
240193
common-build: promu
241194
@echo ">> building binaries"
242-
GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
195+
$(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
243196

244197
.PHONY: common-tarball
245198
common-tarball: promu
@@ -295,12 +248,6 @@ $(GOLANGCI_LINT):
295248
| sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
296249
endif
297250

298-
ifdef GOVENDOR
299-
.PHONY: $(GOVENDOR)
300-
$(GOVENDOR):
301-
GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor
302-
endif
303-
304251
.PHONY: precheck
305252
precheck::
306253

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This is the [Go](http://golang.org) client library for
1010
instrumenting application code, and one for creating clients that talk to the
1111
Prometheus HTTP API.
1212

13-
__This library requires Go1.16 or later.__
13+
__This library requires Go1.17 or later.__
1414

1515
## Important note about releases and stability
1616

api/client_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ func BenchmarkClient(b *testing.B) {
134134

135135
for _, sizeKB := range []int{4, 50, 1000, 2000} {
136136
b.Run(fmt.Sprintf("%dKB", sizeKB), func(b *testing.B) {
137-
138137
testServer := httptest.NewServer(serveSpaces{sizeKB})
139138
defer testServer.Close()
140139

api/prometheus/v1/api.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ func marshalPointJSON(ptr unsafe.Pointer, stream *json.Stream) {
109109

110110
stream.WriteRaw(`"`)
111111
stream.WriteArrayEnd()
112-
113112
}
114113

115114
func marshalPointJSONIsEmpty(ptr unsafe.Pointer) bool {
@@ -230,25 +229,25 @@ type API interface {
230229
// Config returns the current Prometheus configuration.
231230
Config(ctx context.Context) (ConfigResult, error)
232231
// DeleteSeries deletes data for a selection of series in a time range.
233-
DeleteSeries(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) error
232+
DeleteSeries(ctx context.Context, matches []string, startTime, endTime time.Time) error
234233
// Flags returns the flag values that Prometheus was launched with.
235234
Flags(ctx context.Context) (FlagsResult, error)
236235
// LabelNames returns the unique label names present in the block in sorted order by given time range and matchers.
237-
LabelNames(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]string, Warnings, error)
236+
LabelNames(ctx context.Context, matches []string, startTime, endTime time.Time) ([]string, Warnings, error)
238237
// LabelValues performs a query for the values of the given label, time range and matchers.
239-
LabelValues(ctx context.Context, label string, matches []string, startTime time.Time, endTime time.Time) (model.LabelValues, Warnings, error)
238+
LabelValues(ctx context.Context, label string, matches []string, startTime, endTime time.Time) (model.LabelValues, Warnings, error)
240239
// Query performs a query for the given time.
241240
Query(ctx context.Context, query string, ts time.Time, opts ...Option) (model.Value, Warnings, error)
242241
// QueryRange performs a query for the given range.
243242
QueryRange(ctx context.Context, query string, r Range, opts ...Option) (model.Value, Warnings, error)
244243
// QueryExemplars performs a query for exemplars by the given query and time range.
245-
QueryExemplars(ctx context.Context, query string, startTime time.Time, endTime time.Time) ([]ExemplarQueryResult, error)
244+
QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]ExemplarQueryResult, error)
246245
// Buildinfo returns various build information properties about the Prometheus server
247246
Buildinfo(ctx context.Context) (BuildinfoResult, error)
248247
// Runtimeinfo returns the various runtime information properties about the Prometheus server.
249248
Runtimeinfo(ctx context.Context) (RuntimeinfoResult, error)
250249
// Series finds series by label matchers.
251-
Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, Warnings, error)
250+
Series(ctx context.Context, matches []string, startTime, endTime time.Time) ([]model.LabelSet, Warnings, error)
252251
// Snapshot creates a snapshot of all current data into snapshots/<datetime>-<rand>
253252
// under the TSDB's data directory and returns the directory as response.
254253
Snapshot(ctx context.Context, skipHead bool) (SnapshotResult, error)
@@ -257,9 +256,9 @@ type API interface {
257256
// Targets returns an overview of the current state of the Prometheus target discovery.
258257
Targets(ctx context.Context) (TargetsResult, error)
259258
// TargetsMetadata returns metadata about metrics currently scraped by the target.
260-
TargetsMetadata(ctx context.Context, matchTarget string, metric string, limit string) ([]MetricMetadata, error)
259+
TargetsMetadata(ctx context.Context, matchTarget, metric, limit string) ([]MetricMetadata, error)
261260
// Metadata returns metadata about metrics currently scraped by the metric name.
262-
Metadata(ctx context.Context, metric string, limit string) (map[string][]Metadata, error)
261+
Metadata(ctx context.Context, metric, limit string) (map[string][]Metadata, error)
263262
// TSDB returns the cardinality statistics.
264263
TSDB(ctx context.Context) (TSDBResult, error)
265264
// WalReplay returns the current replay status of the wal.
@@ -699,7 +698,7 @@ func (h *httpAPI) Config(ctx context.Context) (ConfigResult, error) {
699698
return res, json.Unmarshal(body, &res)
700699
}
701700

702-
func (h *httpAPI) DeleteSeries(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) error {
701+
func (h *httpAPI) DeleteSeries(ctx context.Context, matches []string, startTime, endTime time.Time) error {
703702
u := h.client.URL(epDeleteSeries, nil)
704703
q := u.Query()
705704

@@ -772,7 +771,7 @@ func (h *httpAPI) Runtimeinfo(ctx context.Context) (RuntimeinfoResult, error) {
772771
return res, json.Unmarshal(body, &res)
773772
}
774773

775-
func (h *httpAPI) LabelNames(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]string, Warnings, error) {
774+
func (h *httpAPI) LabelNames(ctx context.Context, matches []string, startTime, endTime time.Time) ([]string, Warnings, error) {
776775
u := h.client.URL(epLabels, nil)
777776
q := u.Query()
778777
q.Set("start", formatTime(startTime))
@@ -795,7 +794,7 @@ func (h *httpAPI) LabelNames(ctx context.Context, matches []string, startTime ti
795794
return labelNames, w, json.Unmarshal(body, &labelNames)
796795
}
797796

798-
func (h *httpAPI) LabelValues(ctx context.Context, label string, matches []string, startTime time.Time, endTime time.Time) (model.LabelValues, Warnings, error) {
797+
func (h *httpAPI) LabelValues(ctx context.Context, label string, matches []string, startTime, endTime time.Time) (model.LabelValues, Warnings, error) {
799798
u := h.client.URL(epLabelValues, map[string]string{"name": label})
800799
q := u.Query()
801800
q.Set("start", formatTime(startTime))
@@ -833,7 +832,6 @@ func WithTimeout(timeout time.Duration) Option {
833832
}
834833

835834
func (h *httpAPI) Query(ctx context.Context, query string, ts time.Time, opts ...Option) (model.Value, Warnings, error) {
836-
837835
u := h.client.URL(epQuery, nil)
838836
q := u.Query()
839837

@@ -890,7 +888,7 @@ func (h *httpAPI) QueryRange(ctx context.Context, query string, r Range, opts ..
890888
return model.Value(qres.v), warnings, json.Unmarshal(body, &qres)
891889
}
892890

893-
func (h *httpAPI) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, Warnings, error) {
891+
func (h *httpAPI) Series(ctx context.Context, matches []string, startTime, endTime time.Time) ([]model.LabelSet, Warnings, error) {
894892
u := h.client.URL(epSeries, nil)
895893
q := u.Query()
896894

@@ -973,7 +971,7 @@ func (h *httpAPI) Targets(ctx context.Context) (TargetsResult, error) {
973971
return res, json.Unmarshal(body, &res)
974972
}
975973

976-
func (h *httpAPI) TargetsMetadata(ctx context.Context, matchTarget string, metric string, limit string) ([]MetricMetadata, error) {
974+
func (h *httpAPI) TargetsMetadata(ctx context.Context, matchTarget, metric, limit string) ([]MetricMetadata, error) {
977975
u := h.client.URL(epTargetsMetadata, nil)
978976
q := u.Query()
979977

@@ -997,7 +995,7 @@ func (h *httpAPI) TargetsMetadata(ctx context.Context, matchTarget string, metri
997995
return res, json.Unmarshal(body, &res)
998996
}
999997

1000-
func (h *httpAPI) Metadata(ctx context.Context, metric string, limit string) (map[string][]Metadata, error) {
998+
func (h *httpAPI) Metadata(ctx context.Context, metric, limit string) (map[string][]Metadata, error) {
1001999
u := h.client.URL(epMetadata, nil)
10021000
q := u.Query()
10031001

@@ -1054,7 +1052,7 @@ func (h *httpAPI) WalReplay(ctx context.Context) (WalReplayStatus, error) {
10541052
return res, json.Unmarshal(body, &res)
10551053
}
10561054

1057-
func (h *httpAPI) QueryExemplars(ctx context.Context, query string, startTime time.Time, endTime time.Time) ([]ExemplarQueryResult, error) {
1055+
func (h *httpAPI) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]ExemplarQueryResult, error) {
10581056
u := h.client.URL(epQueryExemplars, nil)
10591057
q := u.Query()
10601058

@@ -1162,7 +1160,6 @@ func (h *apiClientImpl) Do(ctx context.Context, req *http.Request) (*http.Respon
11621160
}
11631161

11641162
return resp, []byte(result.Data), result.Warnings, err
1165-
11661163
}
11671164

11681165
// DoGetFallback will attempt to do the request as-is, and on a 405 or 501 it

0 commit comments

Comments
 (0)