What is a feature toggle for

更新时间:
复制 MD 格式

A feature toggle is a lightweight dynamic configuration framework. It lets you dynamically manage configuration items in your code. You can enable or disable features for an application or set thresholds for performance metrics as needed. Feature toggles are often used for scenarios such as setting blacklists and whitelists, dynamically adjusting log levels at runtime, and degrading business features.

Background information

Business code often contains many configuration items that control various business logic. For example, a boolean variable controls whether a feature is enabled, a list controls access whitelists or blacklists, and a string controls a prompt message. Developers often want to view and modify these configuration items dynamically and in real time without writing extra management code. AHAS feature toggles allow you to modify and view these configuration items in real time. Unlike traditional configuration centers, AHAS feature toggles do not require developers to handle the parsing logic of configuration items. You can simply declare the variable and add the AHAS feature toggle annotation to dynamically manage the configuration in the feature toggle console.

Key features

  • View feature toggles: View the toggles included in your application on the feature toggle page. For more information, see View feature toggles.

  • View toggle value distribution: View the value and distribution information for each toggle on the feature toggle page. For more information, see View feature toggles.

  • Push toggle settings: On the feature toggle page, you can set the push value for a toggle. After a successful push, the change takes effect in your business code in real time. For more information, see Push toggle settings.

    Note

    AHAS feature toggles also support grayscale and batched pushes. You can first validate the change on a batch of machines and then publish it globally. This prevents unexpected changes from causing online failures.

For example, during major sales promotions, you can use a toggle to degrade non-core business logic and reduce unnecessary resource consumption. The following example shows the process:

  1. Add a core business toggle, instrumentation, and business logic to your code.

  2. You can view the information and value distribution of feature toggles on the Feature Toggles page.

  3. On the Feature Toggles page, set this toggle's Push Value to true.

  4. Modify the configuration item in the console. After a successful push, the change takes effect in the business code in real time. The toggle variable in the code becomes true. This demonstrates how you can dynamically control business logic in real time using a feature toggle.

Common scenarios

  • Dynamically adjust log levels at runtime: Different application scenarios require different log levels to obtain useful information. Feature toggles allow you to dynamically modify log levels while an application is running. You can add a log level toggle to your application and set its push value in the console to quickly adjust the log level and obtain more useful information. For more information, see Dynamically adjust log levels at runtime.

  • Proactively degrade business features: A business feature usually includes many business logic components, which can be divided into core and non-core business logic. Under high concurrency, such as during the 618 and Double 11 sales promotions, the system needs to reduce resource consumption from non-essential business logic. Proactively degrading non-essential business features improves system performance. You can define a degradation business toggle in your application and push its settings from the console to quickly degrade the business feature. For more information, see Proactively degrade business features.

  • Blacklists and whitelists: Blacklists and whitelists are common access control rules. You can implement this feature quickly using feature toggles. You can simply add a blacklist or whitelist toggle to your application and then push its settings from the console. For more information, see Quickly implement blacklists and whitelists.

Notes

In some Integrated Development Environments (IDEs), especially when using the Spring Boot technology stack, a ClassLoader mismatch can cause issues. Because the SwitchManager and your code are loaded by different ClassLoaders, your project may not be able to retrieve the latest value after a feature toggle is modified in the cloud.