Release: Deprecate latest.json and replace with api call to grafana.com (#80537)

* remove latest.json and replace with api call to grafana.com

* remove latest.json

* Revert "remove latest.json"

This reverts commit bcff43d898.

* Revert "remove latest.json and replace with api call to grafana.com"

This reverts commit 02b867d84e.

* add deprecation message to latest.json
pull/80608/head
Ashley Harrison 1 year ago committed by GitHub
parent 31256bcc85
commit 127decee1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      conf/defaults.ini
  2. 2
      conf/sample.ini
  3. 1
      latest.json
  4. 27
      pkg/services/updatechecker/grafana.go

@ -246,7 +246,7 @@ reporting_distributor = grafana-labs
# for new versions of grafana. The check is used # for new versions of grafana. The check is used
# in some UI views to notify that a grafana update exists. # in some UI views to notify that a grafana update exists.
# This option does not cause any auto updates, nor send any information # This option does not cause any auto updates, nor send any information
# only a GET request to https://raw.githubusercontent.com/grafana/grafana/main/latest.json to get the latest version. # only a GET request to https://grafana.com/api/grafana/versions/stable to get the latest version.
check_for_updates = true check_for_updates = true
# Set to false to disable all checks to https://grafana.com # Set to false to disable all checks to https://grafana.com

@ -253,7 +253,7 @@
# for new versions of grafana. The check is used # for new versions of grafana. The check is used
# in some UI views to notify that a grafana update exists. # in some UI views to notify that a grafana update exists.
# This option does not cause any auto updates, nor send any information # This option does not cause any auto updates, nor send any information
# only a GET request to https://raw.githubusercontent.com/grafana/grafana/main/latest.json to get the latest version. # only a GET request to https://grafana.com/api/grafana/versions/stable to get the latest version.
;check_for_updates = true ;check_for_updates = true
# Set to false to disable all checks to https://grafana.com # Set to false to disable all checks to https://grafana.com

@ -1,4 +1,5 @@
{ {
"__message": "This file is now deprecated, and will be removed in a future release. No further updates should be made to this file",
"stable": "10.2.3", "stable": "10.2.3",
"testing": "10.2.3" "testing": "10.2.3"
} }

@ -20,7 +20,7 @@ import (
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
) )
const grafanaLatestJSONURL = "https://raw.githubusercontent.com/grafana/grafana/main/latest.json" const grafanaStableVersionURL = "https://grafana.com/api/grafana/versions/stable"
type GrafanaService struct { type GrafanaService struct {
hasUpdate bool hasUpdate bool
@ -92,13 +92,13 @@ func (s *GrafanaService) instrumentedCheckForUpdates(ctx context.Context) {
func (s *GrafanaService) checkForUpdates(ctx context.Context) error { func (s *GrafanaService) checkForUpdates(ctx context.Context) error {
ctxLogger := s.log.FromContext(ctx) ctxLogger := s.log.FromContext(ctx)
ctxLogger.Debug("Checking for updates") ctxLogger.Debug("Checking for updates")
req, err := http.NewRequestWithContext(ctx, http.MethodGet, grafanaLatestJSONURL, nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, grafanaStableVersionURL, nil)
if err != nil { if err != nil {
return err return err
} }
resp, err := s.httpClient.Do(req) resp, err := s.httpClient.Do(req)
if err != nil { if err != nil {
return fmt.Errorf("failed to get latest.json repo from github.com: %w", err) return fmt.Errorf("failed to get stable version from grafana.com: %w", err)
} }
defer func() { defer func() {
if err := resp.Body.Close(); err != nil { if err := resp.Body.Close(); err != nil {
@ -107,27 +107,24 @@ func (s *GrafanaService) checkForUpdates(ctx context.Context) error {
}() }()
body, err := io.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return fmt.Errorf("update check failed, reading response from github.com: %w", err) return fmt.Errorf("update check failed, reading response from grafana.com: %w", err)
} }
type latestJSON struct { type grafanaVersionJSON struct {
Stable string `json:"stable"` Version string `json:"version"`
Testing string `json:"testing"`
} }
var latest latestJSON var latest grafanaVersionJSON
err = json.Unmarshal(body, &latest) err = json.Unmarshal(body, &latest)
if err != nil { if err != nil {
return fmt.Errorf("failed to unmarshal latest.json: %w", err) return fmt.Errorf("failed to unmarshal response from grafana.com: %w", err)
} }
s.mutex.Lock() s.mutex.Lock()
defer s.mutex.Unlock() defer s.mutex.Unlock()
if strings.Contains(s.grafanaVersion, "-") { // only check for updates in stable versions
s.latestVersion = latest.Testing if !strings.Contains(s.grafanaVersion, "-") {
s.hasUpdate = !strings.HasPrefix(s.grafanaVersion, latest.Testing) s.latestVersion = latest.Version
} else { s.hasUpdate = latest.Version != s.grafanaVersion
s.latestVersion = latest.Stable
s.hasUpdate = latest.Stable != s.grafanaVersion
} }
currVersion, err1 := version.NewVersion(s.grafanaVersion) currVersion, err1 := version.NewVersion(s.grafanaVersion)

Loading…
Cancel
Save