forked from prometheus-community/postgres_exporter
-
Notifications
You must be signed in to change notification settings - Fork 13
PMM-14368 PostgreSQL 18 support #336
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
Open
artemgavrilov
wants to merge
16
commits into
main
Choose a base branch
from
PMM-14368-pg18-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f0e2a72
PMM-7 Add PostgreSQL 18 support with new metrics and collectors
BupycHuk 48cba6b
PMM-7 Update collector tests and queries for PostgreSQL 18 compatibility
BupycHuk 46c388e
Update CI matrix
artemgavrilov 0c02c5a
Refactor pg_stat_database collector
artemgavrilov daf03c4
Fix pg_stat_bgwriter collector
artemgavrilov d34127c
Fix pg_stat_user_tables collector
artemgavrilov fd5646d
Fix pg_stat_io collector
artemgavrilov fd9a56d
Cleanup
artemgavrilov 858e45e
Format
artemgavrilov 26b1189
Fix linter warning
artemgavrilov 949b21e
Refactor custom queries
artemgavrilov 939ec72
Update changelog
artemgavrilov c0fce30
Update readme
artemgavrilov e56fa27
Revert
artemgavrilov 9a4c187
Refactoring
artemgavrilov d21e5e5
Fix
artemgavrilov 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ import ( | |||||
| "context" | ||||||
| "database/sql" | ||||||
|
|
||||||
| "github.com/blang/semver/v4" | ||||||
| "github.com/go-kit/log" | ||||||
| "github.com/go-kit/log/level" | ||||||
| "github.com/prometheus/client_golang/prometheus" | ||||||
|
|
@@ -206,6 +207,24 @@ var ( | |||||
| []string{"datid", "datname"}, | ||||||
| prometheus.Labels{}, | ||||||
| ) | ||||||
| statDatabaseParallelWorkersToLaunch = prometheus.NewDesc(prometheus.BuildFQName( | ||||||
| namespace, | ||||||
| statDatabaseSubsystem, | ||||||
| "parallel_workers_to_launch", | ||||||
| ), | ||||||
| "Number of parallel workers to launch (PostgreSQL 18+)", | ||||||
| []string{"datid", "datname"}, | ||||||
| prometheus.Labels{}, | ||||||
| ) | ||||||
| statDatabaseParallelWorkersLaunched = prometheus.NewDesc(prometheus.BuildFQName( | ||||||
| namespace, | ||||||
| statDatabaseSubsystem, | ||||||
| "parallel_workers_launched", | ||||||
| ), | ||||||
| "Number of parallel workers launched (PostgreSQL 18+)", | ||||||
| []string{"datid", "datname"}, | ||||||
| prometheus.Labels{}, | ||||||
| ) | ||||||
|
|
||||||
| statDatabaseQuery = ` | ||||||
| SELECT | ||||||
|
|
@@ -228,15 +247,22 @@ var ( | |||||
| ,blk_read_time | ||||||
| ,blk_write_time | ||||||
| ,stats_reset | ||||||
| CASE WHEN current_setting('server_version_num')::int >= 180000 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| THEN parallel_workers_to_launch | ||||||
| ELSE NULL END as parallel_workers_to_launch | ||||||
| CASE WHEN current_setting('server_version_num')::int >= 180000 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| THEN parallel_workers_launched | ||||||
| ELSE NULL END as parallel_workers_launched | ||||||
| FROM pg_stat_database; | ||||||
| ` | ||||||
| ) | ||||||
|
|
||||||
| func (c *PGStatDatabaseCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error { | ||||||
| db := instance.getDB() | ||||||
| rows, err := db.QueryContext(ctx, | ||||||
| statDatabaseQuery, | ||||||
| ) | ||||||
|
|
||||||
| after18 := instance.version.GTE(semver.Version{Major: 18}) | ||||||
|
|
||||||
| rows, err := db.QueryContext(ctx, statDatabaseQuery) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
|
|
@@ -246,6 +272,7 @@ func (c *PGStatDatabaseCollector) Update(ctx context.Context, instance *instance | |||||
| var datid, datname sql.NullString | ||||||
| var numBackends, xactCommit, xactRollback, blksRead, blksHit, tupReturned, tupFetched, tupInserted, tupUpdated, tupDeleted, conflicts, tempFiles, tempBytes, deadlocks, blkReadTime, blkWriteTime sql.NullFloat64 | ||||||
| var statsReset sql.NullTime | ||||||
| var parallelWorkersToLaunch, parallelWorkersLaunched sql.NullFloat64 | ||||||
|
|
||||||
| err := rows.Scan( | ||||||
| &datid, | ||||||
|
|
@@ -267,6 +294,8 @@ func (c *PGStatDatabaseCollector) Update(ctx context.Context, instance *instance | |||||
| &blkReadTime, | ||||||
| &blkWriteTime, | ||||||
| &statsReset, | ||||||
| ¶llelWorkersToLaunch, | ||||||
| ¶llelWorkersLaunched, | ||||||
| ) | ||||||
| if err != nil { | ||||||
| return err | ||||||
|
|
@@ -353,6 +382,18 @@ func (c *PGStatDatabaseCollector) Update(ctx context.Context, instance *instance | |||||
| statsResetMetric = float64(statsReset.Time.Unix()) | ||||||
| } | ||||||
|
|
||||||
| if after18 { | ||||||
| if !parallelWorkersToLaunch.Valid { | ||||||
| level.Debug(c.log).Log("msg", "Skipping collecting metric because it has no parallel_workers_to_launch") | ||||||
| continue | ||||||
| } | ||||||
|
|
||||||
| if !parallelWorkersLaunched.Valid { | ||||||
| level.Debug(c.log).Log("msg", "Skipping collecting metric because it has no parallel_workers_launched") | ||||||
| continue | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| labels := []string{datid.String, datname.String} | ||||||
|
|
||||||
| ch <- prometheus.MustNewConstMetric( | ||||||
|
|
@@ -473,6 +514,22 @@ func (c *PGStatDatabaseCollector) Update(ctx context.Context, instance *instance | |||||
| statsResetMetric, | ||||||
| labels..., | ||||||
| ) | ||||||
|
|
||||||
| if after18 { | ||||||
| ch <- prometheus.MustNewConstMetric( | ||||||
| statDatabaseParallelWorkersToLaunch, | ||||||
| prometheus.CounterValue, | ||||||
| parallelWorkersToLaunch.Float64, | ||||||
| labels..., | ||||||
| ) | ||||||
|
|
||||||
| ch <- prometheus.MustNewConstMetric( | ||||||
| statDatabaseParallelWorkersLaunched, | ||||||
| prometheus.CounterValue, | ||||||
| parallelWorkersLaunched.Float64, | ||||||
| labels..., | ||||||
| ) | ||||||
| } | ||||||
| } | ||||||
| return nil | ||||||
| } | ||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.