DEV Community

pp
pp

Posted on

Submission for the DevCycle Feature Flag Challenge: Skip Controller Actions

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 a json response
    • template: return an existing template
  • for redirect, it can redirect to an relative_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"
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Test Case Example

API response

  1. http://localhost:8000/test

    • return {"status":"ok"}
      • it should return { message: "tested OK" } if no feature flag is setup
  2. http://localhost:8000/test?case=return_home

    • render home template
  3. http://localhost:8000/test?case=redirect

    • return {"message":"redirect success!"}
      • the request has been redirect to /redirect path
  4. 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
  5. http://localhost:8000/test?unknown

    • return {"message":"tested OK"}
      • no handling is configured in the feature flag

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 with number type, the value can only be between 0 and 100,
  • difficulty_level with string type, the value can only be low, medium, hard etc

Additional Prize Categories

Top comments (0)