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: State Manager takes screenshots. #49338

Merged
merged 4 commits into from
May 23, 2022

Conversation

joeblubaugh
Copy link
Contributor

The State Manager will now take screenshots when an alert instance
switches to an Alerting or Resolved state.

Signed-off-by: Joe Blubaugh joe.blubaugh@grafana.com

Special notes for your reviewer:

This PR is based on joe/add-screenshots-to-ngalert, #49293 . Once that PR merges, I'll change the base to main

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.

First pass looking good, some nits and comments.

pkg/services/ngalert/models/alert_rule.go Outdated Show resolved Hide resolved
pkg/services/ngalert/state/manager.go Show resolved Hide resolved
@joeblubaugh joeblubaugh marked this pull request as ready for review May 22, 2022 11:54
@joeblubaugh joeblubaugh requested a review from a team May 22, 2022 11:54
// It's not an error if screenshots are disabled, or our rule isn't allowed to generate screenshots.
return nil
} else if err != nil {
st.log.Error("failed to create image", "error", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

But there is double logging here, which we don't need. I'm going to remove this one and keep the more detailed one in the outer function.

@@ -1770,7 +1770,7 @@ func TestProcessEvalResults(t *testing.T) {

for _, tc := range testCases {
ss := mockstore.NewSQLStoreMock()
st := state.NewManager(log.New("test_state_manager"), testMetrics.GetStateMetrics(), nil, nil, &store.FakeInstanceStore{}, ss, &dashboards.FakeDashboardService{}, &image.NoopImageService{})
st := state.NewManager(log.New("test_state_manager"), testMetrics.GetStateMetrics(), nil, nil, &store.FakeInstanceStore{}, ss, &dashboards.FakeDashboardService{}, &image.NotAvailableImageService{})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was so I didn't have to modify a bunch of tests with zero-value image structs.

Base automatically changed from joe/add-screenshots-to-ngalert to main May 22, 2022 14:33
@joeblubaugh joeblubaugh requested a review from a team as a code owner May 22, 2022 14:33
@joeblubaugh joeblubaugh requested review from zserge, idafurjes and ying-jeanne and removed request for a team May 22, 2022 14:33
The State Manager will now take screenshots when an alert instance
switches to an Alerting or Resolved state.

Signed-off-by: Joe Blubaugh <joe.blubaugh@grafana.com>
@joeblubaugh joeblubaugh force-pushed the joe/call-image-create-manager branch from 9fe09a0 to 223d4e8 Compare May 22, 2022 14:34
@grafanabot
Copy link
Contributor

@joeblubaugh joeblubaugh requested a review from JohnnyQQQQ May 22, 2022 15:44
@JohnnyQQQQ JohnnyQQQQ added this to the 9.0.0 milestone May 22, 2022
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

@alexweav alexweav left a comment

Choose a reason for hiding this comment

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

LGTM. Great structure and really readable PR - nice work. Had a single comment that was just a nitpick (and optional).

// 1. The alert state is transitioning into the "Alerting" state from something else.
// 2. The alert state has just transitioned to the resolved state.
// 3. The state is alerting and there is no screenshot annotation on the alert state.
func (st *Manager) maybeNewImage(ctx context.Context, alertRule *ngModels.AlertRule, state *State, oldState eval.State) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (st *Manager) maybeNewImage(ctx context.Context, alertRule *ngModels.AlertRule, state *State, oldState eval.State) error {
func (st *Manager) maybeTakeScreenshot(ctx context.Context, alertRule *ngModels.AlertRule, state *State, oldState eval.State) error {

Huge nit, ignore if you disagree. Just staying away from the new term since that usually implies a constructor in Go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is great, much better name.

PanelIDAnnotation = "__panelId__"
DashboardUIDAnnotation = "__dashboardUid__"
PanelIDAnnotation = "__panelId__"
ScreenshotTokenAnnotation = "__alertScreenshotToken__"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ScreenshotTokenAnnotation = "__alertScreenshotToken__"
ScreenshotTokenAnnotation = "__alertScreenshotToken__ //nolint:gosec"

To fix the linter

@grafanabot
Copy link
Contributor

@joeblubaugh joeblubaugh merged commit 1d72481 into main May 23, 2022
@joeblubaugh joeblubaugh deleted the joe/call-image-create-manager branch May 23, 2022 02:53
@joeblubaugh joeblubaugh added the area/alerting/screenshots Issues when seeing metrics when receiving alerts label May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/alerting/screenshots Issues when seeing metrics when receiving alerts area/backend enterprise-failed no-backport Skip backport of PR
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants