(cherry picked from commit 68600c224b)
This commit is contained in:
@@ -124,11 +124,15 @@ func NewScreenshotImageServiceFromCfg(cfg *setting.Cfg, db *store.DBstore, ds da
|
||||
// alert rule has a Dashboard UID and the dashboard exists, but does not have a
|
||||
// Panel ID in its annotations then an ErrNoPanel error is returned.
|
||||
func (s *ScreenshotImageService) NewImage(ctx context.Context, r *models.AlertRule) (*models.Image, error) {
|
||||
logger := s.logger.FromContext(ctx)
|
||||
|
||||
if r.DashboardUID == nil || *r.DashboardUID == "" {
|
||||
logger.Debug("Cannot take screenshot for alert rule as it is not associated with a dashboard")
|
||||
return nil, ErrNoDashboard
|
||||
}
|
||||
|
||||
if r.PanelID == nil || *r.PanelID == 0 {
|
||||
logger.Debug("Cannot take screenshot for alert rule as it is not associated with a panel")
|
||||
return nil, ErrNoPanel
|
||||
}
|
||||
|
||||
@@ -138,14 +142,12 @@ func (s *ScreenshotImageService) NewImage(ctx context.Context, r *models.AlertRu
|
||||
Timeout: screenshotTimeout,
|
||||
}
|
||||
|
||||
logger = logger.New("dashboard", opts.DashboardUID, "panel", opts.PanelID)
|
||||
|
||||
// To prevent concurrent screenshots of the same dashboard panel we use singleflight,
|
||||
// deduplicated on a base64 hash of the screenshot options.
|
||||
optsHash := base64.StdEncoding.EncodeToString(opts.Hash())
|
||||
|
||||
logger := s.logger.FromContext(ctx).New(
|
||||
"dashboard", opts.DashboardUID,
|
||||
"panel", opts.PanelID)
|
||||
|
||||
// If there is an image is in the cache return it instead of taking another screenshot
|
||||
if image, ok := s.cache.Get(ctx, optsHash); ok {
|
||||
logger.Debug("Found cached image", "token", image.Token)
|
||||
|
||||
Reference in New Issue
Block a user