Skip to content

Commit 7ae0283

Browse files
committed
Merge tag 'v0.8.0' into master
2 parents cae5396 + 344b47c commit 7ae0283

File tree

163 files changed

+8241
-1802
lines changed

Some content is hidden

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

163 files changed

+8241
-1802
lines changed

.circleci/config.yml

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
---
22
version: 2.1
33

4-
commands:
5-
default:
6-
steps:
7-
- run: make style check_license test lint
8-
no-test:
4+
jobs:
5+
lint:
6+
docker:
7+
- image: cimg/go:1.18
98
steps:
10-
- run: make style check_license lint
9+
- checkout
10+
- run: make check_license
11+
- run: ./scripts/check_build_tags.sh
12+
- run: make fixtures
13+
- run: make update_fixtures
14+
- run: git diff --exit-code
1115

12-
jobs:
1316
test:
1417
parameters:
15-
command:
16-
type: string
1718
go_version:
1819
type: string
1920
os:
2021
type: string
22+
run_test:
23+
type: boolean
24+
default: true
2125
docker:
22-
- image: circleci/golang:<< parameters.go_version >>
26+
- image: cimg/go:<< parameters.go_version >>
2327
environment:
2428
GOOS: "<< parameters.os >>"
25-
working_directory: /go/src/github.com/prometheus/procfs
2629
steps:
2730
- checkout
28-
- << parameters.command >>
31+
- run: make style lint
32+
- when:
33+
condition: << parameters.run_test >>
34+
steps:
35+
- run: make test
2936

3037
codespell:
3138
docker:
@@ -34,30 +41,28 @@ jobs:
3441
steps:
3542
- checkout
3643
- run: sudo pip install codespell
37-
- run: codespell --skip=".git,./vendor,ttar,fixtures.ttar,./fixtures,go.mod,go.sum" -L uint,packages\',ded,alo,als,te,sie,hart
44+
- run: codespell --skip=".git,./vendor,ttar,fixtures.ttar,./fixtures,go.mod,go.sum" -L uint,packages\',ded,alo,als,te,sie,hart,hda
3845

3946
workflows:
4047
version: 2
4148
procfs:
4249
jobs:
50+
- lint
4351
- test:
44-
command: default
45-
name: linux-1-13
46-
os: linux
47-
go_version: "1.13"
48-
- test:
49-
command: default
50-
name: linux-1-14
52+
name: test-linux
5153
os: linux
52-
go_version: "1.14"
53-
- test:
54-
command: no-test
55-
name: windows-1-13
56-
os: windows
57-
go_version: "1.13"
54+
matrix:
55+
parameters:
56+
go_version:
57+
- "1.17"
58+
- "1.18"
5859
- test:
59-
command: no-test
60-
name: windows-1-14
60+
name: test-windows
6161
os: windows
62-
go_version: "1.14"
62+
run_test: false
63+
matrix:
64+
parameters:
65+
go_version:
66+
- "1.17"
67+
- "1.18"
6368
- codespell

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
paths:
5+
- "go.sum"
6+
- "go.mod"
7+
- "**.go"
8+
- "scripts/errcheck_excludes.txt"
9+
- ".github/workflows/golangci-lint.yml"
10+
- ".golangci.yml"
11+
pull_request:
12+
13+
jobs:
14+
golangci:
15+
name: lint
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v3
20+
- name: install Go
21+
uses: actions/setup-go@v2
22+
with:
23+
go-version: 1.18.x
24+
- name: Install snmp_exporter/generator dependencies
25+
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
26+
if: github.repository == 'prometheus/snmp_exporter'
27+
- name: Lint
28+
uses: golangci/golangci-lint-action@v3.2.0
29+
with:
30+
version: v1.45.2

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/fixtures/
1+
/testdata/fixtures/
2+
/fixtures

.golangci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
---
22
linters:
33
enable:
4-
- golint
4+
- godot
5+
- revive
6+
7+
linter-settings:
8+
godot:
9+
capital: true
10+
exclude:
11+
# Ignore "See: URL"
12+
- 'See:'

CODE_OF_CONDUCT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## Prometheus Community Code of Conduct
1+
# Prometheus Community Code of Conduct
22

