summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Newdigate <andrew@gitlab.com>2018-11-01 13:16:21 +0000
committerAndrew Newdigate <andrew@gitlab.com>2018-11-01 13:16:21 +0000
commit83dc8f1c666419434a23e467508061b6897fdfb6 (patch)
tree533374d31f79a3a2742edbeb87e12502cef035e7
parentcfe3cfb370ca112c5cab2af3550cf68c2ec6042d (diff)
downloadgitlab-ce-83dc8f1c666419434a23e467508061b6897fdfb6.tar.gz
Leak memory, spin cpu and kill the process
-rw-r--r--app/controllers/chaos_controller.rb23
-rw-r--r--config/routes.rb3
2 files changed, 26 insertions, 0 deletions
diff --git a/app/controllers/chaos_controller.rb b/app/controllers/chaos_controller.rb
index ff0ec75f39a..bdb99995532 100644
--- a/app/controllers/chaos_controller.rb
+++ b/app/controllers/chaos_controller.rb
@@ -1,9 +1,32 @@
# frozen_string_literal: true
class ChaosController < ActionController::Base
+ def leakmem
+ memory_mb = params[:memory_mb] ? params[:memory_mb].to_i : 100
+ retainer = []
+
+ memory_mb.times { retainer << "x" * (1024 * 1024) }
+ render text: "OK", content_type: 'text/plain'
+ end
+
+ def cpuspin
+ duration_s = params[:duration_s] ? params[:duration_s].to_i : 30
+ end_time = Time.now + duration_s.seconds;
+ while Time.now < end_time
+ 10_000.times { }
+ end
+
+ render text: "OK", content_type: 'text/plain'
+ end
+
def sleep
duration_s = params[:duration_s] ? params[:duration_s].to_i : 30
Kernel.sleep duration_s
render text: "OK", content_type: 'text/plain'
end
+
+ def kill
+ Process.kill("KILL", Process.pid)
+ end
+
end
diff --git a/config/routes.rb b/config/routes.rb
index 4764b85cc30..d214356f3e9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -83,7 +83,10 @@ Rails.application.routes.draw do
draw :operations
draw :instance_statistics
+ get '/chaos/leakmem' => 'chaos#leakmem'
+ get '/chaos/cpuspin' => 'chaos#cpuspin'
get '/chaos/sleep' => 'chaos#sleep'
+ get '/chaos/kill' => 'chaos#kill'
end
draw :api