Alerting: Use hash of opts in singleflight (#58474)

This commit is contained in:
George Robinson 2022-11-08 22:37:49 +00:00 committed by GitHub
parent 72275e97d2
commit ad9ac85ee0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ package image
import (
"context"
"encoding/base64"
"errors"
"fmt"
"time"
@ -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) {