3-
Prometheus follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
3+
Prometheus follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md).

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Many of the files are changing continuously and the data being read can in some
9797
reads in the same file. Also, most of the files are relatively small (less than a few KBs), and system calls
9898
to the `stat` function will often return the wrong size. Therefore, for most files it's recommended to read the
9999
full file in a single operation using an internal utility function called `util.ReadFileNoStat`.
100-
This function is similar to `ioutil.ReadFile`, but it avoids the system call to `stat` to get the current size of
100+
This function is similar to `os.ReadFile`, but it avoids the system call to `stat` to get the current size of
101101
the file.
102102

103103
Note that parsing the file's contents can still be performed one line at a time. This is done by first reading
@@ -113,7 +113,7 @@ the full file, and then using a scanner on the `[]byte` or `string` containing t
113113
```
114114

115115
The `/sys` filesystem contains many very small files which contain only a single numeric or text value. These files
116-
can be read using an internal function called `util.SysReadFile` which is similar to `ioutil.ReadFile` but does
116+
can be read using an internal function called `util.SysReadFile` which is similar to `os.ReadFile` but does
117117
not bother to check the size of the file before reading.
118118
```
119119
data, err := util.SysReadFile("/sys/class/power_supply/BAT0/capacity")

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414
include Makefile.common
1515

1616
%/.unpacked: %.ttar
17-
@echo ">> extracting fixtures"
17+
@echo ">> extracting fixtures $*"
1818
./ttar -C $(dir $*) -x -f $*.ttar
1919
touch $@
2020

21+
fixtures: testdata/fixtures/.unpacked
22+
2123
update_fixtures:
22-
rm -vf fixtures/.unpacked
23-
./ttar -c -f fixtures.ttar fixtures/
24+
rm -vf testdata/fixtures/.unpacked
25+
./ttar -c -f testdata/fixtures.ttar -C testdata/ fixtures/
2426

2527
.PHONY: build
2628
build:
2729

2830
.PHONY: test
29-
test: fixtures/.unpacked common-test
31+
test: testdata/fixtures/.unpacked common-test

Makefile.common

Lines changed: 32 additions & 68 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

@@ -78,17 +55,23 @@ ifneq ($(shell which gotestsum),)
7855
endif
7956
endif
8057

81-
PROMU_VERSION ?= 0.5.0
58+
PROMU_VERSION ?= 0.13.0
8259
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
8360

8461
GOLANGCI_LINT :=
8562
GOLANGCI_LINT_OPTS ?=
86-
GOLANGCI_LINT_VERSION ?= v1.18.0
63+
GOLANGCI_LINT_VERSION ?= v1.45.2
8764
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
8865
# windows isn't included here because of the path separator being different.
8966
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
9067
ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386))
91-
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
68+
# If we're in CI and there is an Actions file, that means the linter
69+
# is being run in Actions, so we don't need to run it here.
70+
ifeq (,$(CIRCLE_JOB))
71+
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
72+
else ifeq (,$(wildcard .github/workflows/golangci-lint.yml))
73+
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
74+
endif
9275
endif
9376
endif
9477

@@ -118,7 +101,7 @@ endif
118101
%: common-% ;
119102

120103
.PHONY: common-all
121-
common-all: precheck style check_license lint unused build test
104+
common-all: precheck style check_license lint yamllint unused build test
122105

123106
.PHONY: common-style
124107
common-style:
@@ -144,87 +127,72 @@ common-check_license:
144127
.PHONY: common-deps
145128
common-deps:
146129
@echo ">> getting dependencies"
147-
ifdef GO111MODULE
148-
GO111MODULE=$(GO111MODULE) $(GO) mod download
149-
else
150-
$(GO) get $(GOOPTS) -t ./...
151-
endif
130+
$(GO) mod download
152131

153132
.PHONY: update-go-deps
154133
update-go-deps:
155134
@echo ">> updating Go dependencies"
156135
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
157-
$(GO) get $$m; \
136+
$(GO) get -d $$m; \
158137
done
159-
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
160-
ifneq (,$(wildcard vendor))
161-
GO111MODULE=$(GO111MODULE) $(GO) mod vendor
162-
endif
138+
$(GO) mod tidy
163139

164140
.PHONY: common-test-short
165141
common-test-short: $(GOTEST_DIR)
166142
@echo ">> running short tests"
167-
GO111MODULE=$(GO111MODULE) $(GOTEST) -short $(GOOPTS) $(pkgs)
143+
$(GOTEST) -short $(GOOPTS) $(pkgs)
168144

169145
.PHONY: common-test
170146
common-test: $(GOTEST_DIR)
171147
@echo ">> running all tests"
172-
GO111MODULE=$(GO111MODULE) $(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
148+
$(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
173149

174150
$(GOTEST_DIR):
175151
@mkdir -p $@
176152

177153
.PHONY: common-format
178154
common-format:
179155
@echo ">> formatting code"
180-
GO111MODULE=$(GO111MODULE) $(GO) fmt $(pkgs)
156+
$(GO) fmt $(pkgs)
181157

182158
.PHONY: common-vet
183159
common-vet:
184160
@echo ">> vetting code"
185-
GO111MODULE=$(GO111MODULE) $(GO) vet $(GOOPTS) $(pkgs)
161+
$(GO) vet $(GOOPTS) $(pkgs)
186162

187163
.PHONY: common-lint
188164
common-lint: $(GOLANGCI_LINT)
189165
ifdef GOLANGCI_LINT
190166
@echo ">> running golangci-lint"
191-
ifdef GO111MODULE
192167
# 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
193168
# Otherwise staticcheck might fail randomly for some reason not yet explained.
194-
GO111MODULE=$(GO111MODULE) $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
195-
GO111MODULE=$(GO111MODULE) $(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
196-
else
197-
$(GOLANGCI_LINT) run $(pkgs)
169+
$(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
170+
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
198171
endif
172+
173+
.PHONY: common-yamllint
174+
common-yamllint:
175+
@echo ">> running yamllint on all YAML files in the repository"
176+
ifeq (, $(shell which yamllint))
177+
@echo "yamllint not installed so skipping"
178+
else
179+
yamllint .
199180
endif
200181

201182
# For backward-compatibility.
202183
.PHONY: common-staticcheck
203184
common-staticcheck: lint
204185

205186
.PHONY: common-unused
206-
common-unused: $(GOVENDOR)
207-
ifdef GOVENDOR
208-
@echo ">> running check for unused packages"
209-
@$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
210-
else
211-
ifdef GO111MODULE
187+
common-unused:
212188
@echo ">> running check for unused/missing packages in go.mod"
213-
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
214-
ifeq (,$(wildcard vendor))
189+
$(GO) mod tidy
215190
@git diff --exit-code -- go.sum go.mod
216-
else
217-
@echo ">> running check for unused packages in vendor/"
218-
GO111MODULE=$(GO111MODULE) $(GO) mod vendor
219-
@git diff --exit-code -- go.sum go.mod vendor/
220-
endif
221-
endif
222-
endif
223191

224192
.PHONY: common-build
225193
common-build: promu
226194
@echo ">> building binaries"
227-
GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
195+
$(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
228196

229197
.PHONY: common-tarball
230198
common-tarball: promu
@@ -245,10 +213,12 @@ common-docker-publish: $(PUBLISH_DOCKER_ARCHS)
245213
$(PUBLISH_DOCKER_ARCHS): common-docker-publish-%:
246214
docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)"
247215

216+
DOCKER_MAJOR_VERSION_TAG = $(firstword $(subst ., ,$(shell cat VERSION)))
248217
.PHONY: common-docker-tag-latest $(TAG_DOCKER_ARCHS)
249218
common-docker-tag-latest: $(TAG_DOCKER_ARCHS)
250219
$(TAG_DOCKER_ARCHS): common-docker-tag-latest-%:
251220
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:latest"
221+
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)"
252222

253223
.PHONY: common-docker-manifest
254224
common-docker-manifest:
@@ -278,12 +248,6 @@ $(GOLANGCI_LINT):
278248
| sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
279249
endif
280250

281-
ifdef GOVENDOR
282-
.PHONY: $(GOVENDOR)
283-
$(GOVENDOR):
284-
GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor
285-
endif
286-
287251
.PHONY: precheck
288252
precheck::
289253

0 commit comments

Comments
 (0)