Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ labels:
database_observability.mysql "<LABEL>" {
data_source_name = <DATA_SOURCE_NAME>
forward_to = [<LOKI_RECEIVERS>]
targets = "<TARGET_LIST>"
}
```

Expand Down Expand Up @@ -139,9 +140,10 @@ The `aws` block supplies the [ARN](https://docs.aws.amazon.com/IAM/latest/UserGu
```alloy
database_observability.mysql "orders_db" {
data_source_name = "user:pass@tcp(mysql:3306)/"
forward_to = [loki.write.logs_service.receiver]
forward_to = [loki.relabel.orders_db.receiver]
targets = prometheus.exporter.mysql.orders_db.targets

enable_collectors = ["query_samples"]
enable_collectors = ["query_samples", "explain_plans"]

cloud_provider {
aws {
Expand All @@ -150,9 +152,39 @@ database_observability.mysql "orders_db" {
}
}

prometheus.scrape "orders_db" {
prometheus.exporter.mysql "orders_db" {
data_source_name = "user:pass@tcp(mysql:3306)/"
enable_collectors = ["perf_schema.eventsstatements"]
}

loki.relabel "orders_db" {
forward_to = [loki.write.logs_service.receiver]
rule {
target_label = "job"
replacement = "integrations/db-o11y"
}
rule {
target_label = "instance"
replacement = "orders_db"
}
}

discovery.relabel "orders_db" {
targets = database_observability.mysql.orders_db.targets
honor_labels = true // required to keep job and instance labels

rule {
target_label = "job"
replacement = "integrations/db-o11y"
}
rule {
target_label = "instance"
replacement = "orders_db"
}
}

prometheus.scrape "orders_db" {
targets = discovery.relabel.orders_db.targets
job_name = "integrations/db-o11y"
forward_to = [prometheus.remote_write.metrics_service.receiver]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ labels:
database_observability.postgres "<LABEL>" {
data_source_name = <DATA_SOURCE_NAME>
forward_to = [<LOKI_RECEIVERS>]
targets = "<TARGET_LIST>"
}
```

Expand Down Expand Up @@ -116,9 +117,11 @@ The `aws` block supplies the [ARN](https://docs.aws.amazon.com/IAM/latest/UserGu

```alloy
database_observability.postgres "orders_db" {
data_source_name = "postgres://user:pass@localhost:5432/mydb"
forward_to = [loki.write.logs_service.receiver]
enable_collectors = ["query_details", "query_samples", "schema_details"]
data_source_name = "postgres://user:pass@localhost:5432/dbname"
forward_to = [loki.relabel.orders_db.receiver]
targets = prometheus.exporter.postgres.orders_db.targets

enable_collectors = ["query_samples", "explain_plans"]

cloud_provider {
aws {
Expand All @@ -127,9 +130,39 @@ database_observability.postgres "orders_db" {
}
}

prometheus.scrape "orders_db" {
prometheus.exporter.postgres "orders_db" {
data_source_name = "postgres://user:pass@localhost:5432/dbname"
enabled_collectors = ["stat_statements"]
}

loki.relabel "orders_db" {
forward_to = [loki.write.logs_service.receiver]
rule {
target_label = "job"
replacement = "integrations/db-o11y"
}
rule {
target_label = "instance"
replacement = "orders_db"
}
}

discovery.relabel "orders_db" {
targets = database_observability.postgres.orders_db.targets
honor_labels = true // required to keep job and instance labels

rule {
target_label = "job"
replacement = "integrations/db-o11y"
}
rule {
target_label = "instance"
replacement = "orders_db"
}
}

prometheus.scrape "orders_db" {
targets = discovery.relabel.orders_db.targets
job_name = "integrations/db-o11y"
forward_to = [prometheus.remote_write.metrics_service.receiver]
}

Expand Down
4 changes: 2 additions & 2 deletions internal/component/database_observability/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ local.file "mysql_secret_<your_DB_name>" {

prometheus.exporter.mysql "integrations_mysqld_exporter_<your_DB_name>" {
data_source_name = local.file.mysql_secret_<your_DB_name>.content
enable_collectors = ["perf_schema.eventsstatements", "perf_schema.eventswaits"]
enable_collectors = ["perf_schema.eventsstatements"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ported from #4666, to keep README and docs in sync.

}

database_observability.mysql "mysql_<your_DB_name>" {
Expand Down Expand Up @@ -510,7 +510,7 @@ loki.relabel "database_observability_postgres_<your_DB_name>" {
}

discovery.relabel "database_observability_postgres_<your_DB_name>" {
targets = concat(prometheus.exporter.postgres.integrations_postgres_exporter_<your_DB_name>.targets, database_observability.postgres.postgres_<your_DB_name>.targets)
targets = database_observability.postgres.postgres_<your_DB_name>.targets
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Drive-by fix.


rule {
target_label = "job"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var (
type Arguments struct {
DataSourceName alloytypes.Secret `alloy:"data_source_name,attr"`
ForwardTo []loki.LogsReceiver `alloy:"forward_to,attr"`
Targets []discovery.Target `alloy:"targets,attr,optional"`
Targets []discovery.Target `alloy:"targets,attr"`
EnableCollectors []string `alloy:"enable_collectors,attr,optional"`
DisableCollectors []string `alloy:"disable_collectors,attr,optional"`
AllowUpdatePerfSchemaSettings bool `alloy:"allow_update_performance_schema_settings,attr,optional"`
Expand Down
27 changes: 12 additions & 15 deletions internal/component/database_observability/mysql/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ import (
"github.com/grafana/loki/pkg/push"
)

func Test_collectSQLText(t *testing.T) {
func Test_disableQueryRedaction(t *testing.T) {
t.Run("enable sql text when provided", func(t *testing.T) {
t.Parallel()

Comment on lines -29 to -30
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 removed t.Parallel() in these tests as the syntax parser is not safe to use in multiple goroutines. It's the first time I see CI failures related to this issue, maybe it was just flaky before.

exampleDBO11yAlloyConfig := `
data_source_name = ""
forward_to = []
targets = []
query_samples {
disable_query_redaction = true
}
Expand All @@ -44,11 +43,10 @@ func Test_collectSQLText(t *testing.T) {
})

t.Run("disable sql text when not provided (default behavior)", func(t *testing.T) {
t.Parallel()

exampleDBO11yAlloyConfig := `
data_source_name = ""
forward_to = []
targets = []
`

var args Arguments
Expand All @@ -59,11 +57,10 @@ func Test_collectSQLText(t *testing.T) {
})

t.Run("setup consumers scrape interval is correctly parsed from config", func(t *testing.T) {
t.Parallel()

exampleDBO11yAlloyConfig := `
data_source_name = ""
forward_to = []
targets = []
setup_consumers {
collect_interval = "1h"
}
Expand All @@ -79,11 +76,10 @@ func Test_collectSQLText(t *testing.T) {

func Test_parseCloudProvider(t *testing.T) {
t.Run("parse cloud provider block", func(t *testing.T) {
t.Parallel()

exampleDBO11yAlloyConfig := `
data_source_name = ""
forward_to = []
targets = []
cloud_provider {
aws {
arn = "arn:aws:rds:some-region:some-account:db:some-db-instance"
Expand All @@ -98,11 +94,10 @@ func Test_parseCloudProvider(t *testing.T) {
assert.Equal(t, "arn:aws:rds:some-region:some-account:db:some-db-instance", args.CloudProvider.AWS.ARN)
})
t.Run("empty cloud provider block", func(t *testing.T) {
t.Parallel()

exampleDBO11yAlloyConfig := `
data_source_name = ""
forward_to = []
targets = []
`

var args Arguments
Expand All @@ -118,6 +113,7 @@ func Test_enableOrDisableCollectors(t *testing.T) {
exampleDBO11yAlloyConfig := `
data_source_name = ""
forward_to = []
targets = []
`

var args Arguments
Expand All @@ -140,6 +136,7 @@ func Test_enableOrDisableCollectors(t *testing.T) {
exampleDBO11yAlloyConfig := `
data_source_name = ""
forward_to = []
targets = []
enable_collectors = ["query_details", "schema_details", "query_samples", "setup_consumers", "explain_plans", "locks"]
`

Expand All @@ -163,6 +160,7 @@ func Test_enableOrDisableCollectors(t *testing.T) {
exampleDBO11yAlloyConfig := `
data_source_name = ""
forward_to = []
targets = []
disable_collectors = ["query_details", "schema_details", "query_samples", "setup_consumers", "explain_plans"]
`

Expand All @@ -186,6 +184,7 @@ func Test_enableOrDisableCollectors(t *testing.T) {
exampleDBO11yAlloyConfig := `
data_source_name = ""
forward_to = []
targets = []
disable_collectors = ["query_details", "schema_details", "query_samples", "setup_consumers", "explain_plans", "locks"]
enable_collectors = ["query_details", "schema_details", "query_samples", "setup_consumers", "explain_plans", "locks"]
`
Expand All @@ -210,6 +209,7 @@ func Test_enableOrDisableCollectors(t *testing.T) {
exampleDBO11yAlloyConfig := `
data_source_name = ""
forward_to = []
targets = []
disable_collectors = ["schema_details", "query_samples", "setup_consumers", "explain_plans", "locks"]
enable_collectors = ["query_details"]
`
Expand All @@ -234,6 +234,7 @@ func Test_enableOrDisableCollectors(t *testing.T) {
exampleDBO11yAlloyConfig := `
data_source_name = ""
forward_to = []
targets = []
enable_collectors = ["some_string"]
disable_collectors = ["another_string"]
`
Expand Down Expand Up @@ -288,8 +289,6 @@ func Test_addLokiLabels(t *testing.T) {
// TestMySQL_Update_DBUnavailable_ReportsUnhealthy tests that the component does not return an error when the database is unavailable,
// but reports unhealthy with the error message from the database.
func TestMySQL_Update_DBUnavailable_ReportsUnhealthy(t *testing.T) {
t.Parallel()

args := Arguments{DataSourceName: "user:pass@tcp(127.0.0.1:1)/db"}
opts := cmp.Options{
ID: "test.mysql",
Expand All @@ -308,8 +307,6 @@ func TestMySQL_Update_DBUnavailable_ReportsUnhealthy(t *testing.T) {
// TestMySQL_StartCollectors_ReportsUnhealthy_StackedErrors tests that the component tries to start collectors on a best effort basis,
// reports unhealthy stacking errors for the collectors that failed to start and generate metrics for the collectors that started successfully.
func TestMySQL_StartCollectors_ReportsUnhealthy_StackedErrors(t *testing.T) {
t.Parallel()

args := Arguments{
DataSourceName: "user:pass@tcp(127.0.0.1:3306)/db",
DisableCollectors: []string{"query_details", "schema_details", "setup_consumers", "explain_plans"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var (
type Arguments struct {
DataSourceName alloytypes.Secret `alloy:"data_source_name,attr"`
ForwardTo []loki.LogsReceiver `alloy:"forward_to,attr"`
Targets []discovery.Target `alloy:"targets,attr,optional"`
Targets []discovery.Target `alloy:"targets,attr"`
EnableCollectors []string `alloy:"enable_collectors,attr,optional"`
DisableCollectors []string `alloy:"disable_collectors,attr,optional"`

Expand Down
Loading