Skip to content

Commit b74ef57

Browse files
authored
PMM-10278 postgres_exporter integration tests (percona#71)
PMM-10278 add compatibility tests for exporter upgrade
1 parent b3ed0b2 commit b74ef57

17 files changed

+1431
-3
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@
2020
/.metrics.*.removed
2121
/tools/src
2222
/vendor
23+
/percona_tests/assets/postgres_exporter
24+
/percona_tests/assets/postgres_exporter_percona
25+
/percona_tests/assets/metrics.new.txt
26+
/percona_tests/assets/metrics.old.txt
27+
/percona_tests/assets/metrics.names.new.txt
28+
/percona_tests/assets/metrics.names.old.txt

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ require (
66
github.com/blang/semver v3.5.1+incompatible
77
github.com/go-kit/log v0.2.0
88
github.com/lib/pq v1.10.4
9+
github.com/montanaflynn/stats v0.6.6
10+
github.com/pkg/errors v0.9.1
911
github.com/prometheus/client_golang v1.12.1
1012
github.com/prometheus/client_model v0.2.0
1113
github.com/prometheus/common v0.32.1
1214
github.com/prometheus/exporter-toolkit v0.7.1
1315
github.com/stretchr/testify v1.4.0
16+
github.com/tklauser/go-sysconf v0.3.10
17+
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27
1418
gopkg.in/alecthomas/kingpin.v2 v2.2.6
1519
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
1620
gopkg.in/yaml.v2 v2.4.0
@@ -29,13 +33,12 @@ require (
2933
github.com/kr/text v0.1.0 // indirect
3034
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
3135
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
32-
github.com/pkg/errors v0.9.1 // indirect
3336
github.com/pmezard/go-difflib v1.0.0 // indirect
3437
github.com/prometheus/procfs v0.7.3 // indirect
38+
github.com/tklauser/numcpus v0.4.0 // indirect
3539
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
3640
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
3741
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
38-
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
3942
golang.org/x/text v0.3.6 // indirect
4043
google.golang.org/appengine v1.6.6 // indirect
4144
google.golang.org/protobuf v1.26.0 // indirect

go.sum

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
162162
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
163163
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
164164
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
165+
github.com/montanaflynn/stats v0.6.6 h1:Duep6KMIDpY4Yo11iFsvyqJDyfzLF9+sndUKT+v64GQ=
166+
github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
165167
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
166168
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
167169
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
@@ -206,6 +208,10 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
206208
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
207209
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
208210
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
211+
github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw=
212+
github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
213+
github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o=
214+
github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=
209215
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
210216
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
211217
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@@ -335,8 +341,9 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w
335341
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
336342
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
337343
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
338-
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=
339344
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
345+
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 h1:XDXtA5hveEEV8JB2l7nhMTp3t3cHp9ZpwcdjqyEWLlo=
346+
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
340347
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
341348
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
342349
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

percona_tests/Makefile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#########################
2+
### tests
3+
4+
# measures avg scrape time and compares old vs new exporters
5+
test-performance:
6+
go test -v -run '^TestPerformance$$' -args -doRun=true
7+
8+
extraMetrics = false
9+
multipleLabels = false
10+
dumpMetrics = false
11+
12+
test-metrics:
13+
go test -v -run '^TestMissingMetrics$$' -args -doRun=true
14+
15+
test-labels:
16+
go test -v -run '^TestMissingLabels$$' -args -doRun=true
17+
18+
test-resolutions-duplicates:
19+
go test -v -run '^TestResolutionsMetricDuplicates$$' -args -doRun=true
20+
21+
test-resolutions:
22+
go test -v -run '^TestResolutions$$' -args -doRun=true
23+
24+
dump-metrics:
25+
go test -v -run '^TestDumpMetrics$$' -args -doRun=true -extraMetrics=$(extraMetrics) -multipleLabels=$(multipleLabels) -dumpMetrics=$(dumpMetrics)
26+
27+
test-consistency: test-metrics test-resolutions test-resolutions-duplicates
28+
29+
#########################
30+
### env preparation
31+
32+
# download exporter from provided feature build's client binary url
33+
prepare-exporter-from-fb:
34+
go test -v -run '^TestPrepareUpdatedExporter$\' -args -doRun=true -url=$(url)
35+
36+
prepare-exporter-from-repo:
37+
make -C ../ build && cp ../postgres_exporter assets/postgres_exporter
38+
39+
prepare-base-exporter:
40+
tar -xf assets/postgres_exporter_percona.tar.xz -C assets/
41+
42+
start-postgres-db:
43+
docker-compose -f assets/postgres-compose.yml up -d --force-recreate --renew-anon-volumes --remove-orphans
44+
45+
stop-postgres-db:
46+
docker-compose -f assets/postgres-compose.yml down
47+
48+
prepare-env-from-repo: prepare-exporter-from-repo prepare-base-exporter start-postgres-db
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
version: '3.7'
3+
4+
services:
5+
postgres:
6+
image: ${POSTGRES_IMAGE:-postgres:11}
7+
container_name: postgres-test-srv
8+
command: >
9+
-c shared_preload_libraries='${PG_PRELOADED_LIBS:-pg_stat_statements}'
10+
-c track_activity_query_size=2048
11+
-c pg_stat_statements.max=10000
12+
-c pg_stat_monitor.pgsm_query_max_len=10000
13+
-c pg_stat_statements.track=all
14+
-c pg_stat_statements.save=off
15+
-c track_io_timing=on
16+
ports:
17+
- "127.0.0.1:5432:5432"
18+
environment:
19+
- POSTGRES_USER=postgres
20+
- POSTGRES_PASSWORD=postgres
21+
volumes:
22+
- postgres-test-srv-vol:/docker-entrypoint-initdb.d/
23+
networks:
24+
- postgres-test-srv-net
25+
26+
volumes:
27+
postgres-test-srv-vol:
28+
29+
networks:
30+
postgres-test-srv-net:
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--auto-discover-databases
2+
--collect.custom_query.hr
3+
--collect.custom_query.lr
4+
--collect.custom_query.mr
5+
--exclude-databases=template0,template1,postgres,cloudsqladmin,pmm-managed-dev,azure_maintenance
6+
--log.level=warn
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## ######################################################
2+
## WARNING: This is an example. Do not edit this file.
3+
## To create your own Custom Queries - create a new file
4+
## ######################################################
5+
## Custom query example.
6+
#pg_replication:
7+
# query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) as lag"
8+
# metrics:
9+
# - lag:
10+
# usage: "GAUGE"
11+
# description: "Replication lag behind master in seconds"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pg_postmaster_uptime:
2+
query: "select extract(epoch from current_timestamp - pg_postmaster_start_time()) as seconds"
3+
master: true
4+
metrics:
5+
- seconds:
6+
usage: "GAUGE"
7+
description: "Service uptime"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## ######################################################
2+
## WARNING: This is an example. Do not edit this file.
3+
## To create your own Custom Queries - create a new file
4+
## ######################################################
5+
## Custom query example.
6+
#pg_replication:
7+
# query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) as lag"
8+
# metrics:
9+
# - lag:
10+
# usage: "GAUGE"
11+
# description: "Replication lag behind master in seconds"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## ######################################################
2+
## WARNING: This is an example. Do not edit this file.
3+
## To create your own Custom Queries - create a new file
4+
## ######################################################
5+
## Custom query example.
6+
#pg_replication:
7+
# query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) as lag"
8+
# metrics:
9+
# - lag:
10+
# usage: "GAUGE"
11+
# description: "Replication lag behind master in seconds"

0 commit comments

Comments
 (0)