Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: Feature Flags Lifecycles
sidebar_label: Feature Flags Lifecycles
title: Feature Flags Life Spans
sidebar_label: Feature Flags Life Spans
sidebar_position: 1
---

Feature Flags generally have two lifecycles:
Feature Flags generally have two life spans:

1. Short-Lived Flags
2. Long-Lived Flags
Expand All @@ -22,6 +22,8 @@ Short-lived flags are designed to be removed from your code and from Flagsmith a
5. Deploy your application, so that there is no reference to the flag.
6. Remove the flag from Flagsmith.

[Feature Lifecycle](/managing-flags/feature-lifecycle) highlights feature flags at each of these steps, making it easier to spot the ones ready to be removed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This overstates what Feature Lifecycle tracks: it does not represent every action in the six-step list, such as toggling the flag or applying Segment overrides. Describe it as tracking flags through lifecycle stages and identifying cleanup candidates.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At docs/docs/best-practices/flag-life-spans.md, line 25:

<comment>This overstates what Feature Lifecycle tracks: it does not represent every action in the six-step list, such as toggling the flag or applying Segment overrides. Describe it as tracking flags through lifecycle stages and identifying cleanup candidates.</comment>

<file context>
@@ -22,6 +22,8 @@ Short-lived flags are designed to be removed from your code and from Flagsmith a
 5. Deploy your application, so that there is no reference to the flag.
 6. Remove the flag from Flagsmith.
 
+[Feature Lifecycle](/managing-flags/feature-lifecycle) highlights feature flags at each of these steps, making it easier to spot the ones ready to be removed.
+
 :::info 
</file context>
Suggested change
[Feature Lifecycle](/managing-flags/feature-lifecycle) highlights feature flags at each of these steps, making it easier to spot the ones ready to be removed.
[Feature Lifecycle](/managing-flags/feature-lifecycle) tracks feature flags through stages of development and release, making it easier to spot the ones ready to be removed.


:::info

Flagsmith can automatically flag features that have not been changed for a configurable period of time — see [Stale Flag Detection](/managing-flags/stale-flags).
Expand Down Expand Up @@ -80,6 +82,5 @@ With Flagsmith, you can:

## Further Reading

- For a deeper dive into the different types of feature flag lifecycles, check out the [Feature Flags Lifecycles guide](/best-practices/flag-lifecycle).
- Learn more about [A/B and multivariate testing](/experimentation-ab-testing) to see how experimentation can be managed with Flagsmith.
- Explore how [Segments](/flagsmith-concepts/segments) can help you target features to specific groups of users.
2 changes: 1 addition & 1 deletion docs/docs/best-practices/naming-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ Common tag conventions:

## Further reading

- [Feature Flag Lifecycles](/best-practices/flag-lifecycle) - understanding when to remove flags
- [Feature Flags Life Spans](/best-practices/flag-life-spans) - understanding when to remove flags
- [Structuring Your Projects](/best-practices/structuring-your-projects) - organising flags across projects
- [Tagging](/managing-flags/tagging) - using tags to categorise flags
2 changes: 1 addition & 1 deletion docs/docs/best-practices/structuring-your-projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ In practice, many organisations use a hybrid approach: separate projects for tru

Each project has [system limits](/administration-and-security/governance-and-compliance/system-limits) on features and segments.

A well-scoped project should rarely approach these limits. Most feature flags are designed to be temporary, they serve their purpose during a release or experiment and should then be removed. If you find yourself nearing these limits, it's often a sign that stale flags need to be cleaned up or that your project scope is too broad. For guidance on managing flag removal, see [Flag Lifecycle](/best-practices/flag-lifecycle).
A well-scoped project should rarely approach these limits. Most feature flags are designed to be temporary, they serve their purpose during a release or experiment and should then be removed. If you find yourself nearing these limits, it's often a sign that stale flags need to be cleaned up or that your project scope is too broad. For guidance on managing flag removal, see [Feature Flags Life Spans](/best-practices/flag-life-spans).

### Access control

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/best-practices/when-to-use-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ When you want to release a new feature to a specific group of beta testers, you

## Further Reading

