Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PATCH method required for /api/admin/context/{contextField} #8934

Open
preetiakrohilla opened this issue Dec 9, 2024 · 5 comments
Open

PATCH method required for /api/admin/context/{contextField} #8934

preetiakrohilla opened this issue Dec 9, 2024 · 5 comments

Comments

@preetiakrohilla
Copy link

Describe the feature request

Hi Team,

We have a use case where we are trying to update the Unleash UserId context field in parallel. Here are the steps we follow:

We are using REST APIs to update the context field.

  1. To get the current list of legal values for a given userId context field, use the following GET request:

curl --header "Authorization: xxxxxxxxxxxxxxxxxx" --header "Content-Type: application/json" http://localhost:4242/api/admin/context/userId
Sample response:
{
"name": "userId",
"description": "Allows you to constrain on userId",
"stickiness": false,
"sortOrder": 1,
"legalValues": [
{
"value": "aeb27c26-8952-434c-a724-e86fbd124e15",
"description": "test1"
}
],
"createdAt": "2023-10-29T13:25:26.078Z"
}

  1. Add the new userId value to the list of legalValues received in the response from step Agree on a license #1

For example, you may want to add a new user ID like this:
{
"value": "6880e05c-df57-4a06-af65-418e57754d19",
"description": "test2"
}

  1. Use a PUT request to update the userId context field with the modified legalValues list:

curl --request PUT 'http://localhost:4242/api/admin/context/userId'
--header 'Authorization: xxxxxxxxxxxxxx'
--header 'Content-Type: application/json'
--data-raw '{
"name": "userId",
"description": "Allows you to constrain on userId",
"legalValues": [
{
"value": "aeb27c26-8952-434c-a724-e86fbd124e15",
"description": "test1"
},
{
"value": "6880e05c-df57-4a06-af65-418e57754d19",
"description": "test2"
}
],
"stickiness": false
}'

Potential Issue:
Two concurrent requests might lead to data overwriting on the server, as both requests may fetch the same state in step #1 and update the context field simultaneously. This can result in the loss of changes made by one request when the other request is processed later.

Background

No response

Solution suggestions

Introduce Patch Method for Unleash Rest API /api/admin/context/{contextField}

@FredrikOseberg
Copy link
Contributor

@preetiakrohilla

Hi.

I can see the use-case for this functionality, however we have other priorities that are more pressing right now. If you would like to contribute this functionality we'd be happy to take a look at it, otherwise we'll have to revisit this in the future.

@FredrikOseberg FredrikOseberg moved this from New to Investigating in Issues and PRs Dec 10, 2024
@FredrikOseberg FredrikOseberg moved this from Investigating to For later in Issues and PRs Dec 10, 2024
@kwasniew
Copy link
Contributor

kwasniew commented Jan 3, 2025

You can add/update and delete single legal values now: #9056 and #9058

@preetiakrohilla
Copy link
Author

Hello @kwasniew

Thanks for your support!

Could you please confirm when this change is planned for release?

Additionally, we are facing a similar issue when adding whitelisted values for constraints under feature flag strategy.
This operation also requires the complete set of whitelisted values in the PUT request. Two parallel threads are overwriting our values.

Is it possible to support single-value updates and deletions in this case, or is there another workaround available?

@kwasniew
Copy link
Contributor

kwasniew commented Jan 6, 2025

Hi @preetiakrohilla
If you're Unleash hosted client then you should already have it available. If you're self-hosted Enterprise or using OSS version then you'll get it in the next minor release at the end of this month.

For the strategy updates are you using UI or API? In the UI code there's a staleness check that verifies if you're looking at the most recent version. But since you mentioned threads I'm assuming you're updating them with our API.

@preetiakrohilla
Copy link
Author

We are using API to update the strategy.
Initially, we considered using the ETag header, but later we realized that Unleash uses a weak ETag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: For later
Development

No branches or pull requests

3 participants