Alerting: Add a general screenshot service and alerting-specific image service. (#49293)
This commit adds a pkg/services/screenshot package for taking and uploading screenshots of Grafana dashboards. It supports taking screenshots of both dashboards and individual panels within a dashboard, using the rendering service. The screenshot package has the following services, most of which can be composed: BrowserScreenshotService (Takes screenshots with headless Chrome) CachableScreenshotService (Caches screenshots taken with another service such as BrowserScreenshotService) NoopScreenshotService (A no-op screenshot service for tests) SingleFlightScreenshotService (Prevents duplicate screenshots when taking screenshots of the same dashboard or panel in parallel) ScreenshotUnavailableService (A screenshot service that returns ErrScreenshotsUnavailable) UploadingScreenshotService (A screenshot service that uploads taken screenshots) The screenshot package does not support wire dependency injection yet. ngalert constructs its own version of the service. See https://github.com/grafana/grafana/issues/49296 This PR also adds an ImageScreenshotService to ngAlert. This is used to take screenshots with a screenshotservice and then store their location reference for use by alert instances and notifiers.
This commit is contained in:
@@ -48,6 +48,9 @@ const (
|
||||
schedulereDefaultExecuteAlerts = true
|
||||
schedulerDefaultMaxAttempts = 3
|
||||
schedulerDefaultLegacyMinInterval = 1
|
||||
screenshotsDefaultEnabled = false
|
||||
screenshotsDefaultMaxConcurrent = 5
|
||||
screenshotsDefaultUploadImageStorage = false
|
||||
// SchedulerBaseInterval base interval of the scheduler. Controls how often the scheduler fetches database for new changes as well as schedules evaluation of a rule
|
||||
// changing this value is discouraged because this could cause existing alert definition
|
||||
// with intervals that are not exactly divided by this number not to be evaluated
|
||||
@@ -77,6 +80,13 @@ type UnifiedAlertingSettings struct {
|
||||
BaseInterval time.Duration
|
||||
// DefaultRuleEvaluationInterval default interval between evaluations of a rule.
|
||||
DefaultRuleEvaluationInterval time.Duration
|
||||
Screenshots UnifiedAlertingScreenshotSettings
|
||||
}
|
||||
|
||||
type UnifiedAlertingScreenshotSettings struct {
|
||||
Enabled bool
|
||||
MaxConcurrentScreenshots int64
|
||||
UploadExternalImageStorage bool
|
||||
}
|
||||
|
||||
// IsEnabled returns true if UnifiedAlertingSettings.Enabled is either nil or true.
|
||||
@@ -244,6 +254,14 @@ func (cfg *Cfg) ReadUnifiedAlertingSettings(iniFile *ini.File) error {
|
||||
uaCfg.DefaultRuleEvaluationInterval = uaMinInterval
|
||||
}
|
||||
|
||||
screenshots := iniFile.Section("unified_alerting.screenshots")
|
||||
uaCfgScreenshots := uaCfg.Screenshots
|
||||
|
||||
uaCfgScreenshots.Enabled = screenshots.Key("enabled").MustBool(screenshotsDefaultEnabled)
|
||||
uaCfgScreenshots.MaxConcurrentScreenshots = screenshots.Key("max_concurrent_screenshots").MustInt64(screenshotsDefaultMaxConcurrent)
|
||||
uaCfgScreenshots.UploadExternalImageStorage = screenshots.Key("upload_external_image_storage").MustBool(screenshotsDefaultUploadImageStorage)
|
||||
uaCfg.Screenshots = uaCfgScreenshots
|
||||
|
||||
cfg.UnifiedAlerting = uaCfg
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user