- For a deeper dive into the different types of feature flag lifecycles, check out the [Feature Flags Lifecycles guide](/best-practices/flag-lifecycle).
- For a deeper dive into the different types of feature flag life spans, check out the [Feature Flags Life Spans guide](/best-practices/flag-life-spans).
- Learn more about [A/B and multivariate testing](/experimentation-ab-testing) to see how experimentation can be managed with Flagsmith.
- Explore how [Segments](/flagsmith-concepts/segments) can help you target features to specific groups of users.
5 changes: 4 additions & 1 deletion docs/docs/managing-flags/code-references.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Integrate with Code References to track feature flag usage in your codebase, and
- Navigate through the business logic in the code from a feature's perspective
- Coordinate cleanup work around [stale feature flags](/managing-flags/stale-flags) easier

Code References fuels [Feature Lifecycle](/managing-flags/feature-lifecycle), which uses it to highlight the feature flags ready to be removed: first from the code, then from Flagsmith.

![Code References badges displayed in the Features list, each containing a count of references of that feature](./code-references/feature-list.png)

<p style={{textAlign: 'center', fontSize: '0.9em', color: 'gray', marginTop: '-1.5rem'}}>Code Reference counts displayed in Features list</p>
Expand Down Expand Up @@ -133,5 +135,6 @@ Feature details will expand on the _Usage_ tab, and list locations of each code

## Related

- [Feature Lifecycle](/managing-flags/feature-lifecycle): Spot feature flags ready to be removed from the code and from Flagsmith
- [Management API Authentication](/integrating-with-flagsmith/flagsmith-api-overview/management-api/authentication): Generate API keys for Code References
- [Flag Lifecycle](/best-practices/flag-lifecycle): Learn when to remove short-lived flags from your code
- [Feature Flags Life Spans](/best-practices/flag-life-spans): Learn when to remove short-lived flags from your code
66 changes: 66 additions & 0 deletions docs/docs/managing-flags/feature-lifecycle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: Feature Lifecycle
sidebar_label: Feature Lifecycle
sidebar_position: 7
---

The busy age of today makes it easy to forget feature flags in the code, and keep them either enabled — or disabled —
forever. They even overlap and nest sometimes, and create a grey area in feature flag management in which _nobody will
ever touch those features because things just work as they are_. For most of us, software management is already too busy
to fit in feature flag hygiene.

:::tip

As a good practice, feature flags should not live forever.

Most of the time, the ultimate goal of a feature flag is to help serve new software to audiences in a controlled way,
for example with [percentage rollouts](/managing-flags/rollout/rollout-by-percentage). Once the feature is fully rolled
out, the feature flag can be safely removed.

:::

Feature Lifecycle highlights features at each stage of the development and release process, making it easier to spot
feature flags that should be removed: first from the code, then from Flagsmith. Find it under **Lifecycle** in your
project's navigation.

![The Lifecycle tab, with the stages menu and the list of stale features](/img/managing-flags/feature-lifecycle/stale-features.png)

## The stages of a feature flag

Within its life, and in the Lifecycle tab, a feature flag goes through these stages:

- `New`: Created in Flagsmith, but not in the code yet. Becomes `Live` once a code scan finds it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: New does not mean the feature was recently created; existing non-stale features with no code references also appear here. Describe the stage by its actual classification so users do not infer feature age from it.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At docs/docs/managing-flags/feature-lifecycle.md, line 35:

<comment>`New` does not mean the feature was recently created; existing non-stale features with no code references also appear here. Describe the stage by its actual classification so users do not infer feature age from it.</comment>

<file context>
@@ -0,0 +1,67 @@
+Within the life of a feature flag, and also in the Feature Lifecycle tab, we
+identify the stages:
+
+- `New`: Created in Flagsmith, but not in the code yet. Becomes `Live` once a code scan finds it.
+- `Live`: In the code and still being rolled out. Nothing to do.
+- `Permanent`: Meant to stay, e.g. a kill switch. Never flagged for clean-up.
</file context>
Suggested change
- `New`: Created in Flagsmith, but not in the code yet. Becomes `Live` once a code scan finds it.
- `New`: No code references are found in the latest scans, and the feature is neither stale nor permanent; this does not necessarily mean it was recently created.

