Skip to content

feat: Database_observability.postgres: support excluding DBs in all collectors#5366

Merged
cristiangreco merged 2 commits intomainfrom
cristian/dbo11y-exclude-pg-databases-all-collectors
Jan 28, 2026
Merged

feat: Database_observability.postgres: support excluding DBs in all collectors#5366
cristiangreco merged 2 commits intomainfrom
cristian/dbo11y-exclude-pg-databases-all-collectors

Conversation

@cristiangreco
Copy link
Contributor

Brief description of Pull Request

Propagate exclude_databases configuration to all PostgreSQL collectors and append the user-defined databases to the default excluded databases.

Additionally, change the behaviour of explain_plans collector to skip queries from excluded databases instead of processing them.

Followup of #5350

Pull Request Details

Issue(s) fixed by this Pull Request

Notes to the Reviewer

PR Checklist

  • Documentation added
  • Tests updated
  • Config converters updated

@cristiangreco cristiangreco force-pushed the cristian/dbo11y-exclude-pg-databases-all-collectors branch 4 times, most recently from ea452a3 to 006566e Compare January 28, 2026 09:58
@cristiangreco cristiangreco changed the title feat: Database_observability.postgres: support excluding schemas in all collectors feat: Database_observability.postgres: support excluding DBs in all collectors Jan 28, 2026
@cristiangreco cristiangreco force-pushed the cristian/dbo11y-exclude-pg-databases-all-collectors branch from 006566e to 51f4afa Compare January 28, 2026 11:22
package collector

import "strings"
import "github.com/grafana/alloy/internal/component/database_observability"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of the code here has been moved to shared sql_exclusion.go

@@ -0,0 +1,84 @@
package database_observability
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests moved here from deleted file exclude_schemas_test.go

@cristiangreco cristiangreco force-pushed the cristian/dbo11y-exclude-pg-databases-all-collectors branch from 51f4afa to 197c84b Compare January 28, 2026 11:26
@cristiangreco cristiangreco marked this pull request as ready for review January 28, 2026 11:31
@cristiangreco cristiangreco requested a review from a team as a code owner January 28, 2026 11:31
var defaultExclusionClause = buildExclusionClause(defaultExcludedSchemas)
var defaultExclusionClause = database_observability.BuildExclusionClause(defaultExcludedSchemas)

func buildExcludedSchemasClause(excludedSchemas []string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this to sql_exclusion given it's pretty generic appending of slices

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As optimisation, the var defaultExclusionClause is precomputed as string and returned by this method, with the default being different for each engine.

We could move everything into sql_exclusion but would need to carry over the engine-specific lists as well in the top package. I don't have a strong preference, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer not to move engine-specifics to top package so let's keep as is. Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I'll leave as-is. (but I've applied the rename you suggested in the other comment)

import "strings"
import "github.com/grafana/alloy/internal/component/database_observability"

var defaultExcludedSchemas = []string{"mysql", "performance_schema", "sys", "information_schema"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var defaultExcludedSchemas = []string{"mysql", "performance_schema", "sys", "information_schema"}
var excludedSchemas = []string{"mysql", "performance_schema", "sys", "information_schema"}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have pushed a second commit with the rename.

var defaultExcludedSchemas = []string{"mysql", "performance_schema", "sys", "information_schema"}

var defaultExclusionClause = buildExclusionClause(defaultExcludedSchemas)
var defaultExclusionClause = database_observability.BuildExclusionClause(defaultExcludedSchemas)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var defaultExclusionClause = database_observability.BuildExclusionClause(defaultExcludedSchemas)
var exclusionClause = database_observability.BuildExclusionClause(defaultExcludedSchemas)

Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments as in internal/component/database_observability/mysql/collector/exclude_schemas.go

…ollectors

Propagate `exclude_databases` configuration to all PostgreSQL collectors
and append the user-defined databases to the default excluded databases.

Additionally, change the behaviour of `explain_plans` collector to skip
queries from excluded databases instead of processing them.

Followup of #5350
@cristiangreco cristiangreco force-pushed the cristian/dbo11y-exclude-pg-databases-all-collectors branch from 197c84b to 9f9fdf8 Compare January 28, 2026 14:26
@cristiangreco cristiangreco merged commit 1fe42db into main Jan 28, 2026
46 checks passed
@cristiangreco cristiangreco deleted the cristian/dbo11y-exclude-pg-databases-all-collectors branch January 28, 2026 14:56
@grafana-alloybot grafana-alloybot bot mentioned this pull request Jan 28, 2026
@ptodev ptodev added the backport/v1.13 Backport to release/v1.13 label Jan 28, 2026
grafana-alloybot bot pushed a commit that referenced this pull request Jan 28, 2026
…ollectors (#5366)

### Brief description of Pull Request
Propagate `exclude_databases` configuration to all PostgreSQL collectors
and append the user-defined databases to the default excluded databases.

Additionally, change the behaviour of `explain_plans` collector to skip
queries from excluded databases instead of processing them.

Followup of #5350

### Pull Request Details

<!-- Add a more detailed descripion of the Pull Request here, if needed.
-->

### Issue(s) fixed by this Pull Request

<!--
Uncomment the following line and fill in an issue number if you want a
GitHub
  issue to be closed automatically when this PR gets merged.
-->

<!-- Fixes #issue_id -->

### Notes to the Reviewer

<!-- Add any relevant notes for the reviewers and testers of this PR.
-->

### PR Checklist

<!-- Remove items that do not apply. For completed items, change [ ] to
[x]. -->

- [ ] Documentation added
- [x] Tests updated
- [ ] Config converters updated

(cherry picked from commit 1fe42db)
ptodev pushed a commit that referenced this pull request Jan 28, 2026
…ollectors [backport] (#5383)

## Backport of #5366

This PR backports #5366 to release/v1.13.

### Original PR Author
@cristiangreco

### Description
### Brief description of Pull Request
Propagate `exclude_databases` configuration to all PostgreSQL collectors
and append the user-defined databases to the default excluded databases.

Additionally, change the behaviour of `explain_plans` collector to skip
queries from excluded databases instead of processing them.

Followup of #5350

### Pull Request Details

<!-- Add a more detailed descripion of the Pull Request here, if needed.
-->

### Issue(s) fixed by this Pull Request

<!--
Uncomment the following line and fill in an issue number if you want a
GitHub
  issue to be closed automatically when this PR gets merged.
-->

<!-- Fixes #issue_id -->

### Notes to the Reviewer

<!-- Add any relevant notes for the reviewers and testers of this PR.
-->

### PR Checklist

<!-- Remove items that do not apply. For completed items, change [ ] to
[x]. -->

- [ ] Documentation added
- [x] Tests updated
- [ ] Config converters updated


---
*This backport was created automatically.*

Co-authored-by: Cristian Greco <cristian@regolo.cc>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

backport/v1.13 Backport to release/v1.13 frozen-due-to-age

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants