Skip to content

Commit

Permalink
Alerting: Use hash of opts in singleflight (grafana#58474)
Browse files Browse the repository at this point in the history
  • Loading branch information
grobinson-grafana authored Nov 8, 2022
1 parent 72275e9 commit ad9ac85
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/services/ngalert/image/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package image

import (
"context"
"encoding/base64"
"errors"
"fmt"
"time"
Expand Down Expand Up @@ -135,8 +136,8 @@ func (s *ScreenshotImageService) NewImage(ctx context.Context, r *models.AlertRu
Timeout: screenshotTimeout,
}

k := fmt.Sprintf("%s-%d-%s", opts.DashboardUID, opts.PanelID, opts.Theme)
result, err, _ := s.singleflight.Do(k, func() (interface{}, error) {
optsHash := base64.StdEncoding.EncodeToString(opts.Hash())
result, err, _ := s.singleflight.Do(optsHash, func() (interface{}, error) {
screenshot, err := s.limiter.Do(ctx, opts, s.screenshots.Take)
if err != nil {
if errors.Is(err, dashboards.ErrDashboardNotFound) {
Expand Down

0 comments on commit ad9ac85

Please sign in to comment.