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

Alerting: Elide requests to Loki if nothing should be recorded #65011

Merged
merged 1 commit into from Mar 21, 2023

Conversation

alexweav
Copy link
Contributor

What is this feature?

State history does filtering on state transitions and chooses not to write when nothing has changed.

When this happens, we'd have an empty slice of streams - we'd still attempt to write to Loki in this case, resulting in a pointless empty push request.

Now we exit early when this happens. This PR cuts down on a lot of outgoing loki traffic.

There was a similar change in Annotations to do this same thing, but for the database. Refactored this to exit even earlier. Now we don't even start any goroutines if there's nothing to write.

Which issue(s) does this PR fix?:

n/a

Special notes for your reviewer:

@alexweav alexweav added this to the 9.4.8 milestone Mar 19, 2023
@alexweav alexweav requested a review from a team as a code owner March 19, 2023 21:17
@alexweav alexweav added the backport v9.4.x Mark PR for automatic backport to v9.4.x label Mar 19, 2023
Copy link
Member

@JohnnyQQQQ JohnnyQQQQ left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@gotjosh gotjosh left a comment

Choose a reason for hiding this comment

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

LGTM, but please see my comment.

@@ -62,6 +62,11 @@ func (h *AnnotationBackend) Record(ctx context.Context, rule history_model.RuleM
panel := parsePanelKey(rule, logger)

errCh := make(chan error, 1)
if len(annotations) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

My only concern is that there's no distinction between recording and not recording to the caller of this function - but maybe this is captures by metrics and therefore is fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's how it already works to begin with. Right now the scheduler and state packages call Record on every evaluation, and they pass in in tons of states that we don't actually care about or actually want to record, like Alerting->Alerting. Regardless of this change, it relies on getting called a ton and nothing in the caller cares if it recorded or didn't.

@alexweav alexweav merged commit e39d7f4 into main Mar 21, 2023
15 checks passed
@alexweav alexweav deleted the alexweav/avoid-send-empty branch March 21, 2023 14:31
grafanabot pushed a commit that referenced this pull request Mar 21, 2023
Exit early if no log streams or annotations

(cherry picked from commit e39d7f4)
alexweav added a commit that referenced this pull request Mar 21, 2023
…ed (#65118)

Alerting: Elide requests to Loki if nothing should be recorded (#65011)

Exit early if no log streams or annotations

(cherry picked from commit e39d7f4)

Co-authored-by: Alexander Weaver <weaver.alex.d@gmail.com>
gotjosh pushed a commit that referenced this pull request Mar 27, 2023
@zerok zerok modified the milestones: 9.4.x, 9.4.8, 9.5.0 Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants