Skip to content

Commit ed5bd18

Browse files
committed
feat(database_observability): update default excluded schemas and users
Exclude by default well known databases/schemas and users from cloud providers.
1 parent f30d9ae commit ed5bd18

File tree

7 files changed

+87
-7
lines changed

7 files changed

+87
-7
lines changed

docs/sources/reference/components/database_observability/database_observability.mysql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ You can use the following arguments with `database_observability.mysql`:
3434
| `targets` | `list(map(string))` | List of external targets to scrape. | | no |
3535
| `disable_collectors` | `list(string)` | A list of collectors to disable from the default set. | | no |
3636
| `enable_collectors` | `list(string)` | A list of collectors to enable on top of the default set. | | no |
37-
| `exclude_schemas` | `list(string)` | A list of schemas to exclude from monitoring. | | no |
37+
| `exclude_schemas` | `list(string)` | A list of schemas to exclude from monitoring. | `["alloydbadmin", "alloydbmetadata", "azure_maintenance", "azure_sys", "cloudsqladmin", "rdsadmin"]` | no |
3838
| `allow_update_performance_schema_settings` | `boolean` | Whether to allow updates to `performance_schema` settings in any collector. Enable this in conjunction with other collector-specific settings where required. | `false` | no |
3939

4040
The following collectors are configurable:

docs/sources/reference/components/database_observability/database_observability.postgres.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ You can use the following arguments with `database_observability.postgres`:
3434
| `targets` | `list(map(string))` | List of external targets to scrape for Prometheus metrics. | | no |
3535
| `disable_collectors` | `list(string)` | A list of collectors to disable from the default set. | | no |
3636
| `enable_collectors` | `list(string)` | A list of collectors to enable on top of the default set. | | no |
37-
| `exclude_databases` | `list(string)` | A list of databases to exclude from monitoring. | | no |
38-
| `exclude_users` | `list(string)` | A list of users to exclude from monitoring. | | no |
37+
| `exclude_databases` | `list(string)` | A list of databases to exclude from monitoring. | `["alloydbadmin", "alloydbmetadata", "azure_maintenance", "azure_sys", "cloudsqladmin", "rdsadmin"]` | no |
38+
| `exclude_users` | `list(string)` | A list of users to exclude from monitoring. | `["azuresu", "cloudsqladmin", "db-o11y", "rdsadmin"]` | no |
3939

4040
[Data Source Name]: https://pkg.go.dev/github.com/lib/pq#hdr-URL_connection_strings-NewConfig
4141

internal/component/database_observability/mysql/component.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (a *PrometheusExporterArguments) Validate() error {
163163
}
164164

165165
var DefaultArguments = Arguments{
166-
ExcludeSchemas: []string{},
166+
ExcludeSchemas: database_observability.DefaultExcludedSchemas(),
167167
AllowUpdatePerfSchemaSettings: false,
168168

169169
QueryDetailsArguments: QueryDetailsArguments{

internal/component/database_observability/mysql/component_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ import (
2828
"github.com/grafana/loki/pkg/push"
2929
)
3030

31+
func Test_defaultExclusions(t *testing.T) {
32+
exampleDBO11yAlloyConfig := `
33+
data_source_name = ""
34+
forward_to = []
35+
targets = []
36+
`
37+
38+
var args Arguments
39+
err := syntax.Unmarshal([]byte(exampleDBO11yAlloyConfig), &args)
40+
require.NoError(t, err)
41+
42+
assert.Equal(t, []string{
43+
"rdsadmin",
44+
"cloudsqladmin",
45+
"azure_sys",
46+
"azure_maintenance",
47+
"alloydbadmin",
48+
"alloydbmetadata",
49+
}, args.ExcludeSchemas)
50+
}
51+
3152
func Test_disableQueryRedaction(t *testing.T) {
3253
t.Run("enable sql text when provided", func(t *testing.T) {
3354
exampleDBO11yAlloyConfig := `

internal/component/database_observability/postgres/component.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ type SchemaDetailsArguments struct {
121121
}
122122

123123
var DefaultArguments = Arguments{
124-
ExcludeDatabases: []string{},
125-
ExcludeUsers: []string{},
124+
ExcludeDatabases: database_observability.DefaultExcludedDatabases(),
125+
ExcludeUsers: database_observability.DefaultExcludedUsers(),
126126
QuerySampleArguments: QuerySampleArguments{
127127
CollectInterval: 15 * time.Second,
128128
DisableQueryRedaction: false,

internal/component/database_observability/postgres/component_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,34 @@ func newTestComponent(t *testing.T, openSQL func(string, string) (*sql.DB, error
6363
return c
6464
}
6565

66+
func Test_defaultExclusions(t *testing.T) {
67+
exampleDBO11yAlloyConfig := `
68+
data_source_name = "postgres://db"
69+
forward_to = []
70+
targets = []
71+
`
72+
73+
var args Arguments
74+
err := syntax.Unmarshal([]byte(exampleDBO11yAlloyConfig), &args)
75+
require.NoError(t, err)
76+
77+
assert.Equal(t, []string{
78+
"rdsadmin",
79+
"cloudsqladmin",
80+
"azure_sys",
81+
"azure_maintenance",
82+
"alloydbadmin",
83+
"alloydbmetadata",
84+
}, args.ExcludeDatabases)
85+
86+
assert.Equal(t, []string{
87+
"db-o11y",
88+
"rdsadmin",
89+
"cloudsqladmin",
90+
"azuresu",
91+
}, args.ExcludeUsers)
92+
}
93+
6694
func Test_enableOrDisableCollectors(t *testing.T) {
6795
t.Run("nothing specified (default behavior)", func(t *testing.T) {
6896
exampleDBO11yAlloyConfig := `

internal/component/database_observability/sql_exclusion.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
package database_observability
22

3-
import "strings"
3+
import (
4+
"slices"
5+
"strings"
6+
)
7+
8+
var defaultExcludedSchemas = []string{
9+
"alloydbadmin",
10+
"alloydbmetadata",
11+
"azure_maintenance",
12+
"azure_sys",
13+
"cloudsqladmin",
14+
"rdsadmin",
15+
}
16+
17+
var defaultExcludedUsers = []string{
18+
"azuresu",
19+
"cloudsqladmin",
20+
"db-o11y", // default recommended user
21+
"rdsadmin",
22+
}
23+
24+
func DefaultExcludedDatabases() []string {
25+
return slices.Clone(defaultExcludedSchemas)
26+
}
27+
28+
func DefaultExcludedSchemas() []string {
29+
return slices.Clone(defaultExcludedSchemas)
30+
}
31+
32+
func DefaultExcludedUsers() []string {
33+
return slices.Clone(defaultExcludedUsers)
34+
}
435

536
// BuildExclusionClause builds a SQL IN clause from a list of items.
637
func BuildExclusionClause(items []string) string {

0 commit comments

Comments
 (0)