feat(prometheus.exporter.postgres): Update to version 0.19.0 and expose new collectors settings #4640
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
cbe7c33 to
5c01c78
Compare
5c01c78 to
0d46e2c
Compare
|
💻 Deploy preview available (postgres: add support for stat_statements limit flag): |
0d46e2c to
93c0776
Compare
stat_statements flags
93c0776 to
6ae8ccf
Compare
|
💻 Deploy preview available (feat: Postgres_exporter: update version and add |
stat_statements flagsstat_statements flags
stat_statements flags0.19.0 and add expose new collectors settings
6ae8ccf to
ab0a3f1
Compare
|
💻 Deploy preview available (feat(prometheus.exporter.postgres): Update to version |
88e6ad0 to
3a926f5
Compare
| cfg.ExcludeDatabases, | ||
| dsns[0], | ||
| cfg.EnabledCollectors, | ||
| collector.WithCollectionTimeout("10s"), |
There was a problem hiding this comment.
This last parameter is needed due to a change in upstream signature. We could make it configurable, but I've seen some discussion around the implementation so was a bit hesitant to expose it as an alloy setting for now.
There was a problem hiding this comment.
Could we add this default configuration of a 10s timeout to the documentation if it's not there already?
There was a problem hiding this comment.
Definitely agree with keeping it hidden if it's not clear that the upstream implementation will be stable.
🔍 Dependency ReviewBelow are the dependency changes detected in the provided diffs, along with required code changes (if any), evidence, and example patches to keep behavior consistent. github.com/prometheus/common v0.67.4 -> v0.67.5 — ✅ Safe
Evidence
Action
github.com/prometheus/exporter-toolkit v0.15.0 -> v0.15.1 — ✅ Safe
Evidence
Action
github.com/prometheus-community/postgres_exporter (via replace to github.com/grafana/postgres_exporter) v0.0.0-20250930-c8f6a9f4d363 -> v0.0.0-20260212-d256e52d0faf — ❌ Changes NeededStatus
Summary of changes requiring code updates
Evidence (from the updated code in this PR)
Required code changes (already applied here; ensure they are applied everywhere this exporter is used) A) Replace cmd package usage with exporter package and remove Kingpin hacks - "github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/grafana/alloy/internal/runtime/logging"
...
- "github.com/prometheus-community/postgres_exporter/cmd/postgres_exporter"
"github.com/prometheus-community/postgres_exporter/collector"
+ postgres_exporter "github.com/prometheus-community/postgres_exporter/exporter"B) Update programmatic exporter construction and logger injection - e := postgres_exporter.NewExporter(
- dsns,
- postgres_exporter.DisableDefaultMetrics(cfg.DisableDefaultMetrics),
- postgres_exporter.WithUserQueriesPath(cfg.QueryPath),
- postgres_exporter.DisableSettingsMetrics(cfg.DisableSettingsMetrics),
- postgres_exporter.AutoDiscoverDatabases(cfg.AutodiscoverDatabases),
- postgres_exporter.ExcludeDatabases(cfg.ExcludeDatabases),
- postgres_exporter.IncludeDatabases(strings.Join(cfg.IncludeDatabases, ",")),
- postgres_exporter.WithLogger(logger),
- postgres_exporter.WithMetricPrefix("pg"),
- )
+ e := postgres_exporter.NewExporter(
+ dsns,
+ logger,
+ postgres_exporter.DisableDefaultMetrics(cfg.DisableDefaultMetrics),
+ postgres_exporter.WithUserQueriesPath(cfg.QueryPath),
+ postgres_exporter.DisableSettingsMetrics(cfg.DisableSettingsMetrics),
+ postgres_exporter.AutoDiscoverDatabases(cfg.AutodiscoverDatabases),
+ postgres_exporter.ExcludeDatabases(cfg.ExcludeDatabases),
+ postgres_exporter.IncludeDatabases(strings.Join(cfg.IncludeDatabases, ",")),
+ postgres_exporter.WithMetricPrefix("pg"),
+ )C) Configure per-instance collector options (10s collection timeout + stat_statements config) - // Kingpin flag hacks (remove)
- if cfg.StatStatementFlags != nil && cfg.StatStatementFlags.IncludeQuery {
- includeQueryFlag := kingpin.CommandLine.GetFlag("collector.stat_statements.include_query")
- queryLengthFlag := kingpin.CommandLine.GetFlag("collector.stat_statements.query_length")
- ...
- }
+ // Per-instance collector options
+ collectorOpts := []collector.Option{
+ collector.WithCollectionTimeout("10s"),
+ }
+ if cfg.StatStatementFlags != nil {
+ collectorOpts = append(collectorOpts, collector.WithStatStatementsConfig(collector.StatStatementsConfig{
+ IncludeQuery: cfg.StatStatementFlags.IncludeQuery,
+ QueryLength: cfg.StatStatementFlags.QueryLength,
+ Limit: cfg.StatStatementFlags.Limit,
+ ExcludeDatabases: cfg.StatStatementFlags.ExcludeDatabases,
+ ExcludeUsers: cfg.StatStatementFlags.ExcludeUsers,
+ }))
+ }D) Pass the new collector options to the primary collector - c, err := collector.NewPostgresCollector(logger, cfg.ExcludeDatabases, dsns[0], cfg.EnabledCollectors)
+ c, err := collector.NewPostgresCollector(
+ logger,
+ cfg.ExcludeDatabases,
+ dsns[0],
+ cfg.EnabledCollectors,
+ collectorOpts...,
+ )E) Extend the public config surface for stat_statements flags (internal/component mapping) type StatStatementFlags struct {
- IncludeQuery bool `alloy:"include_query,attr,optional"`
- QueryLength uint `alloy:"query_length,attr,optional"`
+ IncludeQuery bool `alloy:"include_query,attr,optional"`
+ QueryLength uint `alloy:"query_length,attr,optional"`
+ Limit uint `alloy:"limit,attr,optional"`
+ ExcludeDatabases []string `alloy:"exclude_databases,attr,optional"`
+ ExcludeUsers []string `alloy:"exclude_users,attr,optional"`
}
func (s *StatStatementFlags) Convert() *postgres_exporter.StatStatementFlags {
if s == nil {
return nil
}
return &postgres_exporter.StatStatementFlags{
- IncludeQuery: s.IncludeQuery,
- QueryLength: s.QueryLength,
+ IncludeQuery: s.IncludeQuery,
+ QueryLength: s.QueryLength,
+ Limit: s.Limit,
+ ExcludeDatabases: s.ExcludeDatabases,
+ ExcludeUsers: s.ExcludeUsers,
}
}F) Documentation alignment
Notes
Notes
|
90eb87c to
70bc192
Compare
| | Name | Type | Description | Default | Required | | ||
| | ------------------- | -------------- | --------------------------------------------------- | ------- | -------- | | ||
| | `include_query` | `bool` | Enable the selection of query ID and SQL statement. | `false` | no | | ||
| | `query_length` | `number` | Maximum length of the statement query text. | `120` | no | |
There was a problem hiding this comment.
Arguments should be sorted first by required, then alphabetically
There was a problem hiding this comment.
I've applied @clayton-cornell's suggestion, which should address your comment.
| } | ||
| } | ||
| if cfg.StatStatementFlags != nil && cfg.StatStatementFlags.Limit != 0 { | ||
| limitFlag := kingpin.CommandLine.GetFlag("collector.stat_statements.limit") |
There was a problem hiding this comment.
I hadn't seen this used before, does this approach work with multiple instances of the postgres exporter?
There was a problem hiding this comment.
You're right, this can't work correctly for multiple instances. I'll have a look.
There was a problem hiding this comment.
@dehaansa thanks for pointing this out, I realised I hadn't tested Alloy with multiple instances.
I've added a new patch in our fork, building on top of the existing one: grafana/postgres_exporter#29
That patch should allow passing collector parameters without using kingpin flag.
Once reviewed, I'll merge that PR in the branch exporter-toolkit-v0.19.0 and update our deps here.
| cfg.ExcludeDatabases, | ||
| dsns[0], | ||
| cfg.EnabledCollectors, | ||
| collector.WithCollectionTimeout("10s"), |
There was a problem hiding this comment.
Definitely agree with keeping it hidden if it's not clear that the upstream implementation will be stable.
docs/sources/reference/components/prometheus/prometheus.exporter.postgres.md
Show resolved
Hide resolved
|
FYI a recent issue was opened regarding a panic that was fixed in v0.19.0. I imagine this PR will resolve #5502 |
Yes, should be fixed by prometheus-community/postgres_exporter#1252, which is included in v0.19.0 |
f941257 to
bff8bb3
Compare
…expose new collectors settings Update the postgres_exporter to version v0.19.0 (but continue to use our grafana fork). The update adds support for configuring the stat_statements collector flags, including limit, exclude_databases, and exclude_users.
bff8bb3 to
3b500b0
Compare
|
Thanks @cristiangreco, I edited the PR description to state that it will close #5502. |
docs/sources/reference/components/prometheus/prometheus.exporter.postgres.md
Show resolved
Hide resolved
clayton-cornell
left a comment
There was a problem hiding this comment.
Docs are OK - one small non-blocking suggestion
…er.postgres.md Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
0.19.0 and add expose new collectors settings 0.19.0 and expose new collectors settings
|
💻 Deploy preview deleted (feat(prometheus.exporter.postgres): Update to version |
…pose new collectors settings (#4640) #### PR Description Update the `postgres_exporter` to version [v0.19.0](https://github.com/prometheus-community/postgres_exporter/releases/tag/v0.19.0) (but continue to use our [fork](https://github.com/grafana/postgres_exporter/tree/exporter-package-v0.19.0)). The update adds support for configuring the `stat_statements` collector flags, including `limit`, `exclude_databases`, and `exclude_users`. #### Which issue(s) this PR fixes Fixes #5502 #### Notes to the Reviewer #### PR Checklist <!-- Remove items that do not apply. For completed items, change [ ] to [x]. --> - [ ] CHANGELOG.md updated - [x] Documentation added - [ ] Tests updated - [ ] Config converters updated --------- Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
…pose new collectors settings (grafana#4640) #### PR Description Update the `postgres_exporter` to version [v0.19.0](https://github.com/prometheus-community/postgres_exporter/releases/tag/v0.19.0) (but continue to use our [fork](https://github.com/grafana/postgres_exporter/tree/exporter-package-v0.19.0)). The update adds support for configuring the `stat_statements` collector flags, including `limit`, `exclude_databases`, and `exclude_users`. #### Which issue(s) this PR fixes Fixes grafana#5502 #### Notes to the Reviewer #### PR Checklist <!-- Remove items that do not apply. For completed items, change [ ] to [x]. --> - [ ] CHANGELOG.md updated - [x] Documentation added - [ ] Tests updated - [ ] Config converters updated --------- Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
PR Description
Update the
postgres_exporterto version v0.19.0 (but continue to use our fork).The update adds support for configuring the
stat_statementscollector flags, includinglimit,exclude_databases, andexclude_users.Which issue(s) this PR fixes
Fixes #5502
Notes to the Reviewer
PR Checklist