Sometimes you need a feature toggle in a rush … or just dont want to invest time in adding a feature toggle framework…
This thought came to me while I was working on some bot and had to protect myself with a feature toggle, problem was the bot was written with micro services, some in scala, some in java, some in php and even bash …
Main idea was to hold a centralised location with the feature toggle state, each service can obtain this state.
Ive made a list of the feature toggle requirement:
-Protected with some kind of Auth
-NO SSH to production machines.
-Not code changes (in app), no deployments to change state
-Change feature toggle state from any device with internet (phone, laptop, internet cafe etc…)
-Hold record of state change (to know who and when changed the feature toggle state)
-GitHub repo/gist with json file holding the feature toggle state – https://gist.github.com/Nimrod007/843580c66ef973d6fb3b
-Easy to login and change the json with any device.
-GitHub availability is high.
-Each gist/repo has a change log so tracking changes is easy
-Each micro-service will make a HTTP GET request to get the feature toggle state (this is expensive IO but can be reduced with caching on a file on the system that each micro-service can read from if needed)
JSON in GitHub example:
"active" : true
PHP snippet, fetching the state from GitHub and deciding to act/skip the feature toggle:
//Get json from github
$json = file_get_contents('https://gist.githubusercontent.com/Nimrod007/843580c66ef973d6fb3b/raw');
//get boolean feature toggle
$isActive = json_decode($json)->active;
//check if toggle is on/off
echo "Feature Toggle is up";
echo "Feature Toggle is down";