Commit b7f6c9e7 authored by 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
parents 8d1e9432 1714c47f
......@@ -20,7 +20,11 @@ class ChaosController < ActionController::Base
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 @@ module Chaos
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 @@ Rails.application.routes.draw do
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 @@ module Gitlab
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 @@ RSpec.describe ChaosController do
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 @@ RSpec.describe ChaosController do
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 @@ RSpec.describe ChaosController do
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 }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment