Skip to content

Fix inconsistent Id returned for silences.Set#3868

Closed
grobinson-grafana wants to merge 1 commit intoprometheus:mainfrom
grobinson-grafana:grobinson/fix-inconsistent-id
Closed

Fix inconsistent Id returned for silences.Set#3868
grobinson-grafana wants to merge 1 commit intoprometheus:mainfrom
grobinson-grafana:grobinson/fix-inconsistent-id

Conversation

@grobinson-grafana
Copy link
Collaborator

@grobinson-grafana grobinson-grafana commented Jun 6, 2024

This pull request fixes inconsistent behavior of silences.Set() where it can return an empty string and an error but also set sil.Id to a UUID. This can happen when creating a silence that is invalid or exceeds limits. This bug was introduced in #3852.

This commit fixes inconsistent behavior of silences.Set where if
a silence was invalid or exceeds limits, sil.Id would contain the
silence UUID but the Id returned would be the empty string.
This bug was introduced in prometheus#3866.

Signed-off-by: George Robinson <george.robinson@grafana.com>
@grobinson-grafana grobinson-grafana force-pushed the grobinson/fix-inconsistent-id branch from a97f41d to 8da10ba Compare June 6, 2024 15:59
// If we got here it's either a new silence or a replacing one.
if s.limits.MaxSilences > 0 {
if len(s.st)+1 > s.limits.MaxSilences {
return sil.Id, fmt.Errorf("exceeded maximum number of silences: %d (limit: %d)", len(s.st), s.limits.MaxSilences)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I return sil.Id here as that's what happens if s.setSilence returns an error too. s.setSilence can return an error if the silence is invalid or maximum size has been exceeded.

@grobinson-grafana
Copy link
Collaborator Author

I closed and then re-opened this PR as what I want to do is make sure sil.Id is "" when creating a silence fails, but making this consistent is much more complicated than I first thought because of how updates (expire then re-create) works.

}

return sil.Id, nil
return sil.Id, s.setSilence(sil, now, false)
Copy link
Collaborator Author

@grobinson-grafana grobinson-grafana Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how it was before #3852.

@grobinson-grafana
Copy link
Collaborator Author

I'm going to close this in favor of doing the bigger changes, as mentioned here.

@grobinson-grafana grobinson-grafana deleted the grobinson/fix-inconsistent-id branch June 25, 2024 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant