@@ -40,17 +41,57 @@ class ChaosController < ActionController::Base
...
@@ -40,17 +41,57 @@ class ChaosController < ActionController::Base
private
private
defvalidate_request
defrequest_start_time
secret=ENV['GITLAB_CHAOS_SECRET']
@start_time||=Time.now
# GITLAB_CHAOS_SECRET is required unless you're running in Development mode
end
if!secret&&!Rails.env.development?
renderplain: "chaos misconfigured: please configure GITLAB_CHAOS_SECRET when using GITLAB_ENABLE_CHAOS_ENDPOINTS outside of a development environment",status: :internal_server_error
@@ -15,23 +15,19 @@ Currently, there are four endpoints for simulating the following conditions:
...
@@ -15,23 +15,19 @@ Currently, there are four endpoints for simulating the following conditions:
## Enabling chaos endpoints
## Enabling chaos endpoints
For obvious reasons, these endpoints are not enabled by default. They can be enabled by setting the `GITLAB_ENABLE_CHAOS_ENDPOINTS` environment variable to `1`.
For obvious reasons, these endpoints are not enabled by default on `production`.
They are enabled by default on **development** environments.
For example, if you're using the [GDK](https://gitlab.com/gitlab-org/gitlab-development-kit) this can be done with the following command:
```bash
GITLAB_ENABLE_CHAOS_ENDPOINTS=1 gdk run
```
## Securing the chaos endpoints
DANGER: **Danger:**
DANGER: **Danger:**
It is highly recommended that you secure access to the chaos endpoints using a secret token. This is recommended when enabling these endpoints locally and essential when running in a staging or other shared environment. You should not enable them in production unless you absolutely know what you're doing.
It is required that you secure access to the chaos endpoints using a secret token.
You should not enable them in production unless you absolutely know what you're doing.
A secret token can be set through the `GITLAB_CHAOS_SECRET` environment variable. For example, when using the [GDK](https://gitlab.com/gitlab-org/gitlab-development-kit) this can be done with the following command:
A secret token can be set through the `GITLAB_CHAOS_SECRET` environment variable.
For example, when using the [GDK](https://gitlab.com/gitlab-org/gitlab-development-kit)
this can be done with the following command:
```bash
```bash
GITLAB_ENABLE_CHAOS_ENDPOINTS=1 GITLAB_CHAOS_SECRET=secret gdk run
GITLAB_CHAOS_SECRET=secret gdk run
```
```
Replace `secret` with your own secret token.
Replace `secret` with your own secret token.
...
@@ -56,10 +52,11 @@ GET /-/chaos/leakmem?memory_mb=1024&duration_s=50
...
@@ -56,10 +52,11 @@ GET /-/chaos/leakmem?memory_mb=1024&duration_s=50
This endpoint is similar to the CPU Spin endpoint but simulates off-processor activity, such as network calls to backend services. It will sleep for a given duration.
This endpoint is similar to the CPU Spin endpoint but simulates off-processor activity, such as network calls to backend services. It will sleep for a given duration_s.
As with the CPU Spin endpoint, this may lead to your request timing out if duration exceeds the configured limit.
As with the CPU Spin endpoint, this may lead to your request timing out if duration_s exceeds the configured limit.
```
```
GET /-/chaos/sleep
GET /-/chaos/sleep
...
@@ -99,6 +120,7 @@ GET /-/chaos/sleep?duration_s=50
...
@@ -99,6 +120,7 @@ GET /-/chaos/sleep?duration_s=50