Skip to content

Commit

Permalink
docs: add feature toggle reference, new how-to (#1694)
Browse files Browse the repository at this point in the history
* Docs: write down the currently available steps

* docs: quick updates to the projects page.

* docs: further scaffold the how-to guide

* docs: add feature-toggle.mdx (toggle reference doc)

* docs: Add note that feature toggle names must be unique

* docs: add API doc links

* docs: delete old content

* docs: delete old images

* docs: update variants text

* docs: update introduction

* docs: add new images, update api annotations

* docs: add links to context fields, improve link text for other links.

* docs: remove redundant wording.

* docs: fix default project for toggles

* docs: typo: singular -> plural

* docs: mention admin ui curl command

* docs: remove leftover words

* docs: improve linking to default project.

* Apply suggestions from code review

Co-authored-by: sighphyre <liquidwicked64@gmail.com>

* Apply suggestions from code review

Co-authored-by: sighphyre <liquidwicked64@gmail.com>

* docs: clarify constraint timing

* docs: apply suggestion from code review

* docs: add link to variants document

* docs: Add sections on environments and projects, link from ft docs

* docs: minor rewording into unleash context.

* docs: remove misleading section about "all strats evaluated"

* docs: evaluate -> resolve

Co-authored-by: sighphyre <liquidwicked64@gmail.com>
  • Loading branch information
thomasheartman and sighphyre committed Jun 17, 2022
1 parent 525fce3 commit 5a3f418
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 95 deletions.
39 changes: 39 additions & 0 deletions website/docs/reference/feature-toggles.mdx
@@ -0,0 +1,39 @@
---
title: Feature Toggles
---

Feature toggles are the central concept that we built Unleash around. In Unleash, feature toggles are organized within [projects](../user_guide/projects.md). Feature toggles can have different [activation strategies](../user_guide/activation-strategies.md) for each of their project's [environments](../user_guide/environments.md), and can also be given [variants](../advanced/feature-toggle-variants.md) to facilitate A/B testing.

## Configuration options

Each feature toggle has the following configuration options

| Option | Required? | Default value | Description |
| --- | --- | --- | --- |
| name | Yes | N/A | The feature toggle's name. Must be URL-friendly according to [section 2.3 of RFC 3986](https://www.rfc-editor.org/rfc/rfc3986#section-2.3) and must be unique within your Unleash instance. |
| feature toggle type | Yes | Release | The [feature toggle's type](../advanced/feature-toggle-types.md). |
| project | Yes | The [default project](../user_guide/projects.md#the-default-project). When created from a project page in the admin UI, that project will be the default value instead. | The [project](../user_guide/projects.md) that should contain the feature toggle. |
| description | No | N/A | A description of the feature toggle's purpose. |
| enable impression data | Yes | No | Whether to enable [impression data](../advanced/impression-data.md) for this toggle or not. |

## Environments

You probably won't want to use the same configuration to enable a toggle in development as you do in production. That's why feature toggles have different activation strategy configurations for each environment.

You can enable and disable a toggle independently in each of the [project's environments](../user_guide/projects.md#projects-and-environments). When you disable a toggle in an environment, it will always evaluate to false in that environment. When you enable a toggle in an environment, the toggle will evaluate to true or false depending on its activation strategies.

Refer to the [documentation on environments](../user_guide/environments.md) for more details on how environments work.

## Activation strategies

To enable a feature in an environment, you must assign it at least one activation strategy. A feature toggle's activation strategies determine whether the toggle gets enabled for a particular [Unleash context](../user_guide/unleash-context.md) (typically a user). When using multiple strategies in a single environment, only a single strategy needs to evaluate to true for the toggle to get enabled for a user. Whenever Unleash evaluates a toggle, it will evaluate strategies in the current environment until one of them resolves to true. If no strategies resolve to true, then the toggle's value is false.

Refer to the [activation strategies documentation](../user_guide/activation-strategies.md) for a detailed description of all the built-in strategies.

## Variants

[Variants](../advanced/feature-toggle-variants.md) adds another dimension of flexibility to feature toggles. Each feature toggle can be assigned any number of variants which will then get distributed amongst your users based on your choice of [context field](../user_guide/unleash-context.md#structure). You can find out more about variants in the [variants docs](../advanced/feature-toggle-variants.md).

### Creating toggles with payloads

While variants are most often used for A/B testing and the like, you can also use variants to assign a constant payload to a toggle. If you give a toggle only a single variant and that variant has a payload, then all users variants will receive that payload.
142 changes: 122 additions & 20 deletions website/docs/user_guide/create-feature-toggle.md
Expand Up @@ -3,39 +3,141 @@ id: create_feature_toggle
title: How to create a feature toggle
---

In this guide you will learn how to create your first feature toggle using Unleash.
[Feature toggles](../reference/feature-toggles.mdx) are the foundation of Unleash. They are at the core of everything we do and are a fundamental building block in any feature management system. This guide shows you how to create feature toggles in Unleash and how to add any optional constraints, segments, variants, and more. Links to learn more about these concepts will be scattered throughout the text.

## Step 1: Click the “create feature toggle” button {#step-1-click-the-create-feature-toggle-button}
You can perform every action both via the UI and the admin API. This guide includes screenshots to highlight the relevant UI controls and links to the relevant API methods for each step.

The first time you log-in to your Unleash instance you will see an empty list of feature toggles. In order to create a new feature toggle you have to click the “create feature toggle” button
This guide is split into three sections:
1. [Prerequisites](#prerequisites): you need these before you can create a toggle.
2. [Required steps](#required-steps): all the required steps to create a toggle and activate it in production.
3. [Optional steps](#optional-steps): optional steps you can take to further target and configure your feature toggle and its audience.

![Create a feature toggle](/img/create_feature_toggle_button.png)
## Prerequisites

## Step 2: Create Feature toggle {#step-2-create-feature-toggle}
To be able to create a feature toggle in an Unleash system you will need:
- A running Unleash instance
- A project to hold the toggle
- A user with an **editor** or **admin** role OR a user with the following permissions inside the target project:
- create feature toggles
- create/edit variants
- create activation strategies (for the right environment)
- update activation strategies (for the right environment)
- enable/disable toggles (for the right environment)

After clicking the “create feature toggle” button you will be presented with a form for creating a new feature toggle. You will need to define a few fields before you can actually complete the new feature toggle.
:::info roles

- **Name** – Must be unique across all your feature toggle. The name must also follow a URL friendly format. Can not be changed.
- **Description** – A good description makes it easier for other members on your team to understand why this feature toggle exists.
- **Enabled** – Whether the feature toggle should be enabled or disabled. If the feature toggle is disabled, activation strategy configurations will not be evaluated.
- **Activation** strategies – A list of one or more activation strategies. An activation strategy is used to enable the feature toggle to a subset, or all, of your users.
Refer to [the documentation on role-based access control](./rbac.md) for more information about the available roles and their permissions.

In the example below we have chosen to not set up a strategy, which means that the standard strategy will be applied.
:::

![Create a feature toggle](/img/create_feature_toggle_save.png)
## Required steps

## Step 3: Congratulations, you have now created your first feature toggle! {#step-3-congratulations-you-have-now-created-your-first-feature-toggle}
This section takes you through the required steps to create and activate a feature toggle. It assumes that you have all the prerequisites from the previous section done.

The toggle is now created and ready to be used. The toggle does not have any metrics because it is not used by any applications, yet!
### Step 1: Create a toggle {#step-1}

![Create a feature toggle](/img/create_feature_toggle_list.png)
:::tip API: create a toggle

## Step 4: Enable the feature toggle only for your boss! {#step-4-enable-the-feature-toggle-only-for-your-boss}
Use the [Admin API endpoint for creating a feature toggle](../api/admin/feature-toggles-api-v2.md#create-toggle). The payload accepts all the same fields as the Admin UI form. The Admin UI also displays the corresponding cURL command when you use the form.

The next step is to change the activation strategy to only target your boss. You can use the “userIDs”-strategy for that. Using the configuration shown below will only enable the feature toggle for “boss@company.com” and “me@company.com”. Thus, you can safely test your feature in production, without exposing it to your users.
:::

![Create a feature toggle](/img/create_feature_toggle_userIds.png)
In the project that you want to create the toggle in, use the "new feature toggle" button and fill the form out with your desired configuration. Refer to the [feature toggle reference documentation](../reference/feature-toggles.mdx) for the full list of configuration options and explanations.

## Summary {#summary}

In this guide you created your first feature toggle and enabled it for everyone. In later guides we will learn how we can reduce the risk by enabling the toggle for a controlled set of users first.
![](/img/create-toggle-new-toggle.png)

### Step 2: Add a strategy {#step-2}

:::tip API: Add a strategy

Use the [API for adding a strategy to a feature toggle](../api/admin/feature-toggles-api-v2.md#add-strategy). You can find the configuration options for each strategy in the [activation strategy reference documentation](../user_guide/activation-strategies.md).

:::

Decide which environment you want to enable the toggle in. Select that environment and add an activation strategy. Different activation strategies will act differently as described in the [activation strategy documentation](../user_guide/activation-strategies.md). The configuration for each strategy differs accordingly. After selecting a strategy, complete the steps to configure it.

![](/img/create-toggle-add-strategy.png)

### Step 3: Enable the toggle {#step-3}

:::tip API: Enable a toggle

Use the [API for enabling an environment for a toggle](../api/admin/feature-toggles-api-v2.md#enable-env) and specify the environment you'd like to enable.

:::

Use the environments toggles to switch on the environment that you chose above. Depending on the activation strategy you added in the previous step, the toggle should now evaluate to true or false depending on the Unleash context you provide it.

![](/img/create-toggle-enable-env.png)

## Optional steps

These optional steps allow you to further configure your feature toggles to add optional payloads, variants for A/B testing, more detailed user targeting and exceptions/overrides.

### Add constraints and segmentation


Constraints and segmentation allow you to set filters on your strategies, so that they will only be evaluated for users and applications that match the specified preconditions. Refer to the [strategy constraints](../advanced/strategy-constraints.md "strategy constraints reference documentation") and [segments reference documentation](../reference/segments.mdx) for more information.

To add constraints and segmentation, use the "edit strategy" button for the desired strategy.

![](/img/create-toggle-edit-strategy.png)


#### Constraints

:::info

Constraints aren't fixed and can be changed later to further narrow your audience. You can add them either when you add a strategy to a toggle or at any point thereafter.

:::

:::tip API: Add constraints

You can either [add constraints when you add the strategy](../api/admin/feature-toggles-api-v2.md#add-strategy) or [PUT](../api/admin/feature-toggles-api-v2.md#update-strategy "PUT an activation strategy") or [PATCH the strategy afterwards](../api/admin/feature-toggles-api-v2.md#put-strategy)

:::

In the strategy configuration screen for the strategy that you want to configure, use the "add custom constraint" button to add a custom constraint.


![](/img/create-toggle-add-constraint.png)

#### Segments

:::info

This can be done after you have created a strategy.

:::

:::tip API: add segments

Use the [API for adding segments to a strategy](../api/admin/segments.mdx#replace-activation-strategy-segments) to add segments to your strategy.

:::


In the strategy configuration screen for the strategy that you want to configure, use the "select segments" dropdown to add segments.

![](/img/create-toggle-add-segment.png)

### Add variants
:::info

This can be done at any point after you've created your toggle.

:::

:::tip API: add variants


Use the [update variants endpoint](../api/admin/feature-toggles-api-v2.md#update-variants). The payload should be your desired variant configuration.

:::

[Variants](../advanced/feature-toggle-variants.md) give you the ability to further target your users and split them into groups of your choosing, such as for A/B testing.
On the toggle overview page, select the variants tab. Use the "new variant" button to add the variants that you want.

![](/img/create-toggle-add-variants.png)

0 comments on commit 5a3f418

Please sign in to comment.