diff --git a/docs/docs/best-practices/flag-lifecycle.md b/docs/docs/best-practices/flag-life-spans.md similarity index 94% rename from docs/docs/best-practices/flag-lifecycle.md rename to docs/docs/best-practices/flag-life-spans.md index 29e83237887f..472090cac2c3 100644 --- a/docs/docs/best-practices/flag-lifecycle.md +++ b/docs/docs/best-practices/flag-life-spans.md @@ -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 @@ -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 Flagsmith can automatically flag features that have not been changed for a configurable period of time — see [Stale Flag Detection](/managing-flags/stale-flags). @@ -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. diff --git a/docs/docs/best-practices/naming-conventions.md b/docs/docs/best-practices/naming-conventions.md index 9e8ccabef3cb..123bf48e4e4f 100644 --- a/docs/docs/best-practices/naming-conventions.md +++ b/docs/docs/best-practices/naming-conventions.md @@ -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 diff --git a/docs/docs/best-practices/structuring-your-projects.md b/docs/docs/best-practices/structuring-your-projects.md index 1ab75deb0506..b3d288ddf6a8 100644 --- a/docs/docs/best-practices/structuring-your-projects.md +++ b/docs/docs/best-practices/structuring-your-projects.md @@ -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 diff --git a/docs/docs/best-practices/when-to-use-flags.md b/docs/docs/best-practices/when-to-use-flags.md index 79689ccd7752..740b355cd112 100644 --- a/docs/docs/best-practices/when-to-use-flags.md +++ b/docs/docs/best-practices/when-to-use-flags.md @@ -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. diff --git a/docs/docs/managing-flags/code-references.md b/docs/docs/managing-flags/code-references.md index 2afa8aa57c1f..9b49ec7d4e39 100644 --- a/docs/docs/managing-flags/code-references.md +++ b/docs/docs/managing-flags/code-references.md @@ -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)

Code Reference counts displayed in Features list

@@ -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 diff --git a/docs/docs/managing-flags/feature-lifecycle.md b/docs/docs/managing-flags/feature-lifecycle.md new file mode 100644 index 000000000000..adc4d07883ac --- /dev/null +++ b/docs/docs/managing-flags/feature-lifecycle.md @@ -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. +- `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. + +```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). + +::: diff --git a/docs/docs/managing-flags/stale-flags.md b/docs/docs/managing-flags/stale-flags.md index e446ea954310..02dcff056d9f 100644 --- a/docs/docs/managing-flags/stale-flags.md +++ b/docs/docs/managing-flags/stale-flags.md @@ -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 @@ -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) diff --git a/docs/static/img/managing-flags/feature-lifecycle/stale-features.png b/docs/static/img/managing-flags/feature-lifecycle/stale-features.png new file mode 100644 index 000000000000..3c5a0fd1c22d Binary files /dev/null and b/docs/static/img/managing-flags/feature-lifecycle/stale-features.png differ diff --git a/docs/vercel.json b/docs/vercel.json index dd7221131aef..fc9f7fe62f00 100644 --- a/docs/vercel.json +++ b/docs/vercel.json @@ -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", diff --git a/frontend/common/utils/__tests__/format.test.ts b/frontend/common/utils/__tests__/format.test.ts index 6960247d4fea..82164c20c0e4 100644 --- a/frontend/common/utils/__tests__/format.test.ts +++ b/frontend/common/utils/__tests__/format.test.ts @@ -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 diff --git a/frontend/common/utils/format.ts b/frontend/common/utils/format.ts index 9c029b8d9b23..869a29663165 100644 --- a/frontend/common/utils/format.ts +++ b/frontend/common/utils/format.ts @@ -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 diff --git a/frontend/web/components/feature-summary/FeatureTags.tsx b/frontend/web/components/feature-summary/FeatureTags.tsx index 626830db5a7b..eecd7ff81829 100644 --- a/frontend/web/components/feature-summary/FeatureTags.tsx +++ b/frontend/web/components/feature-summary/FeatureTags.tsx @@ -1,7 +1,7 @@ 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' @@ -9,7 +9,7 @@ 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 @@ -38,14 +38,6 @@ const FeatureTags: FC = ({ 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 ( <> = ({ editFeature, projectFlag }) => { count={projectFlag.num_identity_overrides} showPlusIndicator={showPlusIndicator} /> - {hasScannedCodeReferences && ( - { - e.stopPropagation() - editFeature(Constants.featurePanelTabs.USAGE) - }} - style={{ cursor: 'pointer' }} - > - - - } - place='top' - > - {`Scanned ${codeReferencesCounts?.toString()} times in ${projectFlag?.code_references_counts?.length?.toString()} repositories`} - - )} + { + e.stopPropagation() + editFeature(Constants.featurePanelTabs.USAGE) + }} + /> {projectFlag.is_server_key_only && ( = ({ } : 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 */} @@ -77,20 +69,7 @@ const ProjectFeatureRow: FC = ({
- {hasScannedCodeReferences && ( - - } - place='top' - > - {`Scanned ${codeReferencesCounts} times in ${projectFlag?.code_references_counts?.length} repositories`} - - )} + = ({ )}
- {hasScannedCodeReferences && ( - - } - place='top' - > - {`Scanned ${codeReferencesCounts} times in ${projectFlag?.code_references_counts?.length} repositories`} - - )} + ) => void +} + +const CodeReferencesTag: FC = ({ counts, onClick }) => { + if (!counts?.length) { + return null + } + + const total = counts.reduce((sum, { count }) => sum + count, 0) + const scans = Format.pluralise(total, 'time', 'times') + const repositories = Format.pluralise( + counts.length, + 'repository', + 'repositories', + ) + const tag = ( + + ) + + return ( + + {tag} +
+ ) : ( + tag + ) + } + place='top' + > + {`Scanned ${scans} in ${repositories}`} + + ) +} + +export default CodeReferencesTag