Skip to content

Commit db4c6e8

Browse files
authored
PMM-7806: add compatibility with percona pg exporter (percona#68)
* add compatibility with old exporter
1 parent 0bacea2 commit db4c6e8

29 files changed

+4278
-347
lines changed

.circleci/config.yml

-90
This file was deleted.

.github/ISSUE_TEMPLATE/bug_report.md

-47
This file was deleted.

.github/ISSUE_TEMPLATE/config.yml

-5
This file was deleted.

.github/ISSUE_TEMPLATE/feature_request.md

-21
This file was deleted.

.github/workflows/go.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- v[0-9]+.[0-9]+.[0-9]+*
9+
pull_request:
10+
11+
jobs:
12+
test:
13+
name: Test
14+
strategy:
15+
matrix:
16+
go-version:
17+
- 1.17
18+
postgresql-image:
19+
- postgres:10
20+
- postgres:11
21+
- postgres:12
22+
- postgres:13
23+
- postgres:14
24+
runs-on: ubuntu-latest
25+
# The environment this job references
26+
environment:
27+
name: CI
28+
steps:
29+
- name: Set up Go release
30+
uses: percona-platform/setup-go@v2
31+
with:
32+
go-version: ${{ matrix.go-version }}
33+
- name: Checkout code
34+
uses: percona-platform/checkout@v2
35+
- name: Run checks
36+
run: |
37+
go build -modfile=tools/go.mod -o bin/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
38+
go build -modfile=tools/go.mod -o bin/reviewdog github.com/reviewdog/reviewdog/cmd/reviewdog
39+
bin/golangci-lint run -c=.golangci-required.yml --out-format=line-number | env REVIEWDOG_GITHUB_API_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/reviewdog -f=golangci-lint -level=error -reporter=github-pr-check
40+
bin/golangci-lint run -c=.golangci.yml --out-format=line-number | env REVIEWDOG_GITHUB_API_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/reviewdog -f=golangci-lint -level=error -reporter=github-pr-review
41+
- name: Run Tests
42+
run: |
43+
sudo chown 999:999 testdata/ssl/server/*
44+
sudo chmod 600 testdata/ssl/server/*
45+
docker-compose up -d
46+
make
47+
make test
48+
env:
49+
POSTGRESQL_IMAGE: ${{ matrix.postgresql-image }}
50+
- name: Run debug commands on failure
51+
if: ${{ failure() }}
52+
run: |
53+
env
54+
go version
55+
go env
56+
pwd
57+
git status
58+
docker --version
59+
docker-compose --version
60+
docker-compose logs

Makefile.common

+1-21
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ endif
124124
%: common-% ;
125125

126126
.PHONY: common-all
127-
common-all: precheck style check_license lint yamllint unused build test
127+
common-all: precheck style lint unused build test
128128

129129
.PHONY: common-style
130130
common-style:
@@ -136,17 +136,6 @@ common-style:
136136
exit 1; \
137137
fi
138138

139-
.PHONY: common-check_license
140-
common-check_license:
141-
@echo ">> checking license header"
142-
@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
143-
awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
144-
done); \
145-
if [ -n "$${licRes}" ]; then \
146-
echo "license header checking failed:"; echo "$${licRes}"; \
147-
exit 1; \
148-
fi
149-
150139
.PHONY: common-deps
151140
common-deps:
152141
@echo ">> getting dependencies"
@@ -204,15 +193,6 @@ else
204193
endif
205194
endif
206195

207-
.PHONY: common-yamllint
208-
common-yamllint:
209-
@echo ">> running yamllint on all YAML files in the repository"
210-
ifeq (, $(shell which yamllint))
211-
@echo "yamllint not installed so skipping"
212-
else
213-
yamllint .
214-
endif
215-
216196
# For backward-compatibility.
217197
.PHONY: common-staticcheck
218198
common-staticcheck: lint

cmd/postgres_exporter/datasource.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (e *Exporter) discoverDatabaseDSNs() []string {
3636
var dsnURI *url.URL
3737
var dsnConnstring string
3838

39-
if strings.HasPrefix(dsn, "postgresql://") {
39+
if strings.HasPrefix(dsn, "postgresql://") || strings.HasPrefix(dsn, "postgres://") {
4040
var err error
4141
dsnURI, err = url.Parse(dsn)
4242
if err != nil {

cmd/postgres_exporter/main.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ import (
3131
)
3232

3333
var (
34-
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
35-
webConfig = webflag.AddFlags(kingpin.CommandLine)
34+
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
35+
webConfig = webflag.AddFlags(kingpin.CommandLine)
36+
webConfigFile = kingpin.Flag(
37+
"web.config",
38+
"[EXPERIMENTAL] Path to config yaml file that can enable TLS or authentication.",
39+
).Default("").String()
3640
metricPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").Envar("PG_EXPORTER_WEB_TELEMETRY_PATH").String()
3741
disableDefaultMetrics = kingpin.Flag("disable-default-metrics", "Do not include default metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_DEFAULT_METRICS").Bool()
3842
disableSettingsMetrics = kingpin.Flag("disable-settings-metrics", "Do not include pg_settings metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_SETTINGS_METRICS").Bool()
3943
autoDiscoverDatabases = kingpin.Flag("auto-discover-databases", "Whether to discover the databases on a server dynamically.").Default("false").Envar("PG_EXPORTER_AUTO_DISCOVER_DATABASES").Bool()
40-
queriesPath = kingpin.Flag("extend.query-path", "Path to custom queries to run.").Default("").Envar("PG_EXPORTER_EXTEND_QUERY_PATH").String()
4144
onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool()
4245
constantLabelsList = kingpin.Flag("constantLabels", "A list of label=value separated by comma(,).").Default("").Envar("PG_EXPORTER_CONSTANT_LABELS").String()
4346
excludeDatabases = kingpin.Flag("exclude-databases", "A list of databases to remove when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_EXCLUDE_DATABASES").String()
@@ -100,7 +103,6 @@ func main() {
100103
DisableDefaultMetrics(*disableDefaultMetrics),
101104
DisableSettingsMetrics(*disableSettingsMetrics),
102105
AutoDiscoverDatabases(*autoDiscoverDatabases),
103-
WithUserQueriesPath(*queriesPath),
104106
WithConstantLabels(*constantLabelsList),
105107
ExcludeDatabases(*excludeDatabases),
106108
IncludeDatabases(*includeDatabases),
@@ -115,6 +117,9 @@ func main() {
115117

116118
prometheus.MustRegister(exporter)
117119

120+
cleanup := initializePerconaExporters(dsn, opts)
121+
defer cleanup()
122+
118123
pe, err := collector.NewPostgresCollector(
119124
logger,
120125
dsn,
@@ -132,9 +137,17 @@ func main() {
132137
w.Write(landingPage) // nolint: errcheck
133138
})
134139

140+
var webCfg string
141+
if *webConfigFile != "" {
142+
webCfg = *webConfigFile
143+
}
144+
if *webConfig != "" {
145+
webCfg = *webConfig
146+
}
147+
135148
level.Info(logger).Log("msg", "Listening on address", "address", *listenAddress)
136149
srv := &http.Server{Addr: *listenAddress}
137-
if err := web.ListenAndServe(srv, *webConfig, logger); err != nil {
150+
if err := web.ListenAndServe(srv, webCfg, logger); err != nil {
138151
level.Error(logger).Log("msg", "Error running HTTP server", "err", err)
139152
os.Exit(1)
140153
}

0 commit comments

Comments
 (0)