Unleash Proxy app_name should not be environment

Description

Following the GitLab docs about the Unleash Proxy, it is required to set the UNLEASH_APP_NAME to the project environment:

docker run \
  -e UNLEASH_PROXY_SECRETS=<secret> \
  -e UNLEASH_URL=<project feature flags URL> \
  -e UNLEASH_INSTANCE_ID=<project feature flags instance ID> \
  -e UNLEASH_APP_NAME=<project environment> \
  -e UNLEASH_API_TOKEN=<tokenNotUsed> \
  -p 3000:3000 \
  unleashorg/unleash-proxy

That means that a different proxy instance has to run for each environment. We're using review environments like dev/123 (where 123 would be the MR number) and it's not feasible to spin up a new proxy instance for each of those.

Looking at the upstream Unleash Proxy docs, the Proxy API actually supports passing the environment as part of the context among other properties:

field name type lifetime description
appName string static the name of the application
environment string static the environment the app is running in
userId string dynamic an identifier for the current user
sessionId string dynamic an identifier for the current session
remoteAddress string dynamic an identifier for the current session
properties Map<string, string> dynamic a key-value store of any data you want

However, the environment parameter is completely ignored in the request. Is there a reason that the proxy works differently when connected to GitLab? Am I missing something?

Sadly it looks like due to this limitation the proxy and therefore the entire FF feature isn't usable for us 😞

Proposal

We introduce a new toggle in the Unleash Client Configuration modal. This b switches the behavior to use environment parameter for selecting feature flags instead of appName parameter.

2023-02-08_15-43

(Note: It's Toggle, not Checkbox. Please see #354087 (comment 1271295831))

Users who expect the environment param to be respected in GitLab Unleash API can enable the toggle. This toggle is enabled by default in all newly created projects. Existing projects have it disabled, but can enable it manually. In this case, we should show a caution that users should make sure the environment parameter is correctly set in the unleash client or proxy beforehand.

Technical details

  • We add use_unleash_environment column (boolean DEFAULT true NOT NULL) to operations_feature_flags_clients table.
  • Switch the flag filtering mechanism between toggle ON/OFF.
  • Update documentation.
  • See PoC !111402 (closed) for more information.
Edited by Shinya Maeda