Skip to content

Commit 4b6557d

Browse files
authored
Merge branch 'prometheus-community:master' into master
2 parents a8735d3 + 9bd9d83 commit 4b6557d

28 files changed

+1050
-270
lines changed

.circleci/config.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,28 @@ workflows:
6363
- cimg/postgres:14.1
6464
- prometheus/build:
6565
name: build
66+
parallelism: 3
67+
promu_opts: "-p linux/amd64 -p windows/amd64 -p linux/arm64 -p darwin/amd64 -p darwin/arm64 -p linux/386"
6668
filters:
6769
tags:
68-
only: /.*/
70+
ignore: /^v.*/
71+
branches:
72+
ignore: /^(main|master|release-.*|.*build-all.*)$/
73+
- prometheus/build:
74+
name: build_all
75+
parallelism: 12
76+
filters:
77+
branches:
78+
only: /^(main|master|release-.*|.*build-all.*)$/
79+
tags:
80+
only: /^v.*/
6981
- prometheus/publish_master:
7082
context: org-context
7183
docker_hub_organization: prometheuscommunity
7284
quay_io_organization: prometheuscommunity
7385
requires:
7486
- test
75-
- build
87+
- build_all
7688
filters:
7789
branches:
7890
only: master
@@ -82,7 +94,7 @@ workflows:
8294
quay_io_organization: prometheuscommunity
8395
requires:
8496
- test
85-
- build
97+
- build_all
8698
filters:
8799
tags:
88100
only: /^v.*/

CHANGELOG.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
## master / unreleased
22

3-
* [CHANGE] pg_stat_bgwriter counter metrics had the `_total` suffix added #556
3+
## 0.12.0-rc.0 / 2022-08-26
4+
5+
BREAKING CHANGES:
6+
7+
This release changes support for multiple postgres servers to use the
8+
multi-target exporter pattern. This makes it much easier to monitor multiple
9+
PostgreSQL servers from a single exporter by passing the target via URL
10+
params. See the Multi-Target Support section of the README.
11+
12+
* [CHANGE] Add multi-target support #618
13+
* [BUGFIX] Add dsn type for handling datasources #678
14+
15+
## 0.11.1 / 2022-08-01
16+
17+
* [BUGFIX] Fix checkpoint_write_time value type #666
18+
* [BUGFIX] Fix checkpoint_sync_time value type #667
19+
20+
## 0.11.0 / 2022-07-28
21+
22+
NOTE: pg_stat_bgwriter counter metrics had the `_total` suffix added #556
23+
24+
* [CHANGE] refactor pg_stat_bgwriter metrics into standalone collector #556
25+
* [FEATURE] Add pg_database collector #613
426
* [ENHANCEMENT] Add pg_database_size_bytes metric #613
27+
* [BUGFIX] Avoid parsing error from bogus Azure Flexible Server custom GUC #587
28+
* [BUGFIX] Fix pg_stat_archiver error in 9.4 and earlier. #599
29+
* [BUGFIX] Sanitize setting values because of Aurora irregularity #620
530

631
## 0.10.1 / 2022-01-14
732

Makefile.common

Lines changed: 16 additions & 66 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

@@ -81,16 +58,19 @@ endif
8158
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

61+
SKIP_GOLANGCI_LINT :=
8462
GOLANGCI_LINT :=
8563
GOLANGCI_LINT_OPTS ?=
86-
GOLANGCI_LINT_VERSION ?= v1.45.2
64+
GOLANGCI_LINT_VERSION ?= v1.49.0
8765
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
8866
# windows isn't included here because of the path separator being different.
8967
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
9068
ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386))
9169
# If we're in CI and there is an Actions file, that means the linter
9270
# is being run in Actions, so we don't need to run it here.
93-
ifeq (,$(CIRCLE_JOB))
71+
ifneq (,$(SKIP_GOLANGCI_LINT))
72+
GOLANGCI_LINT :=
73+
else ifeq (,$(CIRCLE_JOB))
9474
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
9575
else ifeq (,$(wildcard .github/workflows/golangci-lint.yml))
9676
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
@@ -150,58 +130,47 @@ common-check_license:
150130
.PHONY: common-deps
151131
common-deps:
152132
@echo ">> getting dependencies"
153-
ifdef GO111MODULE
154-
GO111MODULE=$(GO111MODULE) $(GO) mod download
155-
else
156-
$(GO) get $(GOOPTS) -t ./...
157-
endif
133+
$(GO) mod download
158134

159135
.PHONY: update-go-deps
160136
update-go-deps:
161137
@echo ">> updating Go dependencies"
162138
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
163139
$(GO) get -d $$m; \
164140
done
165-
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
166-
ifneq (,$(wildcard vendor))
167-
GO111MODULE=$(GO111MODULE) $(GO) mod vendor
168-
endif
141+
$(GO) mod tidy
169142

170143
.PHONY: common-test-short
171144
common-test-short: $(GOTEST_DIR)
172145
@echo ">> running short tests"
173-
GO111MODULE=$(GO111MODULE) $(GOTEST) -short $(GOOPTS) $(pkgs)
146+
$(GOTEST) -short $(GOOPTS) $(pkgs)
174147

175148
.PHONY: common-test
176149
common-test: $(GOTEST_DIR)
177150
@echo ">> running all tests"
178-
GO111MODULE=$(GO111MODULE) $(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
151+
$(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
179152

180153
$(GOTEST_DIR):
181154
@mkdir -p $@
182155

183156
.PHONY: common-format
184157
common-format:
185158
@echo ">> formatting code"
186-
GO111MODULE=$(GO111MODULE) $(GO) fmt $(pkgs)
159+
$(GO) fmt $(pkgs)
187160

188161
.PHONY: common-vet
189162
common-vet:
190163
@echo ">> vetting code"
191-
GO111MODULE=$(GO111MODULE) $(GO) vet $(GOOPTS) $(pkgs)
164+
$(GO) vet $(GOOPTS) $(pkgs)
192165

193166
.PHONY: common-lint
194167
common-lint: $(GOLANGCI_LINT)
195168
ifdef GOLANGCI_LINT
196169
@echo ">> running golangci-lint"
197-
ifdef GO111MODULE
198170
# 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
199171
# 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
172+
$(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
173+
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
205174
endif
206175

207176
.PHONY: common-yamllint
@@ -218,28 +187,15 @@ endif
218187
common-staticcheck: lint
219188

220189
.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
190+
common-unused:
227191
@echo ">> running check for unused/missing packages in go.mod"
228-
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
229-
ifeq (,$(wildcard vendor))
192+
$(GO) mod tidy
230193
@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
238194

239195
.PHONY: common-build
240196
common-build: promu
241197
@echo ">> building binaries"
242-
GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
198+
$(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
243199

244200
.PHONY: common-tarball
245201
common-tarball: promu
@@ -295,12 +251,6 @@ $(GOLANGCI_LINT):
295251
| sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
296252
endif
297253

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

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,36 @@ docker run \
2121
quay.io/prometheuscommunity/postgres-exporter
2222
```
2323

24+
## Multi-Target Support (BETA)
25+
**This Feature is in beta and may require changes in future releases. Feedback is welcome.**
26+
27+
This exporter supports the [multi-target pattern](https://prometheus.io/docs/guides/multi-target-exporter/). This allows running a single instance of this exporter for multiple postgres targets. Using the multi-target functionality of this exporter is **optional** and meant for cases where it is impossible to install the exporter as a sidecar, for example SaaS-managed services.
28+
29+
To use the multi-target functionality, send an http request to the endpoint `/probe?target=foo:5432` where target is set to the DSN of the postgres instance to scrape metrics from.
30+
31+
To avoid putting sensitive information like username and password in the URL, preconfigured auth modules are supported via the [auth_modules](#auth_modules) section of the config file. auth_modules for DSNs can be used with the `/probe` endpoint by specifying the `?auth_module=foo` http parameter.
32+
33+
## Configuration File
34+
35+
The configuration file controls the behavior of the exporter. It can be set using the `--config.file` command line flag and defaults to `postgres_exporter.yml`.
36+
37+
### auth_modules
38+
This section defines preset authentication and connection parameters for use in the [multi-target endpoint](#multi-target-support-beta). `auth_modules` is a map of modules with the key being the identifier which can be used in the `/probe` endpoint.
39+
Currently only the `userpass` type is supported.
40+
41+
Example:
42+
```yaml
43+
auth_modules:
44+
foo1: # Set this to any name you want
45+
type: userpass
46+
userpass:
47+
username: first
48+
password: firstpass
49+
options:
50+
# options become key=value parameters of the DSN
51+
sslmode: disable
52+
```
53+
2454
## Building and running
2555
2656
git clone https://github.com/prometheus-community/postgres_exporter.git

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.10.1
1+
0.12.0-rc.0

cmd/postgres_exporter/datasource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ func getDataSources() ([]string, error) {
162162
uri = os.Getenv("DATA_SOURCE_URI")
163163
}
164164

165+
// No datasources found. This allows us to support the multi-target pattern
166+
// without an explicit datasource.
167+
if uri == "" {
168+
return []string{}, nil
169+
}
170+
165171
dsn = "postgresql://" + ui + "@" + uri
166172

167173
return []string{dsn}, nil

cmd/postgres_exporter/main.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/go-kit/log"
2121
"github.com/go-kit/log/level"
2222
"github.com/prometheus-community/postgres_exporter/collector"
23+
"github.com/prometheus-community/postgres_exporter/config"
2324
"github.com/prometheus/client_golang/prometheus"
2425
"github.com/prometheus/client_golang/prometheus/promhttp"
2526
"github.com/prometheus/common/promlog"
@@ -31,6 +32,11 @@ import (
3132
)
3233

3334
var (
35+
c = config.ConfigHandler{
36+
Config: &config.Config{},
37+
}
38+
39+
configFile = kingpin.Flag("config.file", "Postgres exporter configuration file.").Default("postgres_exporter.yml").String()
3440
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
3541
webConfig = webflag.AddFlags(kingpin.CommandLine)
3642
metricPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").Envar("PG_EXPORTER_WEB_TELEMETRY_PATH").String()
@@ -85,14 +91,14 @@ func main() {
8591
return
8692
}
8793

88-
dsn, err := getDataSources()
89-
if err != nil {
90-
level.Error(logger).Log("msg", "Failed reading data sources", "err", err.Error())
91-
os.Exit(1)
94+
if err := c.ReloadConfig(*configFile, logger); err != nil {
95+
// This is not fatal, but it means that auth must be provided for every dsn.
96+
level.Error(logger).Log("msg", "Error loading config", "err", err)
9297
}
9398

94-
if len(dsn) == 0 {
95-
level.Error(logger).Log("msg", "Couldn't find environment variables describing the datasource to use")
99+
dsns, err := getDataSources()
100+
if err != nil {
101+
level.Error(logger).Log("msg", "Failed reading data sources", "err", err.Error())
96102
os.Exit(1)
97103
}
98104

@@ -106,7 +112,7 @@ func main() {
106112
IncludeDatabases(*includeDatabases),
107113
}
108114

109-
exporter := NewExporter(dsn, opts...)
115+
exporter := NewExporter(dsns, opts...)
110116
defer func() {
111117
exporter.servers.Close()
112118
}()
@@ -115,23 +121,31 @@ func main() {
115121

116122
prometheus.MustRegister(exporter)
117123

124+
// TODO(@sysadmind): Remove this with multi-target support. We are removing multiple DSN support
125+
dsn := ""
126+
if len(dsns) > 0 {
127+
dsn = dsns[0]
128+
}
129+
118130
pe, err := collector.NewPostgresCollector(
119131
logger,
120132
dsn,
121133
[]string{},
122134
)
123135
if err != nil {
124136
level.Error(logger).Log("msg", "Failed to create PostgresCollector", "err", err.Error())
125-
os.Exit(1)
137+
} else {
138+
prometheus.MustRegister(pe)
126139
}
127-
prometheus.MustRegister(pe)
128140

129141
http.Handle(*metricPath, promhttp.Handler())
130142
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
131143
w.Header().Set("Content-Type", "text/html; charset=UTF-8") // nolint: errcheck
132144
w.Write(landingPage) // nolint: errcheck
133145
})
134146

147+
http.HandleFunc("/probe", handleProbe(logger))
148+
135149
level.Info(logger).Log("msg", "Listening on address", "address", *listenAddress)
136150
srv := &http.Server{Addr: *listenAddress}
137151
if err := web.ListenAndServe(srv, *webConfig, logger); err != nil {

cmd/postgres_exporter/namespace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"fmt"
2020
"time"
2121

22-
"github.com/blang/semver"
22+
"github.com/blang/semver/v4"
2323
"github.com/go-kit/log/level"
2424
"github.com/lib/pq"
2525
"github.com/prometheus/client_golang/prometheus"

0 commit comments

Comments
 (0)