Skip to content

πŸš€ A POC for using Unleash feature flag service with express

License

Notifications You must be signed in to change notification settings

murshidazher/poc-express-unleash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Codacy grade

πŸš€ A proof of concept for using Unleash feature flag service with express

  • Unleash an open-source software for managing feature flags for trunk-based development.
  • Documentation for Getting started with Unleash could be found here
  • Docker compose file and setup can be found here

Table of Contents

Getting Started

Docker-compose

🐳 Make sure that the docker service is up and running.

  1. Clone the unleash-docker repository. git clone git@github.com:murshidazher/poc-express-unleash.git
  2. Run docker-compose build in repository root folder.
  3. Run docker-compose up in repository root folder.

Setting up Unleash Proxy

Documentation could be found here.

An unleash proxy is need as a way for client-sdks to consume feature flags in the application.

  • Open the browser and go to localhost:4242

  • Add the default admin credentials and login

  • Go to Configure -> API access -> Configure the proxy

  • Create a token for the unleash-proxy and add it to the docker-compose.

    Example screen shot for configured client key
  • docker-compose up proxy to restart the proxy.

  • Verify that the proxy is running

    curl -H "Content-Type: application/json" \
       -H "Authorization: proxy-client-key" \
       -X GET \
       http://localhost:3000/proxy
    Example curl request for fetching flags using proxy key

User accounts

  • Once started up, you'll have a user with
    • username: admin
    • password: unleash4all

Snake Service

An example small api to fetch snake names

  • By default, the service only returns a single snake name.

  • A new product outline has come in to add a new modification to send multiple snake names instead of one.

  • Since you're doing a truck-based development you need to wrap the changes inside a feature flag.

  • We will be using the node.js SDK, but you can use whatever the SDK you prefer. The list of available SDK are here.

    Default response of snake-name api

Adding a Project

πŸ’‘ Open-source version only get the default project, we cant create more projects. 😞

  • Select the default project.

Adding a feature flag

🎏 Check out the feature flags documentation for the types of feature flag that could be created.

  • You can also use the unleash-client-proxy with node-fetch module to connect to the proxy instead of connecting to the server directly using API key.
  • But this example uses the unleash-client SDK to directly connect since the communication would be amount services.

For this example, lets create a flag called fflag-get-three-snake-names

using the shell ```sh curl --location --request POST 'http://localhost:3000/api/admin/projects/default/features' \ --header 'Authorization: proxy-client-key' \ --header 'Content-Type: application/json' \ --data-raw '{ "type": "operational", "name": "fflag-get-three-snake-names", "description": "PO - Return three random snake names instead of a single snake name in response", "impressionData": true }' ```
using the UI
  • Enable the flag in development environment and gradual rollout to 50%

    Enable the flag
    Requesting fflag with 50% gradual rollout
  • After feature flag response

Getting the new feature

Rebuild the image

You need to rebuild the docker-image after any changes,

docker-compose build snake-service
docker-compose up snake-service

Common issues

Work locally with this repo

🌟 This section is adapted from unleash-docker docs.

Start by cloning this repository.

The unleash community has set up docker-compose to start postgres and the unleash server together. This makes it really fast to start up unleash locally without setting up a database or node.

docker-compose build
docker-compose up

On some computers, the database won't start in time for Unleash the first time you run this. If Unleash fails to reach the database, docker-compose restart web usually resolves the issue.

Additional Links

  • To give context to unleash, refer to this section of the documentation.
  • For custom auth strategy, example if you need to enable a feature for QA users with some email address. Refer to this section of the documentation
  • For custom redis storage, refer to this section fo the documentation and client-proxy-sdk.

Thoughts

My thoughts on Unleash,

  • 🟒 Great interface and easy setup
  • 🟑 Would've been great if there was an extendible db setup other than PostgreSQL (ex. MongoDB)
  • πŸ”΄ Pegging the number of project to 1 which is only the default project. (Open-source)
  • πŸ”΄ The user access control feature for individual projects is only available for paid versions. (Open-source)

LICENSE

2023 Β© Unleash & Murshid Azher.

About

πŸš€ A POC for using Unleash feature flag service with express

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published