Skip to content

A sample application that demonstrates the consumption of Feature Flags service on SAP Cloud Platform, Cloud Foundry environment

License

Notifications You must be signed in to change notification settings

SAP-samples/cloud-cf-feature-flags-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

REUSE status

Feature Flags Service Demo Application

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. There is also one REST end-point that reads the value of VCAP_SERVICES environment variable.

Prerequisites

Running the Application on SAP BTP

Follow these steps to run the Feature Flags Service Demo application on SAP BTP, Cloud Foundry environment.

Note: This guide uses the Cloud Foundry trial account on Europe (Frankfurt) region (https://account.hanatrial.ondemand.com/cockpit#/home/overview). If you want to use a different region, you have to modify the domain in the requests. For more information about regions and hosts on SAP BTP, Cloud Foundry environment, see Regions and Hosts.

1. Build the feature-flags-demo Application

$ 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, use the clean install goal from Run As > Maven Build... menu.

2. Edit application name in manifest file

Due to CloudFoundry's limitiation in regards to application naming it's quite possible for someone to have already deployed the Feature Flags demo application with the feature-flags-demo name as it is currently set in the manifest.yml file. CloudFoundry will not allow another application with the same name to be deployed, so you MUST edit the manifest file and change the application name before deploying. For example:

---
applications:
- name: feature-flags-demo123
  path: target/feature-flags-demo.jar

Note: Use the modified value in the commands which require application name (e.g. cf bind-service) and when requesting the application in the browser or via curl.

3. Deploy feature-flags-demo on SAP BTP

$ cf api https://api.cf.eu10.hana.ondemand.com
$ cf login
$ cf push

4. Create a Service Instance of Feature Flags service

4.1 Ensure the feature-flags Service Exists in the Marketplace

$ cf marketplace

-----
Getting services from marketplace in org <ORG_ID> / space dev as <USER_ID>...
OK
service          	plans    	description
...
feature-flags    	standard     	Feature Flags service for controlling feature rollout
...

4.2 Create a Service Instance of Feature Flags with Plan standard

$ cf create-service feature-flags standard feature-flags-instance

-----
Creating service instance feature-flags-instance in org <ORG_ID> / space dev as <USER_ID>...
OK

Note: Alternatively, you can also use the SAP BTP Cockpit. See Create a Service Instance.

5. Call the feature-flags-demo Application's /vcap_services End-Point

Note: Expect to receive an empty JSON.

The /vcap_services end-point simply returns the content of VCAP_SERVICES environment variable. As for now there is no service instances bound to feature-flags-demo, so you will receive an empty JSON.

In the command you use the following URL: <application_URL>/vcap_services. You can find the <application_URL> in the SAP BTP Cockpit, in the feature-flag-demo > Overview > Application Routes.

$ curl https://feature-flags-demo.cfapps.eu10.hana.ondemand.com/vcap_services

6. Bind feature-flags-demo to feature-flags-instance

$ cf bind-service feature-flags-demo feature-flags-instance

-----
Binding service feature-flags-instance to app feature-flags-demo in org <ORG_ID> / space dev as <USER_ID>...
OK
TIP: Use 'cf restage feature-flags-demo' to ensure your env variable changes take effect

Note: Alternatively, you can also use the SAP BTP Cockpit. See Bind Your Application to the Feature Flags Service Instance.

7. Restage feature-flags-demo

Restage feature-flags-demo application so the changes in the application environment take effect.

$ cf restage feature-flags-demo

8. Ensure that feature-flags-instance is Bound to feature-flags-demo

Note: Expect to receive the injected environment variables by the Feature Flags service.

$ curl https://feature-flags-demo.cfapps.eu10.hana.ondemand.com/vcap_services

Sample JSON response:

{
  "feature-flags": [
    {
      "credentials": {
        "x509": {
          "certificate": "...",
          "key": "...",
          "clientid": "...",
          "...": "..."
        },
        "password": "aa_GgZf1GIDZbuXV9s0RknzRE+qs0e=",
        "uri": "https://feature-flags.cfapps.eu10.hana.ondemand.com",
        "username": "sbss_x324osjl//pmabsuskr6nshmb2arw6dld4hfb3cj4m2bonkqmm3ts6c68mdpzxz2fma="
      },
      "syslog_drain_url": null,
      "volume_mounts": [ ],
      "label": "feature-flags",
      "provider": null,
      "plan": "standard",
      "name": "feature-flags-instance",
      "tags": [
        "feature-flags"
      ]
    }
  ]
}

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: navigate to feature-flags-demo application overview in the SAP BTP Cockpit. Open the link from the Application Routes section (for example, https://feature-flags-demo.cfapps.eu10.hana.ondemand.com). An 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 via the SAP BTP Cockpit: navigate to your subaccount, subscribe to the Feature Flags dashboard via creating an instance of the Feature Flags service, plan dashboard if haven't done so already. Access Feature Flags dashboard from the list of subscribed applications. Select the service instance you are currently working with.

The dashboard could be accessed directly via URL like https://<subdomain>.feature-flags-dashboard.cfapps.eu10.hana.ondemand.com/manageinstances/<instance-id>. The instance ID is a unique ID of the service instance.

9. Evaluate a Missing Feature Flag

Note: Expect the feature flag to be missing.

  1. Open the demo application as described here.
  2. Evaluate a feature flag with random name (for example, type in 'my-boolean-flag'). The result should state that the feature flag with the given name is missing.

10. Create a New Boolean Feature Flag

  1. Open the Feature Flags dashboard as described here.
  2. Choose New Flag.
  3. Fill in the required fields (for example, 'my-boolean-flag' for Name, 'Super cool feature' for Description and 'OFF' for State).
  4. Choose Save.

11. Evaluate the Newly Created Boolean Feature Flag

Note: Expect the variation to be false.

  1. Open the demo application as described here.
  2. Enter the boolean feature flag name in the Feature Flag Name field and choose Evaluate.
  3. Evaluate the newly created feature flag. The result should state that the feature flag is of type BOOLEAN and its variation is false.

12. Enable the Boolean Feature Flag

  1. Open the Feature Flags dashboard as described here.
  2. Enable the boolean feature flag using the switch in the Active column.

13. Verify that the Boolean Feature Flag is Enabled

Note: Expect the feature flag to be enabled.

  1. Open the demo application as described here.
  2. Enter the boolean feature flag name in the Feature Flag Name field and choose Evaluate.
  3. Evaluate the feature flag. The result should state that the feature flag is of type BOOLEAN and its variation is true.

14. Create a New String Feature Flag

  1. Open the Feature Flags dashboard as described here.
  2. Choose New Flag.
  3. Fill in the required fields (for example, 'my-string-flag' for Name, 'Coolest of features' for Description, choose String as Flag Type and 'OFF' for State). 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 a '+' sign) to add a field for it): variation-for-friends-and-family
  1. Select Var. 2 in the Deliver combobox in the Default Variation section.
  2. Choose Save.

