Best Solutions for Automated Feature Flag Cleanup
Cleanup is one of the most annoying things about feature flags. It can be difficult to know which flags are actively being used, and which can be cleaned up. But even if you’re able to identify which needs cleaning up, it’s a chore to do.
Removing the obsolete flag code is often straightforward, but the task management, context switching, waiting for tests to complete, and code review all make it a frustrating task. Many teams just don’t clean up flags, while others put it off. But we regret it when we do, as stale flags build up, our code becomes unwieldy, and then it becomes a real problem.
Many feature flag providers recognize the problem but their solutions are usually CLI tools that identify feature key mentions in your code, while others show you flags that haven’t been accessed in a while. But these only make things less painful, you’re still on the hook to do the work.
The real solution is to automate feature flag cleanup entirely, and there are a few options. In this article, we’ll walk through different solutions for automated feature flag cleanup, so you can choose the best tool for you.
1. Reflag: self-cleaning feature flags with AI
Score: 5/5
Reflag offers self-cleaning flags. It’s an AI-based solution to flag cleanup that uses LLMs to refactor code to remove stale flags and outdated flag code.
The result: An entirely automated flag cleanup solution. All you need to do is review and approve the PRs it generates to remove unused flag code. Once merged, the flag is archived automatically.
How it works
Reflag’s self-cleaning flags combine a range of features that help to automate flag cleanup. Firstly, they have stale flag detection. Reflag performs continuous checks, assessing whether a flag has been rolled out to everyone, whether the flag code has been removed, and whether access checks haven't run recently.
Once the checks pass, the flag is marked as stale (denoted with a broom icon) and it’s added to the stale flag view - a list where you can see all the features that are currently stale, as well as what needs to be done before they can be archived.
When a flag becomes stale, the AI flag cleanup agent runs. The Reflag agent, which operates as a GitHub integration, searches for usage of the Reflag SDK in the codebase and identifies where specific feature keys are used. LLMs are employed to refactor the code to remove the flag and eliminate codepaths that become unreachable.
With the obsolete flag code removed, their auto-archiving automation can run. It archives flags when all archival checks pass. Finally, they also have archive Slack reminders and notifications.
You can get Slack reminders when a flag becomes stale and when a flag is ready to be archived. Or just get notified when the flag has been auto-archived instead.
These combine to make a comprehensive system for automating feature flag cleanup, putting it entirely on autopilot (except for the PR reviews).
2. Piranha: code transformation toolset without AI
Score: 3/5
Developed by Uber, Piranha (PolyglotPiranha) is an open-source, lightweight code transformation toolset for automating large scale changes that they use mostly for cleaning up stale feature flags.
It can be used as a Python library or as a command-line tool and works for the languages that Uber uses internally, including Objective-C, Swift, and Java. Although, there are a number of forks.
It works by taking the name of the flag and the expected behavior as inputs. You specify a list of APIs in a properties file, and then Piranha uses this info to automatically refactor the code according to the expected behavior. Under the hood, it analyzes the abstract syntax trees (ASTs) of the program to generate appropriate refactorings which are packaged into a diff.
Some users note that Piranha requires significant setup per language and the launch post for Piranha is no longer online. However, there’s a version you can check out via the Wayback Machine, documentation is available on GitHub, and there’s a video providing an overview on YouTube.
3. Codemod: Enterprise code transformations
Score: 4/5
Codemod is a platform to de-risk, automate, and orchestrate large-scale code changes. It’s created for platform teams and engineering leaders to de-risk and automate large-scale code migrations that’s purpose-built for enterprise-wide transformations.
Codemods can be used to autonomously handle the removal of feature flags and subsequent code refactoring. They function similar to Reflag agent in that they automate the identification and replacement of feature flag SDK calls, as well as performing the necessary code refactoring to maintain code quality.
However, since it’s not a feature flag tool itself, they don’t identify stale flags or automate the archiving of flags. Their solution works with specific feature flags providers, in this case: DevCycle and Statsig, but they say they can support others.
Conclusion
Staying on top of stale feature flags can be difficult. However, there are solutions that can help you to automate feature flag cleanup entirely. With the right solution, you can make the flag cleanup problem a thing of the past.