Skip to content

Commit b67b69a

Browse files
committed
Update for Prometheus Community
Add standard Prometheus build setup * CircleCI config * Makefile * Go modules * Golang-CI Lint * promu config * Remove /vendor * Remove mage build * Update READMEs prometheus-community#478 Signed-off-by: Ben Kochie <[email protected]>
1 parent 8531aba commit b67b69a

File tree

1,455 files changed

+684
-529255
lines changed

Some content is hidden

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

1,455 files changed

+684
-529255
lines changed

Diff for: .circleci/config.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
version: 2.1
3+
4+
orbs:
5+
prometheus: prometheus/[email protected]
6+
7+
executors:
8+
# This must match .promu.yml.
9+
golang:
10+
docker:
11+
- image: circleci/golang:1.15
12+
13+
jobs:
14+
test:
15+
executor: golang
16+
17+
steps:
18+
- prometheus/setup_environment
19+
- run: make
20+
- prometheus/store_artifact:
21+
file: postgres_exporter
22+
23+
workflows:
24+
version: 2
25+
postgres_exporter:
26+
jobs:
27+
- test:
28+
filters:
29+
tags:
30+
only: /.*/
31+
- prometheus/build:
32+
name: build
33+
filters:
34+
tags:
35+
only: /.*/
36+
- prometheus/publish_master:
37+
context: org-context
38+
docker_hub_organization: prometheuscommunity
39+
quay_io_organization: prometheuscommunity
40+
requires:
41+
- test
42+
- build
43+
filters:
44+
branches:
45+
only: master
46+
- prometheus/publish_release:
47+
context: org-context
48+
docker_hub_organization: prometheuscommunity
49+
quay_io_organization: prometheuscommunity
50+
requires:
51+
- test
52+
- build
53+
filters:
54+
tags:
55+
only: /^v.*/
56+
branches:
57+
ignore: /.*/

Diff for: .dockerignore

-2
This file was deleted.

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
/.metrics.*.added
2020
/.metrics.*.removed
2121
/tools/src
22+
/vendor

Diff for: .golangci.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
issues:
3+
exclude-rules:
4+
- path: _test.go
5+
linters:
6+
- errcheck
7+
8+
linters-settings:
9+
errcheck:
10+
exclude: scripts/errcheck_excludes.txt

Diff for: .promu.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
go:
2+
# This must match .circle/config.yml.
3+
version: 1.15
4+
repository:
5+
path: github.com/prometheus-community/postgres_exporter
6+
build:
7+
binaries:
8+
- name: postgres_exporter
9+
path: ./cmd/postgres_exporter
10+
flags: -a -tags 'netgo static_build'
11+
ldflags: |
12+
-X github.com/prometheus/common/version.Version={{.Version}}
13+
-X github.com/prometheus/common/version.Revision={{.Revision}}
14+
-X github.com/prometheus/common/version.Branch={{.Branch}}
15+
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
16+
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
17+
tarball:
18+
files:
19+
- LICENSE

Diff for: .travis.yml

-46
This file was deleted.

Diff for: Dockerfile

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM debian:10-slim
2-
RUN useradd -u 20001 postgres_exporter
3-
4-
USER postgres_exporter
5-
6-
ARG binary
7-
8-
COPY $binary /postgres_exporter
9-
10-
EXPOSE 9187
11-
12-
ENTRYPOINT [ "/postgres_exporter" ]
1+
ARG ARCH="amd64"
2+
ARG OS="linux"
3+
FROM quay.io/prometheus/busybox-${OS}-${ARCH}:latest
4+
LABEL maintainer="The Prometheus Authors <[email protected]>"
5+
6+
ARG ARCH="amd64"
7+
ARG OS="linux"
8+
COPY .build/${OS}-${ARCH}/postgres_exporter /bin/postgres_exporter
9+
10+
EXPOSE 9187
11+
USER nobody
12+
ENTRYPOINT [ "/bin/postgres_exporter" ]

Diff for: Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Ensure that 'all' is the default target otherwise it will be the first target from Makefile.common.
2+
all::
3+
4+
# Needs to be defined before including Makefile.common to auto-generate targets
5+
DOCKER_ARCHS ?= amd64 armv7 arm64 ppc64le
6+
DOCKER_REPO ?= prometheuscommunity
7+
8+
include Makefile.common
9+
10+
DOCKER_IMAGE_NAME ?= postgres-exporter

Diff for: vendor/github.com/prometheus/procfs/Makefile.common renamed to Makefile.common

+39-9
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,21 @@ else
6969
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)
7070
endif
7171

72-
PROMU_VERSION ?= 0.4.0
72+
GOTEST := $(GO) test
73+
GOTEST_DIR :=
74+
ifneq ($(CIRCLE_JOB),)
75+
ifneq ($(shell which gotestsum),)
76+
GOTEST_DIR := test-results
77+
GOTEST := gotestsum --junitfile $(GOTEST_DIR)/unit-tests.xml --
78+
endif
79+
endif
80+
81+
PROMU_VERSION ?= 0.7.0
7382
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
7483

7584
GOLANGCI_LINT :=
7685
GOLANGCI_LINT_OPTS ?=
77-
GOLANGCI_LINT_VERSION ?= v1.16.0
86+
GOLANGCI_LINT_VERSION ?= v1.36.0
7887
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
7988
# windows isn't included here because of the path separator being different.
8089
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
@@ -86,6 +95,8 @@ endif
8695
PREFIX ?= $(shell pwd)
8796
BIN_DIR ?= $(shell pwd)
8897
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
98+
DOCKERFILE_PATH ?= ./Dockerfile
99+
DOCKERBUILD_CONTEXT ?= ./
89100
DOCKER_REPO ?= prom
90101

91102
DOCKER_ARCHS ?= amd64
@@ -139,15 +150,29 @@ else
139150
$(GO) get $(GOOPTS) -t ./...
140151
endif
141152

153+
.PHONY: update-go-deps
154+
update-go-deps:
155+
@echo ">> updating Go dependencies"
156+
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
157+
$(GO) get $$m; \
158+
done
159+
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
160+
ifneq (,$(wildcard vendor))
161+
GO111MODULE=$(GO111MODULE) $(GO) mod vendor
162+
endif
163+
142164
.PHONY: common-test-short
143-
common-test-short:
165+
common-test-short: $(GOTEST_DIR)
144166
@echo ">> running short tests"
145-
GO111MODULE=$(GO111MODULE) $(GO) test -short $(GOOPTS) $(pkgs)
167+
GO111MODULE=$(GO111MODULE) $(GOTEST) -short $(GOOPTS) $(pkgs)
146168

147169
.PHONY: common-test
148-
common-test:
170+
common-test: $(GOTEST_DIR)
149171
@echo ">> running all tests"
150-
GO111MODULE=$(GO111MODULE) $(GO) test $(test-flags) $(GOOPTS) $(pkgs)
172+
GO111MODULE=$(GO111MODULE) $(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
173+
174+
$(GOTEST_DIR):
175+
@mkdir -p $@
151176

152177
.PHONY: common-format
153178
common-format:
@@ -199,7 +224,7 @@ endif
199224
.PHONY: common-build
200225
common-build: promu
201226
@echo ">> building binaries"
202-
GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX)
227+
GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
203228

204229
.PHONY: common-tarball
205230
common-tarball: promu
@@ -210,19 +235,22 @@ common-tarball: promu
210235
common-docker: $(BUILD_DOCKER_ARCHS)
211236
$(BUILD_DOCKER_ARCHS): common-docker-%:
212237
docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" \
238+
-f $(DOCKERFILE_PATH) \
213239
--build-arg ARCH="$*" \
214240
--build-arg OS="linux" \
215-
.
241+
$(DOCKERBUILD_CONTEXT)
216242

217243
.PHONY: common-docker-publish $(PUBLISH_DOCKER_ARCHS)
218244
common-docker-publish: $(PUBLISH_DOCKER_ARCHS)
219245
$(PUBLISH_DOCKER_ARCHS): common-docker-publish-%:
220246
docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)"
221247

248+
DOCKER_MAJOR_VERSION_TAG = $(firstword $(subst ., ,$(shell cat VERSION)))
222249
.PHONY: common-docker-tag-latest $(TAG_DOCKER_ARCHS)
223250
common-docker-tag-latest: $(TAG_DOCKER_ARCHS)
224251
$(TAG_DOCKER_ARCHS): common-docker-tag-latest-%:
225252
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:latest"
253+
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)"
226254

227255
.PHONY: common-docker-manifest
228256
common-docker-manifest:
@@ -247,7 +275,9 @@ proto:
247275
ifdef GOLANGCI_LINT
248276
$(GOLANGCI_LINT):
249277
mkdir -p $(FIRST_GOPATH)/bin
250-
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
278+
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCI_LINT_VERSION)/install.sh \
279+
| sed -e '/install -d/d' \
280+
| sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
251281
endif
252282

253283
ifdef GOVENDOR

Diff for: README-RDS.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
### When using postgres-exporter with Amazon Web Services' RDS, the
44
rolname "rdsadmin" and datname "rdsadmin" must be excluded.
55

6-
I had success running docker container 'wrouesnel/postgres_exporter:latest'
6+
I had success running docker container 'quay.io/prometheuscommunity/postgres-exporter:latest'
77
with queries.yaml as the PG_EXPORTER_EXTEND_QUERY_PATH. errors
88
mentioned in issue#335 appeared and I had to modify the
99
'pg_stat_statements' query with the following:
@@ -24,7 +24,7 @@ Running postgres-exporter in a container like so:
2424
-e PG_EXPORTER_DISABLE_DEFAULT_METRICS=true \
2525
-e PG_EXPORTER_DISABLE_SETTINGS_METRICS=true \
2626
-e PG_EXPORTER_EXTEND_QUERY_PATH='/var/lib/postgresql/queries.yaml' \
27-
wrouesnel/postgres_exporter
27+
quay.io/prometheuscommunity/postgres-exporter
2828
```
2929

3030
### Expected changes to RDS:

Diff for: README.md

+19-27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
[![Build Status](https://travis-ci.org/wrouesnel/postgres_exporter.svg?branch=master)](https://travis-ci.org/wrouesnel/postgres_exporter)
2-
[![Coverage Status](https://coveralls.io/repos/github/wrouesnel/postgres_exporter/badge.svg?branch=master)](https://coveralls.io/github/wrouesnel/postgres_exporter?branch=master)
3-
[![Go Report Card](https://goreportcard.com/badge/github.com/wrouesnel/postgres_exporter)](https://goreportcard.com/report/github.com/wrouesnel/postgres_exporter)
4-
[![Docker Pulls](https://img.shields.io/docker/pulls/wrouesnel/postgres_exporter.svg)](https://hub.docker.com/r/wrouesnel/postgres_exporter/tags)
1+
[![Build Status](https://circleci.com/gh/prometheus-community/postgres_exporter.svg?style=svg)](https://circleci.com/gh/prometheus-community/postgres_exporter)
2+
[![Coverage Status](https://coveralls.io/repos/github/prometheus-community/postgres_exporter/badge.svg?branch=master)](https://coveralls.io/github/prometheus-community/postgres_exporter?branch=master)
3+
[![Go Report Card](https://goreportcard.com/badge/github.com/prometheus-community/postgres_exporter)](https://goreportcard.com/report/github.com/prometheus-community/postgres_exporter)
4+
[![Docker Pulls](https://img.shields.io/docker/pulls/prometheuscommunity/postgres-exporter.svg)](https://hub.docker.com/r/prometheuscommunity/postgres-exporter/tags)
55

66
# PostgreSQL Server Exporter
77

@@ -15,31 +15,30 @@ This package is available for Docker:
1515
# Start an example database
1616
docker run --net=host -it --rm -e POSTGRES_PASSWORD=password postgres
1717
# Connect to it
18-
docker run --net=host -e DATA_SOURCE_NAME="postgresql://postgres:password@localhost:5432/postgres?sslmode=disable" wrouesnel/postgres_exporter
18+
docker run \
19+
--net=host \
20+
-e DATA_SOURCE_NAME="postgresql://postgres:password@localhost:5432/postgres?sslmode=disable" \
21+
quay.io/prometheuscommunity/postgres-exporter
1922
```
2023

2124
## Building and running
2225

23-
The build system is based on [Mage](https://magefile.org)
26+
git clone https://github.com/prometheus-community/postgres_exporter.git
27+
cd postgres_exporter
28+
make build
29+
./postgres_exporter <flags>
2430

25-
The default make file behavior is to build the binary:
26-
```
27-
$ go get github.com/wrouesnel/postgres_exporter
28-
$ cd ${GOPATH-$HOME/go}/src/github.com/wrouesnel/postgres_exporter
29-
$ go run mage.go binary
30-
$ export DATA_SOURCE_NAME="postgresql://login:password@hostname:port/dbname"
31-
$ ./postgres_exporter <flags>
32-
```
31+
To build the Docker image:
3332

34-
To build the dockerfile, run `go run mage.go docker`.
33+
make promu
34+
promu crossbuild -p linux/amd64 -p linux/armv7 -p linux/amd64 -p linux/ppc64le
35+
make docker
3536

36-
This will build the docker image as `wrouesnel/postgres_exporter:latest`. This
37-
is a minimal docker image containing *just* postgres_exporter. By default no SSL
38-
certificates are included, if you need to use SSL you should either bind-mount
39-
`/etc/ssl/certs/ca-certificates.crt` or derive a new image containing them.
37+
This will build the docker image as `prometheuscommunity/postgres_exporter:${branch}`.
4038

4139
### Vendoring
42-
Package vendoring is handled with [`govendor`](https://github.com/kardianos/govendor)
40+
41+
Package vendoring is handled with Go modules.
4342

4443
### Flags
4544

@@ -277,10 +276,3 @@ GRANT SELECT ON postgres_exporter.pg_stat_statements TO postgres_exporter;
277276
> ```
278277
> DATA_SOURCE_NAME=postgresql://postgres_exporter:password@localhost:5432/postgres?sslmode=disable
279278
> ```
280-
281-
# Hacking
282-
* To build a copy for your current architecture run `go run mage.go binary`.
283-
This will create a symlink to the just built binary in the root directory.
284-
* To build release tar balls run `go run mage.go release`.
285-
* Build system is a bit temperamental at the moment since the conversion to mage - I am working on getting it
286-
to be a perfect out of the box experience, but am time-constrained on it at the moment.

Diff for: cmd/postgres_exporter/pg_setting.go

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright 2021 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
114
package main
215

316
import (

0 commit comments

Comments
 (0)