Simulate HTTP faults

    HTTPChaos is a fault type provided by Chaos Mesh. By creating HTTPChaos experiments, you can simulate the fault scenarios during the HTTP request and response processing. Currently, HTTPChaos supports simulating the following fault types:

    • delay: injects latency into the request or response
    • replace: replaces part of content in HTTP request or response messages
    • patch: adds additional content to HTTP request or response messages

    HTTPChaos supports combinations of different fault types. If you have configured multiple HTTP fault types at the same time when creating HTTPChaos experiments, the order set to inject the faults when the experiments start running is abort -> delay -> replace -> patch. When the abort fault cause short circuits, the connection will be directly interrupted.

    For the detailed description of HTTPChaos configuration, see Field description below.

    Notes

    Before injecting the faults supported by HTTPChaos, note the followings:

    • There is no control manager of Chaos Mesh running on the target Pod.
    • The rules will affect both of clients and servers in the Pod, if you want to affect only one side, please refer to the specify side section.
    • HTTPS accesses should be disabled, because injecting HTTPS connections is not supported currently.
    • For HTTPChaos injection to take effect, the client should avoid reusing TCP socket. This is because HTTPChaos does not affect the HTTP requests that are sent via TCP socket before the fault injection.
    • Use non-idempotent requests (such as most of the POST requests) with caution in production environments. If such requests are used, the target service may not return to normal status by repeating requests after the fault injection.
    1. Open Chaos Dashboard, and click NEW EXPERIMENT on the page to create a new experiment:

    2. In the Choose a Target area, choose HTTP FAULT and select a specific behavior, such as RESPONSE ABORT. Then fill out specific configurations.

      create HTTP fault

    3. Submit the experiment.

    Create experiments using YAML files

    Chaos Mesh also supports using YAML configuration files to create HTTPChaos experiments. In a YAML file, you can simulate either one HTTP fault type or a combination of different HTTP fault types.

    1. Write the experimental configuration to the http-abort-failure.yaml file as the example below:

      Based on this configuration example, Chaos Mesh will inject the abort fault into the specified pod for 5 minutes. During the fault injection, the GET requests sent through port 80 in the /api path of the target Pod will be interrupted.

    2. After the configuration file is prepared, use kubectl to create the experiment:

      1. kubectl apply -f ./http-abort-failure.yaml

    Example of fault combinations

    1. Write the experimental configuration to http-failure.yaml file as the example below:

      Based on this configuration example, Chaos Mesh will inject the delay fault, replace fault, and patch fault consecutively.

    Common fields are meaningful when the target of fault injection is Request or Response.

    The Request field is a meaningful when the target set to Request during the fault injection.

    Specify side

    The rules will affect both of clients and servers in the Pod by default, but you can affect only one side by selecting the request headers.

    This section provides some examples to specify the affected side, you can adjust the header selector in rules depend on your particular cases.

    To inject faults into clients in the Pod without affecting servers, you can select the request/response by the Host header in the request.

    For example, if you want to interrupt all requests to http://example.com/, you can apply the following YAML config:

    Server side

    To inject faults into servers in the Pod without affecting clients, you can also select the request/response by the Host header in the request.

    For example, if you want to interrupt all requests to your server behind service nginx.nginx.svc, you can apply the following YAML config:

    1. apiVersion: chaos-mesh.org/v1alpha1
    2. kind: HTTPChaos
    3. metadata:
    4. name: test-http-server
    5. spec:
    6. mode: all
    7. selector:
    8. labelSelectors:
    9. app: nginx
    10. target: Request
    11. port: 80
    12. path: '*'
    13. request_headers:
    14. Host: 'nginx.nginx.svc'

    In other cases, especially when injecting the inbound request from outside, you may select the request/response by the X-Forwarded-Host header in the request.

    For example, if you want to interrupt all requests to your server behind a public gateway , you can apply the following YAML config:

    If you are not sure of the effects of certain fault injections, you can also test the corresponding features locally using rs-tproxy. Chaos Mesh also provides HTTPChaos by using rs-tproxy.