Skip to content

database_observability: add auto-enable setup consumers to query_sample #3922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

cristiangreco
Copy link
Contributor

PR Description

Introduce a check in the query_sample collector to automatically enable the events_statements_cpu consumer in the performance_schema.setup_consumers table.

This is guarded by two config options:

  • allow_update_performance_schema_settings: to enable "updates" to performance_schema settings altogether.
  • auto_enable_setup_consumers: to start auto-enabling of the setting specific to the query_sample collector.

Which issue(s) this PR fixes

n.a.

Notes to the Reviewer

PR Checklist

  • CHANGELOG.md updated
  • Documentation added
  • Tests updated
  • Config converters updated

@cristiangreco cristiangreco force-pushed the cristian/dbo11y-query-sample-autoenable-cpu-consumer branch from 941c4f7 to 7219121 Compare June 30, 2025 16:01
DataSourceName alloytypes.Secret `alloy:"data_source_name,attr"`
CollectInterval time.Duration `alloy:"collect_interval,attr,optional"`
ForwardTo []loki.LogsReceiver `alloy:"forward_to,attr"`
EnableCollectors []string `alloy:"enable_collectors,attr,optional"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder, (not sure if it's possible), in the future when we have several different setup_consumers we want to configure in a fine-grained manner, will it be easier provide a list to enable/disable similar to EnableCollectors/DisableCollectors?

Might be overengineered, though, so maybe it's better to start with a simple boolean for now that is at the lowest level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm something to think about, but agree to start simple for now as we don't know how widespread this functionality will be.

@fridgepoet
Copy link
Contributor

Should we distinguish because something that "collects" and something that will "write"?

@cristiangreco cristiangreco force-pushed the cristian/dbo11y-query-sample-autoenable-cpu-consumer branch 3 times, most recently from d8e5886 to d5a6d9a Compare July 9, 2025 10:51
Copy link
Contributor

github-actions bot commented Jul 9, 2025

💻 Deploy preview deleted.

@cristiangreco cristiangreco force-pushed the cristian/dbo11y-query-sample-autoenable-cpu-consumer branch from d5a6d9a to eec1c14 Compare July 9, 2025 10:54
@gaantunes
Copy link
Contributor

I wonder if we should create a separate collector that is responsible for maintaining all write operations based on enabled colletors array (taking into account defaults of course). Detaching it would allow a longer scrape period for these operations, instead of checking/writing every time we do a scrape in each collector.

@cristiangreco cristiangreco force-pushed the cristian/dbo11y-query-sample-autoenable-cpu-consumer branch 3 times, most recently from 221ac06 to 623ef02 Compare July 10, 2025 14:37
@cristiangreco
Copy link
Contributor Author

I wonder if we should create a separate collector that is responsible for maintaining all write operations based on enabled colletors array (taking into account defaults of course). Detaching it would allow a longer scrape period for these operations, instead of checking/writing every time we do a scrape in each collector.

Yes I agree the the two things should not be necessarily tied together. I'd prefer to postpone that for a followup PR though if that's ok (so here we first verify this is working and proves valuable, then optimise it).

Comment on lines 195 to 201
if c.autoEnableSetupConsumers {
if err := c.updateSetupConsumersSettings(ctx); err != nil {
return err
}
}

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 commented by @gaantunes we could decouple the update from the regular collector loop. I'm keen to postpone that work for a followup PR, here I'm more interested in the correctness of the approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be inclined to include this now, or atleast tie it to setup_consumers_collect_interval. Running this every minute seems too often

@cristiangreco cristiangreco marked this pull request as ready for review July 11, 2025 08:20
level.Error(c.logger).Log("msg", "failed to get rows affected from performance_schema.setup_consumers", "err", err)
return err
}
level.Debug(c.logger).Log("msg", "updated performance_schema.setup_consumers", "rows_affected", rowsAffected)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we check rows affected = 1? If it's something else, the operation didn't work as expected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rowsAffected == 0 is also fine, it just means it was already enabled (that's why this is just a debug log)


rowsAffected, err := rs.RowsAffected()
if err != nil {
level.Error(c.logger).Log("msg", "failed to get rows affected from performance_schema.setup_consumers", "err", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we going to end up double logging this error? Here and in the ticker loop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll change these to be fmt.Errorf rather than to log here.

Comment on lines 195 to 201
if c.autoEnableSetupConsumers {
if err := c.updateSetupConsumersSettings(ctx); err != nil {
return err
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be inclined to include this now, or atleast tie it to setup_consumers_collect_interval. Running this every minute seems too often

Copy link
Contributor

@clayton-cornell clayton-cornell left a comment

Choose a reason for hiding this comment

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

Approving for docs

Introduce a check in the `query_sample` collector to automatically
enable the `events_statements_cpu` consumer in the
`performance_schema.setup_consumers` table.

This is guarded by two config options:
- `allow_update_performance_schema_settings`: to enable "updates" to
performance_schema settings altogether.
- `auto_enable_setup_consumers`: to start auto-enabling of the setting
specific to the `query_sample` collector.
@cristiangreco cristiangreco force-pushed the cristian/dbo11y-query-sample-autoenable-cpu-consumer branch from 623ef02 to 146397e Compare July 29, 2025 13:56
@cristiangreco cristiangreco merged commit 64165ff into main Jul 30, 2025
41 checks passed
@cristiangreco cristiangreco deleted the cristian/dbo11y-query-sample-autoenable-cpu-consumer branch July 30, 2025 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants