Skip to content

Commit 127dece

Browse files
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 bcff43d898d571c36680c2267c3cfaa5d8a60bef. * Revert "remove latest.json and replace with api call to grafana.com" This reverts commit 02b867d84ed43e0b0e27524afa87fae1f92f6835. * add deprecation message to latest.json
1 parent 31256bc commit 127dece

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

conf/defaults.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ reporting_distributor = grafana-labs
246246
# for new versions of grafana. The check is used
247247
# in some UI views to notify that a grafana update exists.
248248
# This option does not cause any auto updates, nor send any information
249-
# only a GET request to https://raw.githubusercontent.com/grafana/grafana/main/latest.json to get the latest version.
249+
# only a GET request to https://grafana.com/api/grafana/versions/stable to get the latest version.
250250
check_for_updates = true
251251

252252
# Set to false to disable all checks to https://grafana.com

conf/sample.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
# for new versions of grafana. The check is used
254254
# in some UI views to notify that a grafana update exists.
255255
# This option does not cause any auto updates, nor send any information
256-
# only a GET request to https://raw.githubusercontent.com/grafana/grafana/main/latest.json to get the latest version.
256+
# only a GET request to https://grafana.com/api/grafana/versions/stable to get the latest version.
257257
;check_for_updates = true
258258

259259
# Set to false to disable all checks to https://grafana.com

latest.json

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

pkg/services/updatechecker/grafana.go

+12-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/grafana/grafana/pkg/setting"
2121
)
2222

23-
const grafanaLatestJSONURL = "https://raw.githubusercontent.com/grafana/grafana/main/latest.json"
23+
const grafanaStableVersionURL = "https://grafana.com/api/grafana/versions/stable"
2424

2525
type GrafanaService struct {
2626
hasUpdate bool
@@ -92,13 +92,13 @@ func (s *GrafanaService) instrumentedCheckForUpdates(ctx context.Context) {
9292
func (s *GrafanaService) checkForUpdates(ctx context.Context) error {
9393
ctxLogger := s.log.FromContext(ctx)
9494
ctxLogger.Debug("Checking for updates")
95-
req, err := http.NewRequestWithContext(ctx, http.MethodGet, grafanaLatestJSONURL, nil)
95+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, grafanaStableVersionURL, nil)
9696
if err != nil {
9797
return err
9898
}
9999
resp, err := s.httpClient.Do(req)
100100
if err != nil {
101-
return fmt.Errorf("failed to get latest.json repo from github.com: %w", err)
101+
return fmt.Errorf("failed to get stable version from grafana.com: %w", err)
102102
}
103103
defer func() {
104104
if err := resp.Body.Close(); err != nil {
@@ -107,27 +107,24 @@ func (s *GrafanaService) checkForUpdates(ctx context.Context) error {
107107
}()
108108
body, err := io.ReadAll(resp.Body)
109109
if err != nil {
110-
return fmt.Errorf("update check failed, reading response from github.com: %w", err)
110+
return fmt.Errorf("update check failed, reading response from grafana.com: %w", err)
111111
}
112112

113-
type latestJSON struct {
114-
Stable string `json:"stable"`
115-
Testing string `json:"testing"`
113+
type grafanaVersionJSON struct {
114+
Version string `json:"version"`
116115
}
117-
var latest latestJSON
116+
var latest grafanaVersionJSON
118117
err = json.Unmarshal(body, &latest)
119118
if err != nil {
120-
return fmt.Errorf("failed to unmarshal latest.json: %w", err)
119+
return fmt.Errorf("failed to unmarshal response from grafana.com: %w", err)
121120
}
122121

123122
s.mutex.Lock()
124123
defer s.mutex.Unlock()
125-
if strings.Contains(s.grafanaVersion, "-") {
126-
s.latestVersion = latest.Testing
127-
s.hasUpdate = !strings.HasPrefix(s.grafanaVersion, latest.Testing)
128-
} else {
129-
s.latestVersion = latest.Stable
130-
s.hasUpdate = latest.Stable != s.grafanaVersion
124+
// only check for updates in stable versions
125+
if !strings.Contains(s.grafanaVersion, "-") {
126+
s.latestVersion = latest.Version
127+
s.hasUpdate = latest.Version != s.grafanaVersion
131128
}
132129

133130
currVersion, err1 := version.NewVersion(s.grafanaVersion)

0 commit comments

Comments
 (0)