Git Product home page Git Product logo

cloud-cf-feature-flags-sample's Introduction

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 Cloud Platform, 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 Cloud Platform

Follow these steps to run the Feature Flags Service Demo application on SAP Cloud Platform, 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 Cloud Platform, Cloud Foundry environment, see Regions and Hosts.

  1. Build the application.
  2. Edit the manifest.yml.
  3. Deploy the application.
  4. Create a service instance of the Feature Flag service.
  5. Call feature-flags-demo application /vcap_services end-point.
  6. Bind feature-flags-demo to feature-flags-instance.
  7. Restage feature-flags-demo application.
  8. Ensure that feature-flags-instance is properly bound to feature-flags-demo.
  9. Perform an evaluation of missing feature flag.
  10. Create a new feature flag.
  11. Perform an evaluation of the newly created feature flag.
  12. Enable the feature flag.
  13. Verify that the feature flag was properly enabled.

1. Build the feature-flags-demo Application

$ git clone [email protected]: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

3. Deploy feature-flags-demo on SAP Cloud Platform

$ 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    	lite     	Feature Flags service for controlling feature rollout
...

4.2 Create a Service Instance of Feature Flags with Plan lite

$ cf create-service feature-flags lite 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 Cloud Platform Cockpit. See Create a Service Instance.

5. Call the feature-flags-demo Application /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 Cloud Platform 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 Cloud Platform 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": {
        "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": "lite",
      "name": "feature-flags-instance",
      "tags": [
        "feature-flags"
      ]
    }
  ]
}

9. Evaluate if the Feature Flag is Missing

Note: Expect the feature flag to be missing.

  1. Navigate to feature-flags-demo overview in the SAP Cloud Platform Cockpit (for example, https://feature-flags-demo.cfapps.eu10.hana.ondemand.com). An Evaluation Form opens.
  2. Evaluate a feature flag with random name (for example, type in 'my-flag'). The result should state that the feature flag with the given name is missing.

10. Create a New Feature Flag

  1. Navigate to Feature Flags service instance dashboard in the SAP Cloud Platform Cockpit (for example, https://feature-flags-dashboard.cfapps.eu10.hana.ondemand.com/manageinstances/<instance-id>). The instance ID is a unique ID of the service instance.

Note: The easiest way to access the Feature Flags dashboard is through the cockpit. Go to <your_subaccount> > <your_space> > Service Instances > Actions (from your service instance line) > Open Dashboard icon.

  1. Choose New Flag.
  2. Fill in the required fields (for example, 'my-flag' for Name, 'Super cool feature' for Description and 'OFF' for State).
  3. Choose Add.

11. Evaluate the Newly Created Feature Flag

Note: Expect the feature flag to be disabled.

  1. Navigate to feature-flags-demo application overview in the SAP Cloud Platform Cockpit. Open the link from the Application Routes section (for example, https://feature-flags-demo.cfapps.eu10.hana.ondemand.com). An Evaluation Form opens.
  2. Enter the 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 with the given name is disabled.

12. Enable the Feature Flag

  1. Navigate to Feature Flags service instance dashboard in the SAP Cloud Platform Cockpit (for example, https://feature-flags-dashboard.cfapps.eu10.hana.ondemand.com/manageinstances/<instance-id>). The instance ID is a unique ID of the service instance.

Note: The easiest way to access the Feature Flags dashboard is through the cockpit. Go to <your_subaccount> > <your_space> > Service Instances > Actions (from your service instance line) > Open Dashboard icon.

  1. Enable the feature flag using the switch in the State column.

13. Verify that the Feature Flag is Enabled

Note: Expect the feature flag to be enabled.

  1. Navigate to feature-flags-demo application overview in the SAP Cloud Platform Cockpit. Open the link from the Application Routes section (for example, https://feature-flags-demo.cfapps.eu10.hana.ondemand.com). An Evaluation Form opens.
  2. Enter the 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 with the given name is enabled.

cloud-cf-feature-flags-sample's People

Contributors

dzahariev avatar nickymateev avatar ialidzhikov avatar steinermatt avatar petar-iv avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.