From 8eda093e1e0e7314ac8bf0137f813156715d0787 Mon Sep 17 00:00:00 2001 From: Cristian Greco Date: Wed, 27 Nov 2024 07:36:52 +0100 Subject: [PATCH] `database_observability`: additional configuration and cleanup - add `query_samples_enabled` argument --- .../database_observability.mysql.md | 8 ++-- .../database_observability/mysql/component.go | 40 ++++++++++--------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/docs/sources/reference/components/database_observability/database_observability.mysql.md b/docs/sources/reference/components/database_observability/database_observability.mysql.md index 2bfc85953e..e51af705f8 100644 --- a/docs/sources/reference/components/database_observability/database_observability.mysql.md +++ b/docs/sources/reference/components/database_observability/database_observability.mysql.md @@ -25,9 +25,10 @@ The following arguments are supported: | Name | Type | Description | Default | Required | | -------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------- | ------- | -------- | -| `data_source_name` | `secret` | [Data Source Name](https://github.com/go-sql-driver/mysql#dsn-data-source-name) for the MySQL server to connect to. | | yes | -| `forward_to` | `list(LogsReceiver)` | Where to forward log entries after processing. | | yes | -| `collect_interval` | `duration` | How frequently to collect query samples from database | `"10s"` | no | +| `data_source_name` | `secret` | [Data Source Name](https://github.com/go-sql-driver/mysql#dsn-data-source-name) for the MySQL server to connect to. | | yes | +| `forward_to` | `list(LogsReceiver)` | Where to forward log entries after processing. | | yes | +| `collect_interval` | `duration` | How frequently to collect information from database | `"10s"` | no | +| `query_samples_enabled` | `bool` | Whether to enable collection of query samples | `true` | no | ## Blocks @@ -67,7 +68,6 @@ loki.write "logs_service" { } } ``` - ## Compatible components diff --git a/internal/component/database_observability/mysql/component.go b/internal/component/database_observability/mysql/component.go index 35ed0d8857..d0832c9cd0 100644 --- a/internal/component/database_observability/mysql/component.go +++ b/internal/component/database_observability/mysql/component.go @@ -47,13 +47,15 @@ var ( ) type Arguments struct { - DataSourceName alloytypes.Secret `alloy:"data_source_name,attr"` - CollectInterval time.Duration `alloy:"collect_interval,attr,optional"` - ForwardTo []loki.LogsReceiver `alloy:"forward_to,attr"` + DataSourceName alloytypes.Secret `alloy:"data_source_name,attr"` + CollectInterval time.Duration `alloy:"collect_interval,attr,optional"` + QuerySamplesEnabled bool `alloy:"query_samples_enabled,attr,optional"` + ForwardTo []loki.LogsReceiver `alloy:"forward_to,attr"` } var DefaultArguments = Arguments{ - CollectInterval: 10 * time.Second, + CollectInterval: 10 * time.Second, + QuerySamplesEnabled: true, } func (a *Arguments) SetToDefault() { @@ -194,21 +196,23 @@ func (c *Component) Update(args component.Arguments) error { entryHandler := loki.NewEntryHandler(c.handler.Chan(), func() {}) - qsCollector, err := collector.NewQuerySample(collector.QuerySampleArguments{ - DB: dbConnection, - CollectInterval: c.args.CollectInterval, - EntryHandler: entryHandler, - Logger: c.opts.Logger, - }) - if err != nil { - level.Error(c.opts.Logger).Log("msg", "failed to create QuerySample collector", "err", err) - return err - } - if err := qsCollector.Start(context.Background()); err != nil { - level.Error(c.opts.Logger).Log("msg", "failed to start QuerySample collector", "err", err) - return err + if c.args.QuerySamplesEnabled { + qsCollector, err := collector.NewQuerySample(collector.QuerySampleArguments{ + DB: dbConnection, + CollectInterval: c.args.CollectInterval, + EntryHandler: entryHandler, + Logger: c.opts.Logger, + }) + if err != nil { + level.Error(c.opts.Logger).Log("msg", "failed to create QuerySample collector", "err", err) + return err + } + if err := qsCollector.Start(context.Background()); err != nil { + level.Error(c.opts.Logger).Log("msg", "failed to start QuerySample collector", "err", err) + return err + } + c.collectors = append(c.collectors, qsCollector) } - c.collectors = append(c.collectors, qsCollector) stCollector, err := collector.NewSchemaTable(collector.SchemaTableArguments{ DB: dbConnection,