Skip to content

PMM-10278 postgres_exporter integration tests #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 70 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
cbd7ace
add compatibility with old exporter
ritbl May 22, 2022
e4258fe
add docker compose and SSL serts
ritbl May 22, 2022
46b20fc
add tools
ritbl May 22, 2022
0dc3950
remove common-check_license
ritbl May 22, 2022
9b2058d
cleanup
ritbl May 22, 2022
8cbe0d6
change to manual mode
ritbl May 22, 2022
fe3a5dd
remove yamllint
ritbl May 22, 2022
318af7c
remove tip
ritbl May 22, 2022
074ad4a
add PG 13 and 14 to build matrix
ritbl May 22, 2022
ceb3788
add configs
ritbl May 22, 2022
60adc4c
up
ritbl May 24, 2022
675b953
style
ritbl May 24, 2022
f4f2499
cleanup
ritbl May 24, 2022
6082c4e
fix test
ritbl May 24, 2022
c18424f
style
ritbl May 27, 2022
c09bffd
style
ritbl May 27, 2022
d6f75c3
review request
ritbl May 27, 2022
c9adb32
mod tidy
ritbl Jun 3, 2022
7124736
revert DSN pg change
ritbl Jun 14, 2022
1e10c56
PMM-10278 Added pgexporter test skeleton
tshcherban Jul 27, 2022
ff67891
PMM-10278 Test update
tshcherban Jul 27, 2022
6eae185
PMM-10278 Test update
tshcherban Jul 27, 2022
fcafb6b
PMM-10278 Wrap error
tshcherban Jul 27, 2022
e290e04
PMM-10278 Add memory stats, add exporter extract from client binary
tshcherban Aug 5, 2022
2dfbe3b
PMM-10278 make postgres params configurable
tshcherban Aug 5, 2022
e2d34c8
PMM-10278 message amend
tshcherban Aug 5, 2022
7167fd3
PMM-10278 lint disable
tshcherban Aug 5, 2022
2b84c9d
PMM-10278 host move to const
tshcherban Aug 5, 2022
9c09625
PMM-10278 const update
tshcherban Aug 5, 2022
67c8399
PMM-9973 resolutions filtering fix
tshcherban Aug 19, 2022
1f46409
PMM-9973 resolutions filtering fix
tshcherban Aug 19, 2022
3cc042b
PMM-10278 Add makefile for tests prepare and running
tshcherban Aug 19, 2022
0f388cf
PMM-9973 resolutions filtering fix
tshcherban Aug 19, 2022
fa73ee0
PMM-9973 resolutions filtering fix
tshcherban Aug 19, 2022
43f7dd1
PMM-9973 lint disable
tshcherban Aug 19, 2022
6f7cdf3
Merge remote-tracking branch 'origin/PMM-9973-pg-exporter-resolutions…
tshcherban Aug 19, 2022
e1f0875
PMM-10278 Updated makefile to run tests locally
tshcherban Aug 28, 2022
596d4d7
PMM-10278 Build fix
tshcherban Aug 28, 2022
682e903
PMM-10278 Debug code remove
tshcherban Aug 28, 2022
2ba4152
PMM-10278 Add 'original' exporter binary
tshcherban Aug 29, 2022
2f83aab
PMM-10278 Add 'original' exporter binary to makefile
tshcherban Aug 29, 2022
ee201fe
PMM-10278 Add 'original' exporter binary to makefile
tshcherban Aug 29, 2022
56022d3
PMM-10278 Refactor
tshcherban Aug 29, 2022
8affd7f
PMM-10278 Add metrics test
tshcherban Aug 30, 2022
f1bfa39
PMM-10278 Refactor, add comments to Makefile
tshcherban Aug 30, 2022
e081348
PMM-10278 Debug code cleanup
tshcherban Aug 30, 2022
b3db609
PMM-10278 Readme update, add command to use exporter from local repo
tshcherban Aug 30, 2022
a44d524
PMM-10278 Add single command to prepare env from local repo
tshcherban Aug 30, 2022
f6aed88
PMM-10278 Tests reordered
tshcherban Aug 30, 2022
513ff30
PMM-10278 Assets reorder
tshcherban Aug 30, 2022
d67caae
PMM-10278 Path fix, test run fix
tshcherban Aug 30, 2022
5b0093b
PMM-10278 Debug code remove
tshcherban Aug 30, 2022
76187d8
PMM-10278 Filename move to const
tshcherban Aug 30, 2022
a94ae79
PMM-10278 Message details add
tshcherban Aug 30, 2022
ca64787
PMM-9973 add postgres collector to registry
tshcherban Aug 30, 2022
7065b7a
Merge remote-tracking branch 'origin/PMM-9973-pg-exporter-resolutions…
tshcherban Aug 30, 2022
588c2b1
PMM-9973 debug code remove
tshcherban Aug 30, 2022
6da0992
Merge remote-tracking branch 'origin/PMM-9973-pg-exporter-resolutions…
tshcherban Aug 30, 2022
99881df
PMM-10278 Tests reorganize
tshcherban Aug 30, 2022
da75328
PMM-10278 Remove dump func from tests
tshcherban Aug 30, 2022
579a90a
PMM-10278 Add resolutions tests
tshcherban Aug 30, 2022
6974dd9
Merge remote-tracking branch 'origin/main' into PMM-10278-pg-exporter…
tshcherban Sep 6, 2022
ae4962b
PMM-10278 go.mod fix
tshcherban Sep 6, 2022
f7c60c3
PMM-10278 Add high resolution test
tshcherban Sep 15, 2022
f794d61
PMM-10278 add high resolution test
tshcherban Sep 15, 2022
dfb5774
Update percona_tests/metrics_test.go
tshcherban Sep 21, 2022
e8e4a74
PMM-10278 Lint fix
tshcherban Oct 3, 2022
4bf07b9
PMM-10278 CommandName fix
tshcherban Oct 3, 2022
f73eecb
Merge remote-tracking branch 'origin/main' into PMM-10278-pg-exporter…
tshcherban Oct 3, 2022
e180346
PMM-10278 lint fix
tshcherban Oct 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@
/.metrics.*.removed
/tools/src
/vendor
/percona_tests/assets/postgres_exporter
/percona_tests/assets/postgres_exporter_percona
/percona_tests/assets/metrics.new.txt
/percona_tests/assets/metrics.old.txt
/percona_tests/assets/metrics.names.new.txt
/percona_tests/assets/metrics.names.old.txt
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ require (
github.com/blang/semver v3.5.1+incompatible
github.com/go-kit/log v0.2.0
github.com/lib/pq v1.10.4
github.com/montanaflynn/stats v0.6.6
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.32.1
github.com/prometheus/exporter-toolkit v0.7.1
github.com/stretchr/testify v1.4.0
github.com/tklauser/go-sysconf v0.3.10
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -29,13 +33,12 @@ require (
github.com/kr/text v0.1.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/text v0.3.6 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/protobuf v1.26.0 // indirect
Expand Down
9 changes: 8 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/montanaflynn/stats v0.6.6 h1:Duep6KMIDpY4Yo11iFsvyqJDyfzLF9+sndUKT+v64GQ=
github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
Expand Down Expand Up @@ -206,6 +208,10 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw=
github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o=
github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -335,8 +341,9 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 h1:XDXtA5hveEEV8JB2l7nhMTp3t3cHp9ZpwcdjqyEWLlo=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
48 changes: 48 additions & 0 deletions percona_tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#########################
### tests

# measures avg scrape time and compares old vs new exporters
test-performance:
go test -v -run '^TestPerformance$$' -args -doRun=true

extraMetrics = false
multipleLabels = false
dumpMetrics = false

test-metrics:
go test -v -run '^TestMissingMetrics$$' -args -doRun=true

test-labels:
go test -v -run '^TestMissingLabels$$' -args -doRun=true

test-resolutions-duplicates:
go test -v -run '^TestResolutionsMetricDuplicates$$' -args -doRun=true

test-resolutions:
go test -v -run '^TestResolutions$$' -args -doRun=true

dump-metrics:
go test -v -run '^TestDumpMetrics$$' -args -doRun=true -extraMetrics=$(extraMetrics) -multipleLabels=$(multipleLabels) -dumpMetrics=$(dumpMetrics)

test-consistency: test-metrics test-resolutions test-resolutions-duplicates

#########################
### env preparation

# download exporter from provided feature build's client binary url
prepare-exporter-from-fb:
go test -v -run '^TestPrepareUpdatedExporter$\' -args -doRun=true -url=$(url)

prepare-exporter-from-repo:
make -C ../ build && cp ../postgres_exporter assets/postgres_exporter

prepare-base-exporter:
tar -xf assets/postgres_exporter_percona.tar.xz -C assets/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it's in tar and what does it contain?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its our old exporter (before any updates) to have a baseline.
In tar - because compressed it uses less space

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, but it adds additional code to the codebase, maybe it's better to keep it not archived? Do we have comparison in file sizes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its 2.2x smaller in archive (15.2m vs 6.8m). but ok, not a problem at all to store uncompressed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, can't we substitute it just by some golden file?

Copy link
Author

@tshcherban tshcherban Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you mean with stub metrics - those are dependent on system exporter is running on, so I wouldn't
and we are comparing CPU usage, which also depends on hardware

Copy link
Author

@tshcherban tshcherban Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also as a second iteration after finishing more important tasks im going to make those tests runnable on mac, because for now they're working only under linux. Ok for occasional exporters updating but nor future-proof neither cross-team friendly)


start-postgres-db:
docker-compose -f assets/postgres-compose.yml up -d --force-recreate --renew-anon-volumes --remove-orphans

stop-postgres-db:
docker-compose -f assets/postgres-compose.yml down

prepare-env-from-repo: prepare-exporter-from-repo prepare-base-exporter start-postgres-db
30 changes: 30 additions & 0 deletions percona_tests/assets/postgres-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
version: '3.7'

services:
postgres:
image: ${POSTGRES_IMAGE:-postgres:11}
container_name: postgres-test-srv
command: >
-c shared_preload_libraries='${PG_PRELOADED_LIBS:-pg_stat_statements}'
-c track_activity_query_size=2048
-c pg_stat_statements.max=10000
-c pg_stat_monitor.pgsm_query_max_len=10000
-c pg_stat_statements.track=all
-c pg_stat_statements.save=off
-c track_io_timing=on
ports:
- "127.0.0.1:5432:5432"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
volumes:
- postgres-test-srv-vol:/docker-entrypoint-initdb.d/
networks:
- postgres-test-srv-net

volumes:
postgres-test-srv-vol:

networks:
postgres-test-srv-net:
Binary file not shown.
6 changes: 6 additions & 0 deletions percona_tests/assets/test.exporter-flags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--auto-discover-databases
--collect.custom_query.hr
--collect.custom_query.lr
--collect.custom_query.mr
--exclude-databases=template0,template1,postgres,cloudsqladmin,pmm-managed-dev,azure_maintenance
--log.level=warn
Comment on lines +1 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need it to be in a separate file, not in the test where it's used

Copy link
Author

@tshcherban tshcherban Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really, just a bit simpler to edit flags list separate from code. but yep, ill move them in as a verbatim string

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## ######################################################
## WARNING: This is an example. Do not edit this file.
## To create your own Custom Queries - create a new file
## ######################################################
## Custom query example.
#pg_replication:
# query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) as lag"
# metrics:
# - lag:
# usage: "GAUGE"
# description: "Replication lag behind master in seconds"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pg_postmaster_uptime:
query: "select extract(epoch from current_timestamp - pg_postmaster_start_time()) as seconds"
master: true
metrics:
- seconds:
usage: "GAUGE"
description: "Service uptime"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## ######################################################
## WARNING: This is an example. Do not edit this file.
## To create your own Custom Queries - create a new file
## ######################################################
## Custom query example.
#pg_replication:
# query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) as lag"
# metrics:
# - lag:
# usage: "GAUGE"
# description: "Replication lag behind master in seconds"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## ######################################################
## WARNING: This is an example. Do not edit this file.
## To create your own Custom Queries - create a new file
## ######################################################
## Custom query example.
#pg_replication:
# query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) as lag"
# metrics:
# - lag:
# usage: "GAUGE"
# description: "Replication lag behind master in seconds"
Loading