- `Live`: In the code and still being rolled out. Nothing to do.
- `Permanent`: Meant to stay, e.g. a kill switch. Never flagged for clean-up.
- `Stale`: Still in the code, but [untouched for a while](/managing-flags/stale-flags). Time to remove it from the code.
- `To Monitor`: Gone from the code, but still being evaluated, e.g. by an older release of the application. Wait before
deleting.
- `To Remove`: Gone from the code and no longer evaluated. Safe to delete from Flagsmith.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: To Remove only means no evaluations were recorded in the selected environment during the configured stale threshold, not that the flag is no longer evaluated everywhere. State this limit and tell users to verify other environments and deployed versions before deleting the flag.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At docs/docs/managing-flags/feature-lifecycle.md, line 40:

<comment>`To Remove` only means no evaluations were recorded in the selected environment during the configured stale threshold, not that the flag is no longer evaluated everywhere. State this limit and tell users to verify other environments and deployed versions before deleting the flag.</comment>

<file context>
@@ -0,0 +1,67 @@
+- `Permanent`: Meant to stay, e.g. a kill switch. Never flagged for clean-up.
+- `Stale`: Still in the code, but [untouched for a while](/managing-flags/stale-flags). Time to remove it from the code.
+- `To Monitor`: Gone from the code, but still being evaluated, e.g. by an older release of the application. Wait before deleting.
+- `To Remove`: Gone from the code and no longer evaluated. Safe to delete from Flagsmith.
+
+```mermaid
</file context>
Suggested change
- `To Remove`: Gone from the code and no longer evaluated. Safe to delete from Flagsmith.
- `To Remove`: No code references were found in the latest scans and no evaluations were recorded in the selected environment during the stale threshold. Check other environments and deployed versions before deleting from Flagsmith.


```mermaid
flowchart LR
New -->|found in code| Live
Live -->|no changes for a while| Stale
Live -->|permanent tag| Permanent
Stale -->|removed from code| Monitor[To Monitor]
Monitor -->|evaluations stop| Remove[To Remove]
```

## How to set up

Make sure you set up [Code References](/managing-flags/code-references). Flagsmith does not have access to your
codebase, and only keeps track of where feature flags are referenced (file names and line numbers).

SDKs evaluating feature flags must also enable [Flag Analytics](/managing-flags/flag-analytics), so that Flagsmith knows
about per-feature usage.

The `Stale`, `To Monitor` and `To Remove` stages rely on
[Stale Flag Detection](/managing-flags/stale-flags#requirements), available on the **Scale-up** and **Enterprise**
plans.

:::note Self-hosted

Self-hosted installations of Flagsmith also need to ensure Flag Analytics is available on the API side. See
[Environment Variables](/deployment-self-hosting/core-configuration/environment-variables).

:::
4 changes: 2 additions & 2 deletions docs/docs/managing-flags/stale-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ reference to it in your codebase. Combine it with:

- **[Code References](/managing-flags/code-references)** — to locate every file and line where a stale flag is used, so
you can remove it in a single PR.
- **[Flag Lifecycle](/best-practices/flag-lifecycle)** — for guidance on when to remove short-lived flags versus keep
- **[Feature Flags Life Spans](/best-practices/flag-life-spans)** — for guidance on when to remove short-lived flags versus keep
long-lived ones.

A typical cleanup workflow: filter the Features list by the `Stale` tag, open each feature, use its Code References to
Expand All @@ -86,4 +86,4 @@ find the call sites, remove the flag from the codebase, then delete the flag in
- [Tagging](/managing-flags/tagging)
- [Code References](/managing-flags/code-references)
- [Feature Versioning](/managing-flags/feature-versioning)
- [Flag Lifecycle](/best-practices/flag-lifecycle)
- [Feature Flags Life Spans](/best-practices/flag-life-spans)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions docs/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,15 @@
},
{
"source": "/advanced-use/flag-lifecycle",
"destination": "/best-practices/flag-lifecycle"
"destination": "/best-practices/flag-life-spans"
},
{
"source": "/guides-and-examples/flag-lifecycle",
"destination": "/best-practices/flag-lifecycle"
"destination": "/best-practices/flag-life-spans"
},
{
"source": "/best-practices/flag-lifecycle",
"destination": "/best-practices/flag-life-spans"
},
{
"source": "/advanced-use/efficient-api-usage",
Expand Down
13 changes: 13 additions & 0 deletions frontend/common/utils/__tests__/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ describe('Format', () => {
})
})

describe('pluralise', () => {
it.each`
count | expected
${0} | ${'0 repositories'}
${1} | ${'1 repository'}
${2} | ${'2 repositories'}
`('pluralise($count, ...) returns "$expected"', ({ count, expected }) => {
expect(Format.pluralise(count, 'repository', 'repositories')).toBe(
expected,
)
})
})

describe('camelCase', () => {
it.each`
input | expected
Expand Down
5 changes: 5 additions & 0 deletions frontend/common/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ const Format = {

newLineDelimiter: '↵',

pluralise(count: number, singular: string, plural: string): string {
// 1, 'repository', 'repositories' > 1 repository
return `${count} ${count === 1 ? singular : plural}`
},

shortenNumber(number: NullableNumber): string {
// Converts a float number into a short literal with suffix for the magnitude:
// 1523125 > 1.5M
Expand Down
41 changes: 9 additions & 32 deletions frontend/web/components/feature-summary/FeatureTags.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { FC, useMemo } from 'react'
import SegmentOverridesIcon from 'components/icons/SegmentOverridesIcon'
import Constants from 'common/constants'
import { ProjectFlag, VCSProvider } from 'common/types/responses'
import { ProjectFlag } from 'common/types/responses'
import IdentityOverridesIcon from 'components/icons/IdentityOverridesIcon'
import TagValues from 'components/tags/TagValues'
import UnhealthyFlagWarning from './UnhealthyFlagWarning'
import StaleFlagWarning from './StaleFlagWarning'
import Tag from 'components/tags/Tag'
import Utils from 'common/utils/utils'
import { useGetHealthEventsQuery } from 'common/services/useHealthEvents'
import VCSProviderTag from 'components/tags/VCSProviderTag'
import CodeReferencesTag from 'components/tags/CodeReferencesTag'

type FeatureTagsType = {
editFeature: (tab?: string) => void
Expand Down Expand Up @@ -38,14 +38,6 @@ const FeatureTags: FC<FeatureTagsType> = ({ editFeature, projectFlag }) => {
}
const isFeatureHealthEnabled = Utils.getFlagsmithHasFeature('feature_health')

const hasScannedCodeReferences =
projectFlag?.code_references_counts?.length > 0
const codeReferencesCounts =
projectFlag?.code_references_counts?.reduce(
(acc, curr) => acc + curr.count,
0,
) || 0

return (
<>
<SegmentOverridesIcon
Expand All @@ -63,28 +55,13 @@ const FeatureTags: FC<FeatureTagsType> = ({ editFeature, projectFlag }) => {
count={projectFlag.num_identity_overrides}
showPlusIndicator={showPlusIndicator}
/>
{hasScannedCodeReferences && (
<Tooltip
title={
<div
onClick={(e) => {
e.stopPropagation()
editFeature(Constants.featurePanelTabs.USAGE)
}}
style={{ cursor: 'pointer' }}
>
<VCSProviderTag
count={codeReferencesCounts}
isWarning={codeReferencesCounts === 0}
vcsProvider={VCSProvider.GITHUB}
/>
</div>
}
place='top'
>
{`Scanned ${codeReferencesCounts?.toString()} times in ${projectFlag?.code_references_counts?.length?.toString()} repositories`}
</Tooltip>
)}
<CodeReferencesTag
counts={projectFlag.code_references_counts}
onClick={(e) => {
e.stopPropagation()
editFeature(Constants.featurePanelTabs.USAGE)
}}
/>
{projectFlag.is_server_key_only && (
<Tooltip
title={
Expand Down
42 changes: 4 additions & 38 deletions frontend/web/components/feature-summary/ProjectFeatureRow.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { FC } from 'react'
import classNames from 'classnames'
import { ProjectFlag, VCSProvider } from 'common/types/responses'
import { ProjectFlag } from 'common/types/responses'
import FeatureName from './FeatureName'
import FeatureDescription from './FeatureDescription'
import TagValues from 'components/tags/TagValues'
import VCSProviderTag from 'components/tags/VCSProviderTag'
import CodeReferencesTag from 'components/tags/CodeReferencesTag'

interface ProjectFeatureRowProps {
projectFlag: ProjectFlag
Expand Down Expand Up @@ -36,14 +36,6 @@ const ProjectFeatureRow: FC<ProjectFeatureRowProps> = ({
}
: undefined

const hasScannedCodeReferences =
projectFlag?.code_references_counts?.length > 0
const codeReferencesCounts =
projectFlag?.code_references_counts?.reduce(
(acc, curr) => acc + curr.count,
0,
) || 0

return (
<>
{/* Desktop */}
Expand Down Expand Up @@ -77,20 +69,7 @@ const ProjectFeatureRow: FC<ProjectFeatureRowProps> = ({
<div className='mx-0 flex-1 flex-column'>
<div className='d-flex align-items-center'>
<FeatureName name={projectFlag.name} />
{hasScannedCodeReferences && (
<Tooltip
title={
<VCSProviderTag
count={codeReferencesCounts}
isWarning={codeReferencesCounts === 0}
vcsProvider={VCSProvider.GITHUB}
/>
}
place='top'
>
{`Scanned ${codeReferencesCounts} times in ${projectFlag?.code_references_counts?.length} repositories`}
</Tooltip>
)}
<CodeReferencesTag counts={projectFlag.code_references_counts} />
<TagValues
projectId={`${projectFlag.project}`}
value={projectFlag.tags}
Expand Down Expand Up @@ -131,20 +110,7 @@ const ProjectFeatureRow: FC<ProjectFeatureRowProps> = ({
)}
<div className='flex-1 align-items-center flex-wrap'>
<FeatureName name={projectFlag.name} />
{hasScannedCodeReferences && (
<Tooltip
title={
<VCSProviderTag
count={codeReferencesCounts}
isWarning={codeReferencesCounts === 0}
vcsProvider={VCSProvider.GITHUB}
/>
}
place='top'
>
{`Scanned ${codeReferencesCounts} times in ${projectFlag?.code_references_counts?.length} repositories`}
</Tooltip>
)}
<CodeReferencesTag counts={projectFlag.code_references_counts} />
<TagValues
projectId={`${projectFlag.project}`}
value={projectFlag.tags}
Expand Down
50 changes: 50 additions & 0 deletions frontend/web/components/tags/CodeReferencesTag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { FC, MouseEvent } from 'react'
import { ProjectFlag, VCSProvider } from 'common/types/responses'
import Format from 'common/utils/format'
import Tooltip from 'components/Tooltip'
import VCSProviderTag from './VCSProviderTag'

type CodeReferencesTagProps = {
counts: ProjectFlag['code_references_counts'] | undefined
onClick?: (e: MouseEvent<HTMLDivElement>) => void
}

const CodeReferencesTag: FC<CodeReferencesTagProps> = ({ counts, onClick }) => {
if (!counts?.length) {
return null
}

const total = counts.reduce((sum, { count }) => sum + count, 0)
const scans = Format.pluralise(total, 'time', 'times')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: total counts code references found in the latest scans, not scan runs, so this reports the reference count as the number of scans. Label the total as references found instead.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At frontend/web/components/tags/CodeReferencesTag.tsx, line 18:

<comment>`total` counts code references found in the latest scans, not scan runs, so this reports the reference count as the number of scans. Label the total as references found instead.</comment>

<file context>
@@ -0,0 +1,50 @@
+  }
+
+  const total = counts.reduce((sum, { count }) => sum + count, 0)
+  const scans = Format.pluralise(total, 'time', 'times')
+  const repositories = Format.pluralise(
+    counts.length,
</file context>

const repositories = Format.pluralise(
counts.length,
'repository',
'repositories',
)
const tag = (
<VCSProviderTag
count={total}
isWarning={total === 0}
vcsProvider={VCSProvider.GITHUB}
/>
)

return (
<Tooltip
title={
onClick ? (
<div onClick={onClick} className='cursor-pointer'>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This click handler is attached to a non-focusable div, so keyboard users cannot open the Usage tab from this tag. Render it as a keyboard-operable control.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At frontend/web/components/tags/CodeReferencesTag.tsx, line 36:

<comment>This click handler is attached to a non-focusable `div`, so keyboard users cannot open the Usage tab from this tag. Render it as a keyboard-operable control.</comment>

<file context>
@@ -0,0 +1,50 @@
+    <Tooltip
+      title={
+        onClick ? (
+          <div onClick={onClick} className='cursor-pointer'>
+            {tag}
+          </div>
</file context>

{tag}
</div>
) : (
tag
)
}
place='top'
>
{`Scanned ${scans} in ${repositories}`}
</Tooltip>
)
}

export default CodeReferencesTag
Loading