mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 01:23:32 -06:00
Rendering: periodically refresh remote plugin version (#45505)
* #44449: refresh image renderer version on a schedule * #44449: simplify
This commit is contained in:
parent
78c35e6000
commit
7643ae6c5e
@ -29,8 +29,9 @@ var netClient = &http.Client{
|
||||
}
|
||||
|
||||
var (
|
||||
remoteVersionFetchInterval time.Duration = time.Second * 15
|
||||
remoteVersionFetchRetries uint = 4
|
||||
remoteVersionFetchInterval time.Duration = time.Second * 15
|
||||
remoteVersionFetchRetries uint = 4
|
||||
remoteVersionRefreshInterval = time.Minute * 15
|
||||
)
|
||||
|
||||
func (rs *RenderingService) renderViaHTTP(ctx context.Context, renderKey string, opts Opts) (*RenderResult, error) {
|
||||
@ -251,3 +252,26 @@ func (rs *RenderingService) getRemotePluginVersion() (string, error) {
|
||||
}
|
||||
return info.Version, nil
|
||||
}
|
||||
|
||||
func (rs *RenderingService) refreshRemotePluginVersion() {
|
||||
newVersion, err := rs.getRemotePluginVersion()
|
||||
if err != nil {
|
||||
rs.log.Info("Failed to refresh remote plugin version", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
if newVersion == "" {
|
||||
// the image-renderer could have been temporary unavailable - skip updating the version
|
||||
rs.log.Debug("Received empty version when trying to refresh remote plugin version")
|
||||
return
|
||||
}
|
||||
|
||||
currentVersion := rs.Version()
|
||||
if currentVersion != newVersion {
|
||||
rs.versionMutex.Lock()
|
||||
defer rs.versionMutex.Unlock()
|
||||
|
||||
rs.log.Info("Updating remote plugin version", "currentVersion", currentVersion, "newVersion", newVersion)
|
||||
rs.version = newVersion
|
||||
}
|
||||
}
|
||||
|
@ -120,8 +120,19 @@ func (rs *RenderingService) Run(ctx context.Context) error {
|
||||
})
|
||||
rs.renderAction = rs.renderViaHTTP
|
||||
rs.renderCSVAction = rs.renderCSVViaHTTP
|
||||
<-ctx.Done()
|
||||
return nil
|
||||
|
||||
refreshTicker := time.NewTicker(remoteVersionRefreshInterval)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-refreshTicker.C:
|
||||
go rs.refreshRemotePluginVersion()
|
||||
case <-ctx.Done():
|
||||
rs.log.Debug("Grafana is shutting down - stopping image-renderer version refresh")
|
||||
refreshTicker.Stop()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if rs.pluginAvailable() {
|
||||
|
Loading…
Reference in New Issue
Block a user