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 ...@@ -20,7 +20,11 @@ class ChaosController < ActionController::Base
end end
def kill def kill
do_chaos :kill, Chaos::KillWorker do_chaos :kill, Chaos::KillWorker, 'KILL'
end
def quit
do_chaos :kill, Chaos::KillWorker, 'QUIT'
end end
def gc def gc
......
...@@ -7,8 +7,8 @@ module Chaos ...@@ -7,8 +7,8 @@ module Chaos
sidekiq_options retry: false sidekiq_options retry: false
def perform def perform(signal)
Gitlab::Chaos.kill Gitlab::Chaos.kill(signal)
end end
end 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 ...@@ -179,6 +179,7 @@ Rails.application.routes.draw do
get :db_spin get :db_spin
get :sleep get :sleep
get :kill get :kill
get :quit
post :gc post :gc
end end
end end
......
...@@ -146,10 +146,10 @@ curl "http://localhost:3000/-/chaos/sleep?duration_s=60&token=secret" ...@@ -146,10 +146,10 @@ curl "http://localhost:3000/-/chaos/sleep?duration_s=60&token=secret"
## Kill ## 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 Because this endpoint uses the `KILL` signal, the process isn't given an
opportunity to cleanup or shutdown. opportunity to clean up or shut down.
```plaintext ```plaintext
GET /-/chaos/kill GET /-/chaos/kill
...@@ -158,13 +158,33 @@ GET /-/chaos/kill?async=true ...@@ -158,13 +158,33 @@ GET /-/chaos/kill?async=true
| Attribute | Type | Required | Description | | 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 ```shell
curl "http://localhost:3000/-/chaos/kill" --header 'X-Chaos-Secret: secret' curl "http://localhost:3000/-/chaos/kill" --header 'X-Chaos-Secret: secret'
curl "http://localhost:3000/-/chaos/kill?token=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 ## Run garbage collector
This endpoint triggers a GC run on the worker handling the request and returns its worker ID This endpoint triggers a GC run on the worker handling the request and returns its worker ID
......
...@@ -43,9 +43,9 @@ module Gitlab ...@@ -43,9 +43,9 @@ module Gitlab
Kernel.sleep(duration_s) Kernel.sleep(duration_s)
end end
# Kill will send a SIGKILL signal to the current process # Kill will send the given signal to the current process.
def self.kill def self.kill(signal)
Process.kill("KILL", Process.pid) Process.kill(signal, Process.pid)
end end
def self.run_gc def self.run_gc
......
...@@ -109,7 +109,7 @@ RSpec.describe ChaosController do ...@@ -109,7 +109,7 @@ RSpec.describe ChaosController do
describe '#kill' do describe '#kill' do
it 'calls synchronously' do it 'calls synchronously' do
expect(Gitlab::Chaos).to receive(:kill).with(no_args) expect(Gitlab::Chaos).to receive(:kill).with('KILL')
get :kill get :kill
...@@ -117,7 +117,7 @@ RSpec.describe ChaosController do ...@@ -117,7 +117,7 @@ RSpec.describe ChaosController do
end end
it 'calls asynchronously' do 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 } get :kill, params: { async: 1 }
...@@ -125,6 +125,24 @@ RSpec.describe ChaosController do ...@@ -125,6 +125,24 @@ RSpec.describe ChaosController do
end end
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 describe '#gc' do
let(:gc_stat) { GC.stat.stringify_keys } 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