Renderer: add version information (#34964)

* Renderer: add version information

* fix alerting test
This commit is contained in:
Agnès Toulet
2021-06-04 14:33:49 +03:00
committed by GitHub
parent b46715ee4a
commit 5f6c172b5a
6 changed files with 54 additions and 1 deletions
+33
View File
@@ -2,6 +2,7 @@ package rendering
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
@@ -192,3 +193,35 @@ func (rs *RenderingService) readFileResponse(ctx context.Context, resp *http.Res
return nil
}
func (rs *RenderingService) getRemotePluginVersion() (string, error) {
rendererURL, err := url.Parse(rs.Cfg.RendererUrl + "/version")
if err != nil {
return "", err
}
headers := make(map[string][]string)
resp, err := rs.doRequest(context.Background(), rendererURL, headers)
if err != nil {
return "", err
}
defer func() {
if err := resp.Body.Close(); err != nil {
rs.log.Warn("Failed to close response body", "err", err)
}
}()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("remote rendering request to get version failed, status code: %d, status: %s", resp.StatusCode,
resp.Status)
}
var info struct {
Version string
}
if err := json.NewDecoder(resp.Body).Decode(&info); err != nil {
return "", err
}
return info.Version, nil
}