Skip to content

Commit

Permalink
database_observability: additional configuration and cleanup
Browse files Browse the repository at this point in the history
- add `query_samples_enabled` argument
  • Loading branch information
cristiangreco committed Nov 27, 2024
1 parent cfad180 commit 8eda093
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -67,7 +68,6 @@ loki.write "logs_service" {
}
}
```

<!-- START GENERATED COMPATIBLE COMPONENTS -->

## Compatible components
Expand Down
40 changes: 22 additions & 18 deletions internal/component/database_observability/mysql/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8eda093

Please sign in to comment.