Skip to content

Commit e627d71

Browse files
committed
test(integration): add Compose-based MySQL harness and collector test runner; docs
Add a self-contained integration test that spins up MySQL 8.4 with performance_schema, seeds a small workload, and validates collectors via a locally-built exporter image. What's included: - docker-compose.yml (fixed network name: mysql-test) - mysql/conf.d/perf-schema.cnf - mysql/initdb/01-users.sql (exporter/app users, grants) - seed/seed.sh (INSERT/SELECT/UPDATE/SLEEP loop) - test_compose_collectors.sh: * builds mysqld-exporter:local * ensures users (caching_sha2_password) * runs exporter per --collect.* flag (no host port binding) * curls /metrics from inside the network * per-flag log files under ./_testlogs/ * robust readiness + failure diagnostics * optional auto-discovery of collector flags from --help Docs (README.md): - Document new flags: --collect.sys.user_summary_by_statement_latency --collect.sys.user_summary_by_statement_type * list emitted metric families and units - Note clamping behavior in --collect.sys.user_summary - Add "Docker Compose integration test" section with usage Usage: ./test_compose_collectors.sh Artifacts: _testlogs/exporter_<flag>.log License: Added the mandatory license comments to the newly-committed source files. This commit touches only test infra and docs; no exporter runtime code changes. Signed-off-by: Sergei Klochkov <[email protected]>
1 parent 5c893b0 commit e627d71

12 files changed

+434
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
.idea
1010
*.iml
1111
/vendor
12+
_testlogs/

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,30 @@ docker run -d \
206206
prom/mysqld-exporter
207207
```
208208

209+
## Docker Compose integration test
210+
211+
A self-contained test harness is included to validate collectors against a local MySQL:
212+
213+
- Spins up **MySQL 8.4** with `performance_schema` on
214+
- Seeds basic workload so `sys` summaries have data
215+
- Builds and runs your **local** exporter image per collector flag
216+
- Captures exporter logs per test under `_testlogs/`
217+
- Verifies metrics via in-network HTTP (no host port binding)
218+
219+
**Prereqs:** Docker & Docker Compose v2.
220+
221+
**Files:**
222+
- `docker-compose.yml` (MySQL service + one-shot seeder)
223+
- `mysql/conf.d/perf-schema.cnf` (ensures P_S consumers on)
224+
- `mysql/initdb/01-users.sql` (creates `exporter` & `app`; grants)
225+
- `seed/seed.sh` (simple INSERT/SELECT/UPDATE/SLEEP loop)
226+
- `test_compose_collectors.sh` (runner)
227+
228+
**Run:**
229+
```bash
230+
./test_compose_collectors.sh
231+
```
232+
209233
## heartbeat
210234

211235
With `collect.heartbeat` enabled, mysqld_exporter will scrape replication delay

collector/sys_user_summary_by_statement_latency.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright 2022 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 collector
215

316
import (

collector/sys_user_summary_by_statement_latency_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright 2022 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 collector
215

316
import (

collector/sys_user_summary_by_statement_type.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright 2022 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 collector
215

316
import (

collector/sys_user_summary_by_statement_type_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright 2022 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 collector
215

316
import (

collector/sys_user_summary_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ func TestScrapeSysUserSummary(t *testing.T) {
100100
value = value / picoSeconds
101101
}
102102
if (i == 9 || i == 10) && value < 0 {
103-
value = 0
104-
}
103+
value = 0
104+
}
105105
expectedMetrics = append(expectedMetrics, MetricResult{
106106
labels: labelMap{"user": user.(string)},
107107
value: value,

docker-compose.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
services:
2+
mysql:
3+
image: mysql:8.4
4+
environment:
5+
MYSQL_ROOT_PASSWORD: rootpass
6+
MYSQL_DATABASE: testdb
7+
MYSQL_USER: app
8+
MYSQL_PASSWORD: app
9+
command: ["--performance_schema=ON"]
10+
healthcheck:
11+
test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -uroot -prootpass || exit 1"]
12+
interval: 5s
13+
timeout: 3s
14+
retries: 30
15+
volumes:
16+
- ./test-files/mysql/conf.d:/etc/mysql/conf.d:ro
17+
- ./test-files/mysql/initdb:/docker-entrypoint-initdb.d:ro
18+
networks:
19+
mysql-test:
20+
aliases:
21+
- mysql # ensure 'mysql' DNS name exists on this network
22+
23+
seed:
24+
image: mysql:8.4
25+
depends_on:
26+
mysql:
27+
condition: service_healthy
28+
environment:
29+
MYSQL_HOST: mysql
30+
MYSQL_USER: app
31+
MYSQL_PASSWORD: app
32+
MYSQL_DATABASE: testdb
33+
volumes:
34+
- ./test-files/seed/seed.sh:/seed/seed.sh:ro
35+
entrypoint: ["/bin/bash", "/seed/seed.sh"]
36+
networks: [mysql-test]
37+
38+
networks:
39+
mysql-test:
40+
name: mysql-test
41+
driver: bridge
42+
external: true
43+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[mysqld]
2+
performance_schema=ON
3+
# The following consumers are typically on by default in 8.x; keeping explicit for clarity.
4+
performance_schema_consumer_events_statements_history=ON
5+
performance_schema_consumer_events_statements_history_long=ON
6+
performance_schema_consumer_events_statements_current=ON
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE USER IF NOT EXISTS 'exporter'@'%' IDENTIFIED BY 'exporter';
2+
-- Force the plugin in case the user existed from a previous run with a different plugin
3+
ALTER USER 'exporter'@'%' IDENTIFIED WITH caching_sha2_password BY 'exporter';
4+
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
5+
6+
-- App user for seeding
7+
CREATE USER IF NOT EXISTS 'app'@'%' IDENTIFIED BY 'app';
8+
CREATE DATABASE IF NOT EXISTS testdb;
9+
GRANT ALL PRIVILEGES ON testdb.* TO 'app'@'%';
10+
11+
FLUSH PRIVILEGES;

0 commit comments

Comments
 (0)