0

I'm working with Gitlab Feature Flags and to use them in my Java project I'm using unleash-java. The problem is that in this library it seems that I can't change from my code the values of the feature flags, but just from Gitlab. Is there a way to do it? Maybe using another library?

2
  • Did you already check the GitLab help Unleash Proxy Example? Commented Dec 6, 2023 at 12:39
  • It seems that there are no proxy classes in unleash-java, so I don't know how to use it in the code Commented Dec 6, 2023 at 13:36

1 Answer 1

0

As per GitLab's documentation, answer to your question is Yes. It is possible to update the GitLab feature flag https://docs.gitlab.com/ee/api/feature_flags.html#update-a-feature-flag

To get a feature flag use

GET https://gitlab.example.com/api/v4/projects/<projectId>/feature_flags/test-feature-flag

You have to pass your Git Access token in the header named PRIVATE-TOKEN

and response will be like below

{
    "name": "test-feature-flag",
    "description": "This is a test feature flag to check the API",
    "active": true,
    "version": "new_version_flag",
    "created_at": "2023-12-14T16:52:34.191Z",
    "updated_at": "2023-12-14T16:52:34.191Z",
    "scopes": [],
    "strategies": [
        {
            "id": 6825,
            "name": "default",
            "parameters": {},
            "scopes": [
                {
                    "id": 7572,
                    "environment_scope": "*"
                }
            ]
        }
    ]
}

Now as you can see this feature flag is active now. You can disable it using below end point

PUT https://gitlab.example.com/api/v4/projects/<projectId>/feature_flags/test-feature-flag

and the json body to update required field. For e.g. I passed below to toggle the state.

{
"active": false
}

And it worked perfectly.

Note: If you are using unleash in your application to read the feature flag, then keep in mind that the feature flag's updates will be reflected only after the cache is expired.

Cache can be configured by setting fetchTogglesInterval Below is a Java UnleashConfig bean

@Bean
  public UnleashConfig unleashConfig() {
    return UnleashConfig.builder().appName(unleashConfig.getAppName())
        .instanceId(unleashConfig.getInstanceId()).unleashAPI(unleashConfig.getApiUrl())
        .fetchTogglesInterval(unleashConfig.getCacheInterval()).disableMetrics().build();
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.