15. Evaluate the Newly Created String Feature Flag

Note: Expect the variation to be variation-when-inactive.

  1. Open the demo application as described here.
  2. Enter the string feature flag name in the Feature Flag Name field and choose Evaluate.
  3. Evaluate the newly created feature flag. The result should state that the feature flag is of type STRING and its variation is variation-when-inactive.

16. Enable the String Feature Flag

  1. Open the Feature Flags dashboard as described here.
  2. Enable the string feature flag using the switch in the Active column.

17. Verify that the String Feature Flag is Enabled

Note: Expect the variation to be variation-when-active.

  1. Open the demo application as described here.
  2. Enter the string feature flag name in the Feature Flag Name field and choose Evaluate.
  3. Evaluate the feature flag. The result should state that the feature flag is of type STRING and its variation is variation-when-active.

18. Specify Direct Delivery Strategy of a Variation of the String Flag

  1. Open the Feature Flags dashboard as described here.
  2. Select the string feature flag.
  3. Set it to edit mode via choosing the Edit Flag button in the toolbar.
  4. Go to Strategy section, Direct Delivery sub-section and choose the button with '+' sign.
  5. Select Var. 3 from the combobox and enter friends-and-family in the text input.
  6. Choose Save.

19. Evaluate the String Feature Flag Using Identifier

Note: Expect the variation to be variation-for-friends-and-family.

  1. Open the demo application as described here.
  2. Enter the string feature flag name in the Feature Flag Name field, enter friends-and-family in the Identifier (optional) field and choose Evaluate.
  3. Evaluate the feature flag. The result should state that the feature flag is of type STRING and its variation is variation-for-friends-and-family.

Note: Once direct delivery is configured, Feature Flags service requires providing an identifier. An error is returned if such is not present. Variation variation-when-active is returned for all identifiers except those explicitly configured in the Feature Flags dashboard for which the provided rules apply (like for the friends-and-family identifier).

About

A sample application that demonstrates the consumption of Feature Flags service on SAP Cloud Platform, Cloud Foundry environment

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published