Feature Flags Service Demo Application
Description
Feature Flags service Demo Application is a simple Spring Boot application that consumes the Feature Flags service on SAP BTP, Cloud Foundry environment. It implements a feature toggle (evaluation call to the Feature Flags service) and exposes this feature toggle through a Web user interface.
Requirements
Running the Application on SAP BTP
💡NOTE: This guide uses the eu20 region (https://emea.cockpit.btp.cloud.sap/cockpit#).
To use a different SAP BTP region, you need to modify the domain in the requests. See: Cloud Foundry Regions and API Endpoints
Follow the steps below to run Feature Flags Demo Application on SAP BTP, Cloud Foundry environment.
1. Build the feature-flags-demo Application
Run the following commands, consequently:
$ git clone git@github.com:SAP/cloud-cf-feature-flags-sample.git
$ cd cloud-cf-feature-flags-sample
$ mvn clean install
Note: Alternatively, you can use the Eclipse IDE. Choose the clean install goal from the Run As > Maven Build... menu.
2. Edit application name in manifest file
It's quite possible that someone else has already deployed the Feature Flags Demo Application with the name feature-flags-demo (as it is currently set in the manifest.yml file).
Cloud Foundry does not allow two applications with the same name to be deployed in the same region! Therefore, we highly recommend that you change the application name in the manifest.yml file before deploying. For example:
---
applications:
- name: feature-flags-demo123
path: target/feature-flags-demo.jar
💡NOTE: Use the modified value in all commands that require application name, as well as when requesting the application in a browser or via curl.
3. Create a Service Instance of Feature Flags service
The application requires a Feature Flags service instance to be bound at startup. Create the service instance before deploying.
3.1 Ensure the feature-flags service exists in the Service Marketplace
Run the following command:
$ cf marketplace
Result:
-----
Getting services from marketplace in org <ORG_ID> / space <SPACE> as <USER_ID>...
OK
service plans description
...
feature-flags lite, standard Feature Flags service for controlling feature rollout
...
NOTE: If you're using a trial account, the only available service plan will be lite.
3.2 Create a Service Instance of Feature Flags
For a productive account, run:
$ cf create-service feature-flags standard feature-flags-instance
For a trial account, run:
$ cf create-service feature-flags lite feature-flags-instance
Note: Alternatively, you can use the SAP BTP cockpit. See Create a Service Instance.
4. Deploy feature-flags-demo on SAP BTP
Log in to your Cloud Foundry landscape. (The eu20 region is just an example.) Run:
$ cf login -a https://api.cf.eu20.hana.ondemand.com
Choose your subaccount (org) and space.
Deploy the application. Run:
$ cf push
The manifest.yml declares feature-flags-instance as a required service, so Cloud Foundry binds it automatically during deployment.
Accessing the Demo Application
The web interface of the demo application will be accessed multiple times throughout this tutorial. Here is how to open it:
- Go to the SAP BTP cockpit.
- Navigate to the
feature-flags-demo application overview.
- Open the link from the Application Routes section. For example:
https://feature-flags-demo-happy-bear.cfapps.eu20.hana.ondemand.com
- The Evaluation Form opens.
Accessing the Feature Flags Dashboard
The Feature Flags Dashboard will be accessed multiple times throughout this tutorial. Here is how to open it:
- Go to the SAP BTP cockpit.
- Navigate to your subaccount.
- Create a subscription to Feature Flags Dashboard. To do that, create an instance of the Feature Flags service, with plan
dashboard.
- Access Feature Flags Dashboard from the list of subscribed applications.
- Select the service instance you are currently working with.
💡NOTE: The dashboard URL always has the following pattern:
https://<subdomain\>.feature-flags-dashboard.cfapps.eu20.hana.ondemand.com/manageinstances/<instance-id\>
The is a unique ID of your Feature Flag service instance.
5. Evaluate a Missing Feature Flag
Note: Expect the feature flag to be missing.
- Open the demo application as described here.
- Enter a feature flag with a random name, for example
my-boolean-flag.
- Choose Evaluate.
- The result should state that a feature flag with this name is missing.
6. Create a New Boolean Feature Flag
- Open the
Feature Flags Dashboard as described here.
- Choose New Flag.
- Fill in the required fields. For example:
- Name:
my-boolean-flag
- Description:
Super cool feature
- State:
OFF
- Choose Save.
7. Evaluate the Newly Created Boolean Feature Flag
Note: Expect the variation to be false.
- Open the demo application as described here.
- Enter the Boolean feature flag name.
- Choose Evaluate.
- The result should state that the feature flag is of type
BOOLEAN and its variation is false.
8. Enable the Boolean Feature Flag
- Open the
Feature Flags Dashboard as described here.
- Enable the Boolean feature flag using the switch in the Enabled column.
9. Verify that the Boolean Feature Flag is Enabled
Note: Expect the variation to be true.
- Open the demo application as described here.
- Enter the Boolean feature flag name.
- Choose Evaluate.
- The result should state that the feature flag is of type
BOOLEAN and its variation is true.
CAUTION!
The next procedures (10 - 15) are only applicable for productive accounts, which means plan standard.
10. Create a New String Feature Flag
- Open the
Feature Flags Dashboard as described here.
- Choose New Flag.
- Fill in the required fields. For example:
- Name:
my-string-flag
- Description:
Coolest of features
- Type:
String
- State:
OFF
- Enter the following values as different variations of the flag:
- Var. 1:
variation-when-inactive
- Var. 2:
variation-when-active
- Var. 3 (choose the Add button with the '+' sign to add a new field):
variation-for-friends-and-family
- From the Default Variation tab in the Strategy section open the Deliver combo box and select
Var. 2.
- Choose Save.
11. Evaluate the Newly Created String Feature Flag
Note: Expect the variation to be variation-when-inactive.
- Open the demo application as described here.
- Enter the string feature flag name.
- Choose Evaluate.
- The result should state that the feature flag is of type
STRING and its variation is variation-when-inactive.
12. Enable the String Feature Flag
- Open the
Feature Flags Dashboard as described here.
- Enable the string feature flag using the switch in the Enabled column.
13. Verify that the String Feature Flag is Enabled
Note: Expect the variation to be variation-when-active.
- Open the demo application as described here.
- Enter the string feature flag name.
- Choose Evaluate.
- The result should state that the feature flag is of type
STRING and its variation is variation-when-active.
14. Specify Direct Delivery Strategy of a Variation of the String Flag
- Open the
Feature Flags Dashboard as described here.
- Select the string feature flag.
- Choose the Edit Flag button.
- Go to the Strategy section, Direct Delivery tab, and choose the '+' button.
- Select Var. 3 from the combobox and enter
friends-and-family in the text input.
- Choose Save.
15. Evaluate the String Feature Flag Using Identifier
Note: Expect the variation to be variation-for-friends-and-family.
- Open the demo application as described here.
- Enter the string feature flag name.
- For the Identifier (optional) field, enter
friends-and-family.
- Choose Evaluate.