prometheus / prometheus/alertmanager
Proposal: support idempotency token for create silence api
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 8.6k
- Forks
- 2.5k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 61
Description
Problem
We can not retry on Post silence api from client side because every put silence will generate an UUID. Ideally we should allow an idempotency token in create silence api so that an retry with the same idempotency token can be ignored“
An example of how cortex calling alert manager POST silence API:
If the POST silence call to the first alert manager that is responsible for tenant A, cortex won’t retry to next instance that responsible for tenant A as the lack of idempotency token support discussed here : https://github.com/cortexproject/cortex/pull/4422

Proposed solution
API
Introduce an idempotency token
We will accept an optional parameter for idempotency token, the behavior will remain unchanged if no idempotency token is provided
Pros:
Broadly adopted solution
Cons:
Require more complicated implementation as discussed in the Supporting of idempotency token section below
Allow client to input an UUID for the silence to be created
We will accept an optional parameter for UUID, if the UUID doesn’t exist before, the silence will be created, otherwise will be an update operation
Pros:
Easier to implement
Cons:
This is make create to become current update silence implementation, kind of confuse to the client
Supporting of idempotency token
Support without storing the idempotency token
Instead generating a unique uuid for every new request with a idempotency token here: https://github.com/prometheus/alertmanager/blob/f59460bfd4bf883ca66f4391e7094c0c1794d158/silence/silence.go#L579
We could generate an UUID based on the silence payload+idempotency token so that we make sure that same silence ID will be generated for the same idempotency+payload request.

With idempotency token in the request
- Client request to create a silence with an idempotency token
- A uuid(payload+idempotency) is returned => assume the uuid = 1ab
- Another request comes in
- Create a silence with the same idempotency token and payload, the same UUID will be returned as 1ab
- Create a silence with the same idempotency token but different payload, different UUID will be returned as 1bc
- Create a silence with the different idempotency token but same payload, different UUID will be returned as 1cd
Without idempotency token in the request(remain unchanged behavior as it is right now)
- Client request to create a silence without an idempotency token
- A uuid is returned => assume the uuid = 2ab
- Another request comes in
- Create a silence with the same payload, the UUID will be returned as 2bc
- Create a silence with the different payload, the UUID will be returned as 2de
Pros
- No extra dependency is needed
- Easier implementation
Cons
- In the case of idempotency token was send in before with different payload, we will return a different UUID and let the create go through instead of conflict exception
Support with storing the idempotency token

We will store the request payload and idempotency token to an external key value storage such as dynamodb , more storage option can be added

With idempotency token in the request
- Client request to create a silence with an idempotency token
- A query to the external storage to see if the idempotency token record exist
- If exist and payload match, An uuid(payload+idempotency) will be returned and silence will be create => assume the uuid = 3ab
- If exist and payload doesn’t match, a conflict exception will be returned
- If not exist, an record with the idempotency token will be created and uuid(payload+idempotency) will be returned => assume the uuid = 3ab
- Another request comes in
- Create a silence with the same idempotency token and payload, the same UUID will be returned as 3ab
- Create a silence with the same idempotency token but different payload, a conflict exception will be returned
- Create a silence with the different idempotency token but same payload, different UUID will be returned as 3cd
Pros
- We will do proper validation regarding to existing idempotency token but with different payload
Cons
- Need extra dependency
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the create-silence API and the UUID-generation logic in silence/silence.go referenced by the issue. Review the proposed token-generation and external-storage alternatives, including behavior for repeated tokens and changed payloads. Done requires an agreed API and implementation approach, with validation of the selected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100