cockroachdb / cockroachdb/cockroach
Add eventpb.SampledQuery to event exporter
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
The goal is to [export an event](https://github.com/cockroachdb/cockroach/blob/65cc2617a9e1cd66471edf86671d283e20ec0a0c/pkg/sql/event_log.go#L675) with all the data used compute the StatementStatistics. The existing [SampledQuery](https://github.com/cockroachdb/cockroach/blob/65cc2617a9e1cd66471edf86671d283e20ec0a0c/pkg/util/log/eventpb/telemetry.proto#L33) event already contains almost all the necessary information. The additional export can be added where the[ existing sample query](https://github.com/cockroachdb/cockroach/blob/65cc2617a9e1cd66471edf86671d283e20ec0a0c/pkg/sql/exec_log.go#L401) is logged. The new event type will need to be [added and registered for the exporter](https://github.com/cockroachdb/cockroach/blob/946d774e1fc36f7573033f473283266a06b69b1b/pkg/obs/event_exporter.go#L214-L221).
A new cluster setting should be added with it disabled by default. This avoids any possible issues with the additional export.
Additional notes:
1. `SampledQuery` is only emitted if [sql.telemetry.query_sampling.enabled](https://github.com/cockroachdb/cockroach/blob/65cc2617a9e1cd66471edf86671d283e20ec0a0c/pkg/sql/exec_log.go#L90C3-L90C39) is enabled
2. The event is only emitted in the following scenarios.
a. Last event logged was over 200ms ago. Configured via [sql.telemetry.query_sampling.max_event_frequency](https://github.com/cockroachdb/cockroach/blob/92d5d0e329e1ed2d923c5ff2116fac9813e4dac5/pkg/sql/telemetry_logging.go#L30C3-L30C51) which defaults to 10 logs a seconds.
b. The statement is always logged if it is not [TypeDML](https://github.com/cockroachdb/cockroach/blob/65cc2617a9e1cd66471edf86671d283e20ec0a0c/pkg/sql/exec_log.go#L284C6-L284C48) or tracing is enabled.
3. All the execution statistics like contention events are only available for statements when tracing enabled.
Jira issue: CRDB-36029
Contributor guide
Assessment
This issue has not been assessed yet.