-
Notifications
You must be signed in to change notification settings - Fork 197
[Demo] Feature Flag related cleanup
Ameya Ketkar edited this page Jan 4, 2023
·
2 revisions
We believe, the easiest way to get started with Piranha is to build upon the demos.
To set up the repository:
git clone https://github.com/uber/piranha.git && cd piranha
python3 -m venv .env && source .env/bin/activate
cargo build --no-default-features && maturin develop
To run the demo :
python3 demo/stale_feature_flag_cleanup_demos.py
This script will transform the scenarios the below scenario listed under /demo/feature_flag_cleanup/java, based on demo/feature_flag_cleanup/java/configurations
, as shown below.
Piranha replaces the expression exp.isToggleEnabled(SAMPLE_STALE_FLAG)
with true
and exp.isToggleDisabled(SAMPLE_STALE_FLAG)
with false
. It then follows it up by simplifying the if-else
logic.
SampleClass.java (Before) | SampleClass.java After |
class SampleJava {
public void sampleMethod(ExperimentInterface exp) {
if (exp.isToggleEnabled(SAMPLE_STALE_FLAG)) {
System.out.println("SAMPLE_STALE_FLAG is enabled");
} else {
System.out.println("SAMPLE_STALE_FLAG is disabled");
}
}
public void sampleMethod1(ExperimentInterface exp) {
if (exp.isToggleDisabled(ExpEnum.SAMPLE_STALE_FLAG)) {
System.out.println("SAMPLE_STALE_FLAG is disabled");
} else {
System.out.println("SAMPLE_STALE_FLAG is enabled");
}
}
} |
class SampleJava {
public void sampleMethod(ExperimentInterface exp) {
System.out.println("SAMPLE_STALE_FLAG is enabled");
}
public void sampleMethod1(ExperimentInterface exp) {
System.out.println("SAMPLE_STALE_FLAG is enabled");
}
} |
Inside the configurations
:
-
rules.toml
declare Piranha Rules to- replace the occurrences of expressions like
exp.isToggleEnabled(SAMPLE_STALE_FLAG)
withtrue/false
- delete the enum cases with a particular name
- replace the occurrences of expressions like
-
piranha_arguments.toml
declares the flag behavior, i.e. the flag name and whether it is treated or not.
- Home
- API
- Stale feature flag related cleanup
- Piranha in-depth
- Piranha's Core Framework
- Piranha Rules
- Rule Graph
- Piranha Arguments
- [Advanced] Other use-cases
- Custom Refactoring
- Code Search
- Onboarding a new language