No results for ""
EXPAND ALL
  • Home
  • API docs

Archiving flags

Read time: 5 minutes
Last edited: Oct 15, 2024

Overview

This topic explains how to clean up flags you no longer need. LaunchDarkly helps you identify flags that you can remove from your code, then prompts you to archive these flags. Archiving a flag removes it from your Flags list in LaunchDarkly, without deleting it.

Cleaning up your flags is an important part of the flag lifecycle, and critical to helping reduce the technical debt that you may accumulate as you use flags throughout your organization.

About archiving

When a flag is no longer being served to customers, and it is not a prerequisite of other flags, it may be time to archive it. Archiving a flag retires it from LaunchDarkly without deleting it. You can restore an archived flag if you need it, or find it to reference its configuration later.

LaunchDarkly will not let you archive a flag that is a prerequisite of other flags. Flags are good candidates for archival when they are serving only one variation in the environment you choose and have not been requested in the last seven days.

When you archive a flag in LaunchDarkly, you should also remove the flag from your code. If your application evaluates an archived flag, LaunchDarkly serves the the flag's fallback value. This means it is critical to remove all references to a flag from your code before you archive the flag. LaunchDarkly's code references feature can help you quickly identify all the places a flag is referenced in your code. To learn more, read Code references.

You can delete an archived flag after you determine your project no longer needs it. To learn how, read Deleting flags.

Archiving a flag removes it from every environment in your project

All flags exist in every environment for a project, but often only a few environments matter for your organization's production processes. LaunchDarkly recommends archiving all flags that are ready to archive in your critical environments. However, archiving a flag will remove it from every environment in the project. Be absolutely certain you can archive a flag without any unintended impact.

Archive flags

LaunchDarkly automatically determines if a flag is ready to archive by checking the flag in all of your critical environments for code references, age, status, and whether it is a prerequisite. You can view flags that are ready to archive from the Flags list.

Here's how:

  1. From the Flags list, open the Filters menu.
  2. Under Lifecycle, select Ready to archive:
The project-level Filters menu, with "Ready to archive" selected.
The project-level Filters menu, with "Ready to archive" selected.
  1. Each flag that is ready to archive has a "Ready to archive" indicator in the Flags list.
  2. Click the indicator for the flag you want to archive. The "Ready to archive" dialog appears:
The "Ready to archive" dialog.
The "Ready to archive" dialog.
  1. Review the checks to confirm that the flag is ready to archive.
  2. Enter a Comment to let other members in your organization know why you are archiving the flag.
  3. Click Archive.

The flag is archived and removed from the Flags list. You can find it in the archived Flags list. To learn more, read View and restore flags.

Review "Needs code removal" as well

One of the checks to confirm that a flag is ready to archive is whether or not it has code references. To filter for flags that are ready for code removal, use the Lifecycle filter "Needs code removal." To learn more about code references, read Code references.

You can also archive a flag from the flag's settings page.

Expand how to archive a flag from the flag settings

Here's how to archive a flag from the flag's settings page:

  1. Navigate to the Flags list.

  2. Hover on the flag you wish to deprecate, and click the three-dot overflow menu that appears.

  3. Click Manage flag settings.

  4. In the "Archive flag" section, click Archive. The "Archive this flag?" panel appears.

    • If the flag has dependencies, you cannot archive it:
    A flag that cannot be archived due to dependencies.
    A flag that cannot be archived due to dependencies.

    To learn how to resolve flag dependencies, read Resolve dependencies.

  5. Choose the environments your team or customers depend on to confirm you can archive the flag from those environments without unintended consequences. Verify that the flag is not in use by reviewing its states in the flag archive fields:

A flag with no dependencies that you can archive.
A flag with no dependencies that you can archive.

  1. Type the flag's name in the Archive flag text box.
  2. Click Archive.

The flag is archived and removed from the Flags list. You can find it in the archived Flags list. To learn more, read View and restore flags.

Archived flags serve their fallback values if requested

If end users request a flag after you archive it, the flag value that returns is the fallback value you defined in code.

Resolve dependencies

There are three types of flag dependencies:

  • The flag is a prerequisite for other dependent flags
  • The flag is serving multiple variations
  • The flag has been requested in the last seven days

You cannot archive a flag that is a prerequisite for other flags. You must remove the flag as a prerequisite before you can archive it. Even if the flag's dependent flags themselves are archived, the dependency will still block you from archiving the prerequisite flag. If you attempt to archive a prerequisite flag, the "Archive this flag?" panel prevents you from doing so.

The other two dependencies will not stop you from archiving a flag, but we recommend resolving all dependencies before you archive a flag.

Here is a screenshot of the "Archive this flag?" panel:

A flag with dependencies that do not block it from being archived.
A flag with dependencies that do not block it from being archived.

View and restore flags

By default, the Flags list shows live flags only.

To view archived flags, click Filters from the Flags list and select "Archived" or "Deprecated" under "Lifecycle":

The Flags list Filters, with the lifecycle options shown.
The Flags list Filters, with the lifecycle options shown.

To restore an archived flag:

  1. Navigate to the Flags list.
  2. Click Filters. In the "Lifecycle" section, click "Archived." The archived flag list appears.
  3. Hover on the flag you wish to restore, and click the three-dot overflow menu that appears.
  4. Click Manage flag settings.
  5. In the "Restore flag" section, click Restore. The "Restore flag" panel appears.
  6. The panel shows you how the flag has been evaluated recently. Choose the environments your team or customers depend on to confirm that restoring the flag will have no unexpected consequences.
  7. Type the flag's name in the Restore flag text box.
  8. Click Restore. The flag appears in the live Flags list.
Restoring a flag means it will be evaluated again

When you restore a flag, it returns to evaluation just like any other flag. This is why it is important to confirm that the flag will have no unexpected impact after you restore it.