Skip to content
代码片段 群组 项目
提交 b7f6c9e7 编辑于 作者: Michael Kozono's avatar Michael Kozono
浏览文件

Merge branch 'mk-chaos-quit' into 'master'

Add a chaos endpoint that signals QUIT

See merge request gitlab-org/gitlab!58755
No related branches found
No related tags found
无相关合并请求
......@@ -20,7 +20,11 @@ def sleep
end
def kill
do_chaos :kill, Chaos::KillWorker
do_chaos :kill, Chaos::KillWorker, 'KILL'
end
def quit
do_chaos :kill, Chaos::KillWorker, 'QUIT'
end
def gc
......
......@@ -7,8 +7,8 @@ class KillWorker # rubocop:disable Scalability/IdempotentWorker
sidekiq_options retry: false
def perform
Gitlab::Chaos.kill
def perform(signal)
Gitlab::Chaos.kill(signal)
end
end
end
---
title: Add a chaos endpoint that signals QUIT
merge_request: 58755
author:
type: changed
......@@ -179,6 +179,7 @@
get :db_spin
get :sleep
get :kill
get :quit
post :gc
end
end
......
......@@ -146,10 +146,10 @@ curl "http://localhost:3000/-/chaos/sleep?duration_s=60&token=secret"
## Kill
This endpoint simulates the unexpected death of a worker process using a `kill` signal.
This endpoint simulates the unexpected death of a worker process using the `KILL` signal.
Because this endpoint uses the `KILL` signal, the worker isn't given an
opportunity to cleanup or shutdown.
Because this endpoint uses the `KILL` signal, the process isn't given an
opportunity to clean up or shut down.
```plaintext
GET /-/chaos/kill
......@@ -158,13 +158,33 @@ GET /-/chaos/kill?async=true
| Attribute | Type | Required | Description |
| ------------ | ------- | -------- | ---------------------------------------------------------------------- |
| `async` | boolean | no | Set to true to kill a Sidekiq background worker process |
| `async` | boolean | no | Set to true to signal a Sidekiq background worker process |
```shell
curl "http://localhost:3000/-/chaos/kill" --header 'X-Chaos-Secret: secret'
curl "http://localhost:3000/-/chaos/kill?token=secret"
```
## Quit
This endpoint simulates the unexpected death of a worker process using the `QUIT` signal.
Unlike `KILL`, the `QUIT` signal will also attempt to write a core dump.
See [core(5)](https://man7.org/linux/man-pages/man5/core.5.html) for more information.
```plaintext
GET /-/chaos/quit
GET /-/chaos/quit?async=true
```
| Attribute | Type | Required | Description |
| ------------ | ------- | -------- | ---------------------------------------------------------------------- |
| `async` | boolean | no | Set to true to signal a Sidekiq background worker process |
```shell
curl "http://localhost:3000/-/chaos/quit" --header 'X-Chaos-Secret: secret'
curl "http://localhost:3000/-/chaos/quit?token=secret"
```
## Run garbage collector
This endpoint triggers a GC run on the worker handling the request and returns its worker ID
......
......@@ -43,9 +43,9 @@ def self.sleep(duration_s)
Kernel.sleep(duration_s)
end
# Kill will send a SIGKILL signal to the current process
def self.kill
Process.kill("KILL", Process.pid)
# Kill will send the given signal to the current process.
def self.kill(signal)
Process.kill(signal, Process.pid)
end
def self.run_gc
......
......@@ -109,7 +109,7 @@
describe '#kill' do
it 'calls synchronously' do
expect(Gitlab::Chaos).to receive(:kill).with(no_args)
expect(Gitlab::Chaos).to receive(:kill).with('KILL')
get :kill
......@@ -117,7 +117,7 @@
end
it 'calls asynchronously' do
expect(Chaos::KillWorker).to receive(:perform_async).with(no_args)
expect(Chaos::KillWorker).to receive(:perform_async).with('KILL')
get :kill, params: { async: 1 }
......@@ -125,6 +125,24 @@
end
end
describe '#quit' do
it 'calls synchronously' do
expect(Gitlab::Chaos).to receive(:kill).with('QUIT')
get :quit
expect(response).to have_gitlab_http_status(:ok)
end
it 'calls asynchronously' do
expect(Chaos::KillWorker).to receive(:perform_async).with('QUIT')
get :quit, params: { async: 1 }
expect(response).to have_gitlab_http_status(:ok)
end
end
describe '#gc' do
let(:gc_stat) { GC.stat.stringify_keys }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册