- Notifications
You must be signed in to change notification settings - Fork7
A sample application that demonstrates the consumption of Feature Flags service on SAP Cloud Platform, Cloud Foundry environment
License
SAP-samples/cloud-cf-feature-flags-sample
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Feature Flags service Demo Application is a simple Spring Boot application that consumes theFeature Flags service on SAP BTP, Cloud Foundry environment. It implements afeature 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 ofVCAP_SERVICES environment variable.
You have set upMaven 3.0.x.
You have anSAP BTP enterprise (productive) account on Cloud Foundry environment.
💡NOTE: You can also use atrial account but some functionalities won't be available for you.
You have a space on a Cloud Foundry instance -productive ortrial.
You have set up thecurl plug-in for
cmd.You have installedcf CLI.
💡NOTE: This guide uses theeu20 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 runFeature Flags Demo Application on SAP BTP, Cloud Foundry environment.
- 1. Build the feature-flags-demo Application
- 2. Edit application name in manifest file
- 3. Deploy feature-flags-demo on SAP BTP
- 4. Create a Service Instance of Feature Flags service
- 5. Call the feature-flags-demo Application's /vcap_services End-Point
- 6. Bind feature-flags-demo to feature-flags-instance
- 7. Restage feature-flags-demo
- 8. Ensure that feature-flags-instance is bound to feature-flags-demo
- Accessing the Demo Application
- Accessing the Feature Flags Dashboard
- 9. Evaluate a Missing Feature Flag
- 10. Create a New Boolean Feature Flag
- 11. Evaluate the Newly Created Boolean Feature Flag
- 12. Enable the Boolean Feature Flag
- 13. Verify that the Boolean Feature Flag is Enabled
- 14. Create a New String Feature Flag
- 15. Evaluate the Newly Created String Feature Flag
- 16. Enable the String Feature Flag
- 17. Verify that the String Feature Flag is Enabled
- 18. Specify Direct Delivery Strategy of a Variation of the String Flag
- 19. Evaluate the String Feature Flag Using Identifier
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 installNote: Alternatively, you can use the Eclipse IDE. Choose the
clean installgoal from theRun As > Maven Build... menu.
It's quite possible that someone else has already deployed theFeature Flags Demo Application with the namefeature-flags-demo (as it is currently set in themanifest.yml file).Cloud Foundry does not allow two applications with the same name to be deployed in the same region! Therefore, wehighly recommend that you change the application name in themanifest.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 viacurl.
Log in to your Cloud Foundry landscape. (The
eu20region is just an example.) Run:$ cf login -a https://api.cf.eu20.hana.ondemand.comChoose your subaccount (org) and space.
Deploy the application. Run:
$ cf push
Run the following command:
$ cf marketplaceResult:
-----Getting services from marketplace in org <ORG_ID> / space <SPACE> as <USER_ID>...OKservice 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 belite.
For a productive account, run:
$ cf create-service feature-flags standard feature-flags-instanceFor a trial account, run:
$ cf create-service feature-flags lite feature-flags-instance
Note: Alternatively, you can use the SAP BTP cockpit. SeeCreate a Service Instance.
Note: Expect to receive an empty JSON code - {}.
The/vcap_services end-point simply returns the content of theVCAP_SERVICES environment variable. As for now, there is no service instance bound tofeature-flags-demo, thus you receive an empty JSON.
In the command you use the following URL:\<application_URL\>/vcap_services.
To find the value of\<application_URL\>, go to the SAP BTP cockpit >feature-flag-demo >Overview >Application Routes.
To call the application, run (for example):
$ curl https://feature-flags-demo.cfapps.eu20.hana.ondemand.com/vcap_services$ cf bind-service feature-flags-demo feature-flags-instance -c '{"enableBasicAuth": true}'-----Binding service feature-flags-instance to app feature-flags-demo in org <ORG_ID> / space <SPACE> as <USER_ID>...OKTIP: Use 'cf restage feature-flags-demo' to ensure your env variable changes take effectNote: Alternatively, you can use the SAP BTP cockpit. SeeBind Your Application to the SAP Feature Flags Service Instance.
Restagefeature-flags-demo application so the changes in the application environment take effect.
$ cf restage feature-flags-demoNote: Expect to receive the injected environment variables by the Feature Flags service.
$ curl https://feature-flags-demo.cfapps.eu10.hana.ondemand.com/vcap_servicesSample JSON response:
{"feature-flags": [ {"credentials": {"x509": {"certificate":"...","key":"...","clientid":"...","...":"..." },"password":"aa_12345678XYZZZZZ000mnopRE+qs0e=","uri":"https://feature-flags.cfapps.eu20.hana.ondemand.com","username":"sbss_x234osj//pmabsuskr6nshmb2arw6dld4hfb3cj4m2bonkqmm3ts6c68mdpzxz2fma=" },"syslog_drain_url":null,"volume_mounts": [ ],"label":"feature-flags","provider":null,"plan":"standard","name":"feature-flags-instance","tags": ["feature-flags" ] } ]}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-demoapplication overview. - Open the link from theApplication Routes section. For example:
https://feature-flags-demo-happy-bear.cfapps.eu20.hana.ondemand.com - TheEvaluation Form opens.
TheFeature 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 toFeature Flags Dashboard. To do that, create an instance of the Feature Flags service, with plan
dashboard. - AccessFeature 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.
Note: Expect the feature flag to be missing.
- Open the demo application as describedhere.
- Enter a feature flag with a random name, for example
my-boolean-flag. - ChooseEvaluate.
- The result should state that a feature flag with this name is missing.
- Open the
Feature Flags Dashboardas describedhere. - ChooseNew Flag.
- Fill in the required fields. For example:
- Name:
my-boolean-flag - Description:
Super cool feature - State:
OFF
- Name:
- ChooseSave.
Note: Expect the variation to be
false.
- Open the demo application as describedhere.
- Enter the Boolean feature flag name.
- ChooseEvaluate.
- The result should state that the feature flag is of type
BOOLEANand its variation isfalse.
- Open the
Feature Flags Dashboardas describedhere. - Enable the Boolean feature flag using the switch in theEnabled column.
Note: Expect the variation to be
true.
- Open the demo application as describedhere.
- Enter the Boolean feature flag name.
- ChooseEvaluate.
- The result should state that the feature flag is of type
BOOLEANand its variation istrue.
The next procedures (14 - 19) are only applicable for productive accounts, which means plan
standard.
- Open the
Feature Flags Dashboardas describedhere. - ChooseNew Flag.
- Fill in the required fields. For example:
- Name:
my-string-flag - Description:
Coolest of features - Type:
String - State:
OFF
- Name:
- Enter the following values as different variations of the flag:
- Var. 1:
variation-when-inactive - Var. 2:
variation-when-active - Var. 3 (choose theAdd button with the '+' sign to add a new field):
variation-for-friends-and-family
- Var. 1:
- From theDefault Variation tab in theEnvironment Details section,Strategy subsection, open theDeliver combo box and select
Var. 2. - ChooseSave.
Note: Expect the variation to be
variation-when-inactive.
- Open the demo application as describedhere.
- Enter the string feature flag name.
- ChooseEvaluate.
- The result should state that the feature flag is of type
STRINGand its variation isvariation-when-inactive.
- Open the
Feature Flags Dashboardas describedhere. - Enable the string feature flag using the switch in theEnabled column.
Note: Expect the variation to be
variation-when-active.
- Open the demo application as describedhere.
- Enter the string feature flag name.
- ChooseEvaluate.
- The result should state that the feature flag is of type
STRINGand its variation isvariation-when-active.
- Open the
Feature Flags Dashboardas describedhere. - Select the string feature flag.
- Choose theEdit Flag button.
- Go to theEnvironment Details section,Strategy subsection,Direct Delivery tab, and choose the '+' button.
- SelectVar. 3 from the combobox and enter
friends-and-familyin the text input. - ChooseSave.
Note: Expect the variation to be
variation-for-friends-and-family.
- Open the demo application as describedhere.
- Enter the string feature flag name.
- For theIdentifier (optional) field, enter
friends-and-family. - ChooseEvaluate.
- The result should state that the feature flag is of type
STRINGand its variation isvariation-for-friends-and-family.
OnceDirect Delivery is configured, the Feature Flags service requires providing an identifier. If such is not present, an error is thrown.
💡NOTE:variation-when-active is returned for all identifiers - except for those explicitly configured in theFeature Flags Dashboard for which the provided rules apply (like thefriends-and-family identifier).
Refer to thecontrubuting guideline.
Refer to theSAP Open Source Code of Conduct.
SeeLICENSE file.
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
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors8
Uh oh!
There was an error while loading.Please reload this page.