Fault injection

更新时间:
复制 MD 格式

The fault injection feature lets you inject faults into a test application to test how it handles exceptions. You can then adjust your application based on the results to reduce exceptions in the production environment. This feature is primarily used in staging environments.

Feature Overview

The fault injection flow is as follows:故障注入-1.png

In a microservice, it is implemented as follows:

  1. The management console MS assembles the fault injection rule and sends it to DRM.

  2. MOSN and the Remote Procedure Call (RPC) client subscribe to the key in DRM.

Configure a fault injection rule

  1. Log on to the SOFAStack console.

  2. In the navigation pane on the left, choose Middleware > Microservice Platform > Service Mesh > Service Administration, and then click the Fault Injection tab.

  3. Click Add Injection Group Rule, and then configure the following parameters:

    Parameter

    Description

    Rule Name

    Set the name of the fault injection rule.

    Application

    Select or enter the name of the target application. An asterisk (*) indicates all applications.

    Injection Direction

    Set the direction for fault injection. Valid values:

    • Server-side injection: Injects faults on the server side of the application.

    • Client-side injection: Injects faults on the client side of the application.

    Service

    Configure the service where faults are injected. Click Switch Input Mode to switch between manual entry and dropdown selection.

    Method

    Configure the method for fault injection. An asterisk (*) indicates all methods.

    Runtime Mode

    Configure the runtime mode for the fault injection rule. The values are:

    • Block Mode: Faults are injected into requests that meet the conditions.

    • Observer Mode: Faults are not injected into requests that meet the conditions. Instead, logs are printed in MOSN.

    Fault Type

    Fault injection supports injecting events such as faults or timeouts to test for exceptions and simulate abnormal service conditions. The values are:

    • Abort: Injects a runtime exception, aborts the request, and returns a specified status code.

    • Timeout: Increases the response time for requests that meet the conditions. The request is called normally.

    Timeout Period

    When Fault Type is set to Timeout, set the timeout period for the exception.

    Abnormality Ratio

    Set the percentage of traffic to which faults are injected. For example, if you set this to 80, faults are injected into 80% of the traffic.

    Exact Traffic Match (Optional)

    Set the conditions to match traffic. Fault injection rules are applied only to traffic that meets these conditions. If you leave this empty, all traffic is matched.

    You can configure multiple match conditions. The conditions are combined with an AND operator and are matched in order. The parameters are as follows:

    • Field: You can select a system field or a request header.

    • Field Name: The value depends on the field type.

      • System Field: Includes traffic type, caller application name, caller IP address, and service provider application name.

      • Request Header: Refers to the request header of the protocol. For example, for the Dubbo protocol, it is the attachment. For the HTTP protocol, it is the Request Header. You can define custom request header parameters and values in your application.

    • Logic: Includes equals, not equals, in, not in, and regex.

    • Field Value: The value that corresponds to the field name.

  4. Click Submit, and then click OK.

  5. In the list of fault injection rules, set the status of the rule you created to Enabled.

    Note

    If multiple fault injection rules target the same service, only the first rule takes effect.

Edit a fault injection rule

You can edit an existing fault injection rule at any time. The updated rule takes effect immediately after you submit it.

  1. On the Fault Injection tab, click the plus sign (+) to the left of the target application.

  2. Click Edit to the right of the target fault injection rule.

  3. Edit the fault injection rule as needed, and then click Submit.

Delete a fault injection rule

You can delete an existing fault injection rule. The deletion takes effect immediately. Proceed with caution.

  1. On the Fault Injection tab, click the plus sign (+) to the left of the target application.

  2. Click Delete to the right of the target fault injection rule.

  3. Click OK.