This is a submission for the DevCycle Feature Flag Challenge: Feature Flag Funhouse
What I Built
This POC project leverages the use of DevCycle feature flags to skip necessary controller actions by either returning a specific JSON response, returning an existing template or redirecting to a specific path.
Considering a scenario that a bug is observed in one of our APIs, say the POST /add-funds
path, where existing feature flags won't be able to mitigate the issue. There might be massive impact until the deployment rollback is completed. The quickest way to immediately lower this impact is to skip the logic for that specific API, which is where the feature flag is being used here.
The current demo includes render
& redirect
handlers:
- for
render
, this POC includes types with-
json
: return ajson
response -
template
: return an existingtemplate
-
- for
redirect
, it can redirect to anrelative_path
that is already available in the codebase.
Since it's only a POC project, the handling approach can be extended depending on the needs, e.g. redirect to an external link, render xml response. The main idea is to skip the application logic to avoid/mitigate further (downstream) impact in response to production issues.
The path in feature flag config (e.g. /test?case=return_home
) is currently considering the query string, but depending on the usage, it should be able to accept wildcard, distinguish different HTTP methods (e.g. GET
, POST
, PATCH
etc) and so on, but this POC will not include those features for now.
Demo
DevCycle Feature Flag for skip_controller_action_configs
Example
{
"/test": {
"handler": "render",
"handler_attrs": {
"type": "json",
"value": {
"status": "ok"
}
}
},
"/test?case=return_home": {
"handler": "render",
"handler_attrs": {
"type": "template",
"value": "hello/index"
}
},
"/test?case=redirect": {
"handler": "redirect",
"handler_attrs": {
"type": "relative_path",
"value": "/redirect"
}
},
"/test?case=incorrect_value": {
"handler": "render",
"handler_attrs": {
"type": "unknown_type",
"value": "unknown_value"
}
}
}
Test Case Example
API response
-
http://localhost:8000/test
- return
{"status":"ok"}
- it should return
{ message: "tested OK" }
if no feature flag is setup
- it should return
- return
-
http://localhost:8000/test?case=return_home
- render home template
-
http://localhost:8000/test?case=redirect
- return
{"message":"redirect success!"}
- the request has been redirect to
/redirect
path
- the request has been redirect to
- return
-
http://localhost:8000/test?case=incorrect_value
- return
{"message":"tested OK"}
- due to incorrect
['handler_attrs']['type']
in the feature flag config, i.e. controller actions wont be skipped
- due to incorrect
- return
-
http://localhost:8000/test?unknown
- return
{"message":"tested OK"}
- no handling is configured in the feature flag
- return
My Code
https://github.com/p-pt/skip-controller-action
My DevCycle Experience
The JSON
variable type increases the flexibility on the values to be configured, on the other hands, there might be type safety concerns for mis-configuration, e.g. some keys under the json is expecting a string value but it's being configured to number etc. In view of that, it might be beneficial if user can set up some validation rules, e.g. for a variable named
-
satisfaction_in_percentage
withnumber
type, the value can only be between 0 and 100, -
difficulty_level
withstring
type, the value can only below
,medium
,hard
etc
Top comments (0)