Fix regex match in StatActivitySampler
What does this MR do and why?
The marginalia sampler has recently changed with correlation_id now having a dash - character in it. This makes the StatActivitySampler used by sidekiq circuit breaker to break.
The fix here follows the regexp in gitlab-cookbooks/gitlab-exporters!369 (merged)
References
gitlab-com/gl-infra/data-access/durability/team#291
gitlab-com/gl-infra/data-access/dbo/dbo-issue-tracker#615
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
Previous regex:
[16] pry(main)> ApplicationRecord.connection.execute("SELECT REGEXP_MATCHES('/*application:sidekiq,correlation_id:3dd281c5a2d8d8702f7288b7540b5735-ATL,jid:ac79c221a614370699d4cbff,endpoint_id:Chaos::DbSleepWorker,db_config_database:gitlabhq_development,db_config_name:main,line:/lib/gitlab/chaos.rb:50:in `db_sleep''*/ SELECT PG_SLEEP(20)', '^\\s*(?:\\/\\*(?:application:(\\w+),?)?(?:correlation_id:\\w+,?)?(?:jid:\\w+,?)?(?:endpoint_id:([\\w/\\-\\.:\\\#\\s]+),?)?(?:db_config_database:(\\w+),?)?.*?\\*\\/)?\\s*(\\w+)')").values
(1.4ms) /*application:console,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:gmarco--20220725-2D7YR,console_username:gregoriusmarco,line:(pry):16:in `__pry__'*/ SELECT REGEXP_MATCHES('/*application:sidekiq,correlation_id:3dd281c5a2d8d8702f7288b7540b5735-ATL,jid:ac79c221a614370699d4cbff,endpoint_id:Chaos::DbSleepWorker,db_config_database:gitlabhq_development,db_config_name:main,line:/lib/gitlab/chaos.rb:50:in `db_sleep''*/ SELECT PG_SLEEP(20)', '^\s*(?:\/\*(?:application:(\w+),?)?(?:correlation_id:\w+,?)?(?:jid:\w+,?)?(?:endpoint_id:([\w/\-\.:\#\s]+),?)?(?:db_config_database:(\w+),?)?.*?\*\/)?\s*(\w+)')
=> [["{sidekiq,NULL,NULL,SELECT}"]]
Now:
[15] pry(main)> ApplicationRecord.connection.execute("SELECT REGEXP_MATCHES('/*application:sidekiq,correlation_id:3dd281c5a2d8d8702f7288b7540b5735-ATL,jid:ac79c221a614370699d4cbff,endpoint_id:Chaos::DbSleepWorker,db_config_database:gitlabhq_development,db_config_name:main,line:/lib/gitlab/chaos.rb:50:in `db_sleep''*/ SELECT PG_SLEEP(20)', '^\\s*(?:\\/\\*(?:application:(\\w+),?)?(?:correlation_id:[\\w\\-]+,?)?(?:jid:\\w+,?)?(?:endpoint_id:([\\w/\\-\\.:\\\#\\s]+),?)?(?:db_config_database:(\\w+),?)?.*?\\*\\/)?\\s*(\\w+)')").values
(0.8ms) /*application:console,db_config_database:gitlabhq_development,db_config_name:main,console_hostname:gmarco--20220725-2D7YR,console_username:gregoriusmarco,line:(pry):15:in `__pry__'*/ SELECT REGEXP_MATCHES('/*application:sidekiq,correlation_id:3dd281c5a2d8d8702f7288b7540b5735-ATL,jid:ac79c221a614370699d4cbff,endpoint_id:Chaos::DbSleepWorker,db_config_database:gitlabhq_development,db_config_name:main,line:/lib/gitlab/chaos.rb:50:in `db_sleep''*/ SELECT PG_SLEEP(20)', '^\s*(?:\/\*(?:application:(\w+),?)?(?:correlation_id:[\w\-]+,?)?(?:jid:\w+,?)?(?:endpoint_id:([\w/\-\.:\#\s]+),?)?(?:db_config_database:(\w+),?)?.*?\*\/)?\s*(\w+)')
=> [["{sidekiq,Chaos::DbSleepWorker,gitlabhq_development,SELECT}"]]
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Marco Gregorius