forked from prometheus/mysqld_exporter
-
Notifications
You must be signed in to change notification settings - Fork 41
PMM-12392 Collect processlist from performance_schema on newer MySQL #359
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
4nte
merged 14 commits into
main
from
PMM-12392-collect-processlist-from-performance-schema
May 14, 2026
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0124cb9
PMM-12392 Collect processlist from performance_schema on newer MySQL
4nte 464f8eb
PMM-12392 Check performance_schema is enabled before querying it
4nte 1655e5f
PMM-12392 Group processlist schema constants in single const block
4nte 85eb22a
PMM-12392 Pass context to newInstance and version/perfSchema probes
4nte 0bc9b36
PMM-12392 Fix extraction of mysqld_exporter from tarball
4nte 3da171e
PMM-12392 Drop unsupported exporter flag from benchmark
4nte 6d42a25
PMM-12392 Use `docker compose` instead of deprecated `docker-compose`
4nte 8d4a437
PMM-12392 Pass test exporter credentials via flags instead of DATA_SO…
4nte 20e2d38
PMM-12392 Skip blank lines when parsing exporter flags file
4nte a502077
PMM-12392 Drop unreachable `sql.ErrNoRows` check
4nte 81d38ae
PMM-12392 Remove unused `errors` import
4nte 007f3fe
PMM-12392 Replace `context.Background()` with `t.Context()` in tests
4nte 19caa77
PMM-12392 Improve doc clarity on supported versions
4nte b3137e1
PMM-12392 Add integration test
4nte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Copyright 2018 The Prometheus Authors, 2023 Percona LLC | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package collector | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/DATA-DOG/go-sqlmock" | ||
| "github.com/alecthomas/kingpin/v2" | ||
| "github.com/blang/semver/v4" | ||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/prometheus/common/promslog" | ||
| ) | ||
|
|
||
| func TestPScrapeProcesslistQuerySelection(t *testing.T) { | ||
| if _, err := kingpin.CommandLine.Parse([]string{}); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| cases := []struct { | ||
| name string | ||
| flavor string | ||
| version semver.Version | ||
| perfSchemaEnabled bool | ||
| expectedSchema string | ||
| }{ | ||
| {"MySQL 8.0.22 + PS on -> perf_schema", FlavorMySQL, semver.MustParse("8.0.22"), true, processlistPerfSchema}, | ||
| {"MySQL 8.0.30 + PS on -> perf_schema", FlavorMySQL, semver.MustParse("8.0.30"), true, processlistPerfSchema}, | ||
| {"MySQL 5.7.39 + PS on -> perf_schema", FlavorMySQL, semver.MustParse("5.7.39"), true, processlistPerfSchema}, | ||
| {"MySQL 8.0.22 + PS off -> info_schema", FlavorMySQL, semver.MustParse("8.0.22"), false, processlistInfoSchema}, | ||
| {"MySQL 5.7.39 + PS off -> info_schema", FlavorMySQL, semver.MustParse("5.7.39"), false, processlistInfoSchema}, | ||
| {"MySQL 8.0.21 -> info_schema", FlavorMySQL, semver.MustParse("8.0.21"), true, processlistInfoSchema}, | ||
| {"MySQL 5.7.38 -> info_schema", FlavorMySQL, semver.MustParse("5.7.38"), true, processlistInfoSchema}, | ||
| {"MySQL 8.0.0 -> info_schema", FlavorMySQL, semver.MustParse("8.0.0"), true, processlistInfoSchema}, | ||
| {"MySQL 5.6.50 -> info_schema", FlavorMySQL, semver.MustParse("5.6.50"), true, processlistInfoSchema}, | ||
| {"MariaDB 10.11.0 -> info_schema", FlavorMariaDB, semver.MustParse("10.11.0"), true, processlistInfoSchema}, | ||
| } | ||
|
|
||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| db, mock, err := sqlmock.New() | ||
| if err != nil { | ||
| t.Fatalf("error opening a stub database connection: %s", err) | ||
| } | ||
| defer db.Close() | ||
|
|
||
| inst := &instance{ | ||
| db: db, | ||
| flavor: tc.flavor, | ||
| version: tc.version, | ||
| isPerformanceSchemaEnabled: tc.perfSchemaEnabled, | ||
| } | ||
|
|
||
| expectedSQL := fmt.Sprintf(pInfoSchemaProcesslistQuery, tc.expectedSchema, 0) | ||
| columns := []string{"command", "state", "count", "time"} | ||
| mock.ExpectQuery(sanitizeQuery(expectedSQL)). | ||
| WillReturnRows(sqlmock.NewRows(columns)) | ||
|
|
||
| ch := make(chan prometheus.Metric) | ||
| go func() { | ||
| if err := (PScrapeProcesslist{}).Scrape(t.Context(), inst, ch, promslog.NewNopLogger()); err != nil { | ||
| t.Errorf("error calling Scrape: %s", err) | ||
| } | ||
| close(ch) | ||
| }() | ||
| for range ch { | ||
| } | ||
|
|
||
| if err := mock.ExpectationsWereMet(); err != nil { | ||
| t.Errorf("unfulfilled expectations: %s", err) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.