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

Annotations: Ignore unique constraint violations for tags #65935

Merged
merged 3 commits into from Apr 18, 2023

Conversation

sakjur
Copy link
Contributor

@sakjur sakjur commented Apr 4, 2023

What is this feature?

When creating annotations with tags very fast, there's a race condition where the tag table might have tags added simultaneously triggering a unique constraint violation.

Considerations:

  • Explicit database locks increased complexity quite a bit for relatively little gain.
  • A regular mutex would probably work really well in practice, but HA instances could irregularly still experience the problem.

Instead, I opted for a single retry which seems to work well according to my testing using k6 (I'm not able to write a reliable reproduction test in Go, since this depends on a race condition).

Who is this feature for?

Annotations API users.

Which issue(s) does this PR fix?:

Fixes #61203

Special notes for your reviewer:

excerpt from k6 script for duplication and validation
export default function (data) {
    login("admin", "admin");

    const ts = Math.floor(Date.now() / 100)
    const res = http.post(http.url`${url}/api/annotations`,
        JSON.stringify({
            dashboardUID: data.dashboards[0],
            time: Date.now(),
            timeEnd: Date.now()+30000,
            tags: ['project=foo', `identifier=${ts}`],
            text: 'Wrote an annotation',
        }),
        {
            tags: { type: "annotations", op: "create" },
            headers: { "Content-Type": "application/json" },
        }
    );

    check(res, {
        "annotation successfully created": (r) => r.status === 200,
        "creating annotation takes less than 150ms": (r) => r.timings.duration < 150,
    });

    if (res.status >= 500) {
        console.log(res)
    }
}

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@sakjur sakjur added this to the 9.5.x milestone Apr 11, 2023
@sakjur sakjur marked this pull request as ready for review April 11, 2023 16:14
@sakjur sakjur requested a review from a team as a code owner April 11, 2023 16:14
@sakjur sakjur requested review from papagian, zserge and mildwonkey and removed request for a team April 11, 2023 16:14
@sakjur sakjur added the backport v9.5.x Bot will automatically open backport PR label Apr 11, 2023
@sakjur sakjur merged commit 948131a into main Apr 18, 2023
10 checks passed
@sakjur sakjur deleted the emil/202304/annotations-ignore-unique-constraint branch April 18, 2023 12:21
grafanabot pushed a commit that referenced this pull request Apr 18, 2023
@guicaulada guicaulada modified the milestones: 9.5.x, 9.5.0 Apr 24, 2023
@zerok zerok modified the milestones: 9.5.0, 10.0.0 May 4, 2023
@zerok zerok modified the milestones: 10.0.0, 10.0.0-preview May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Concurrent tagged annotation creations can fail due to duplicate entry errors in mysql
6 participants