From 02b867d84ed43e0b0e27524afa87fae1f92f6835 Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Mon, 15 Jan 2024 10:51:38 +0000 Subject: [PATCH] remove latest.json and replace with api call to grafana.com --- .drone.yml | 16 +---------- .github/CODEOWNERS | 1 - conf/defaults.ini | 2 +- conf/sample.ini | 2 +- pkg/services/updatechecker/grafana.go | 27 +++++++++---------- scripts/drone/events/main.star | 1 - scripts/drone/events/pr.star | 1 - scripts/drone/pipelines/docs.star | 1 - scripts/drone/pipelines/shellcheck.star | 1 - .../drone/pipelines/trigger_downstream.star | 1 - scripts/drone/rgm.star | 1 - 11 files changed, 15 insertions(+), 39 deletions(-) diff --git a/.drone.yml b/.drone.yml index b2380ae67f1..ec896550d63 100644 --- a/.drone.yml +++ b/.drone.yml @@ -744,7 +744,6 @@ trigger: exclude: - '*.md' - docs/** - - latest.json type: docker volumes: - host: @@ -1080,7 +1079,6 @@ trigger: - '*.md' - docs/** - packages/**/*.md - - latest.json repo: - grafana/grafana type: docker @@ -1124,7 +1122,6 @@ trigger: exclude: - '*.md' - docs/** - - latest.json include: - scripts/**/*.sh type: docker @@ -1436,7 +1433,6 @@ trigger: - '*.md' - docs/** - packages/**/*.md - - latest.json repo: - grafana/grafana type: docker @@ -1493,7 +1489,6 @@ trigger: exclude: - '*.md' - docs/** - - latest.json repo: - grafana/grafana type: docker @@ -1561,7 +1556,6 @@ trigger: exclude: - '*.md' - docs/** - - latest.json repo: - grafana/grafana type: docker @@ -1640,7 +1634,6 @@ trigger: exclude: - '*.md' - docs/** - - latest.json repo: - grafana/grafana type: docker @@ -1714,7 +1707,6 @@ trigger: exclude: - '*.md' - docs/** - - latest.json repo: - grafana/grafana type: docker @@ -2114,7 +2106,6 @@ trigger: exclude: - '*.md' - docs/** - - latest.json repo: - grafana/grafana type: docker @@ -2344,7 +2335,6 @@ trigger: exclude: - '*.md' - docs/** - - latest.json repo: - grafana/grafana type: docker @@ -2399,7 +2389,6 @@ trigger: exclude: - '*.md' - docs/** - - latest.json repo: - grafana/grafana type: docker @@ -2445,7 +2434,6 @@ trigger: exclude: - '*.md' - docs/** - - latest.json repo: - grafana/grafana-security-mirror type: docker @@ -2486,7 +2474,6 @@ trigger: exclude: - '*.md' - docs/** - - latest.json repo: - grafana/grafana status: @@ -2887,7 +2874,6 @@ trigger: - '*.md' - docs/** - packages/**/*.md - - latest.json repo: - grafana/grafana type: docker @@ -4731,6 +4717,6 @@ kind: secret name: gcr_credentials --- kind: signature -hmac: 0fb0bf8e3d7ea206f4e58a70ae01017d1e113a1241e78da7dd38d25f894ec04d +hmac: e3875bd413d1eb9f9446b87eaee2d917d1548c4476e3047f09adc242ddf5868e ... diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 0410d4059d1..caa80d5bf09 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -361,7 +361,6 @@ lerna.json @grafana/frontend-ops /.eslintrc @grafana/frontend-ops /.vim @zoltanbedi /jest.config.js @grafana/frontend-ops -/latest.json @grafana/frontend-ops /metadata.md @grafana/plugins-platform /stylelint.config.js @grafana/frontend-ops /tools/ @grafana/frontend-ops diff --git a/conf/defaults.ini b/conf/defaults.ini index a12fccf8467..b5ec8efc511 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -246,7 +246,7 @@ reporting_distributor = grafana-labs # for new versions of grafana. The check is used # in some UI views to notify that a grafana update exists. # 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 # Set to false to disable all checks to https://grafana.com diff --git a/conf/sample.ini b/conf/sample.ini index ad9a28410fd..0533731c558 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -253,7 +253,7 @@ # for new versions of grafana. The check is used # in some UI views to notify that a grafana update exists. # 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 # Set to false to disable all checks to https://grafana.com diff --git a/pkg/services/updatechecker/grafana.go b/pkg/services/updatechecker/grafana.go index 006fc0be575..5a56d886c7d 100644 --- a/pkg/services/updatechecker/grafana.go +++ b/pkg/services/updatechecker/grafana.go @@ -20,7 +20,7 @@ import ( "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 { hasUpdate bool @@ -92,13 +92,13 @@ func (s *GrafanaService) instrumentedCheckForUpdates(ctx context.Context) { func (s *GrafanaService) checkForUpdates(ctx context.Context) error { ctxLogger := s.log.FromContext(ctx) 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 { return err } resp, err := s.httpClient.Do(req) 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() { 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) 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 { - Stable string `json:"stable"` - Testing string `json:"testing"` + type grafanaVersionJSON struct { + Version string `json:"version"` } - var latest latestJSON + var latest grafanaVersionJSON err = json.Unmarshal(body, &latest) 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() defer s.mutex.Unlock() - if strings.Contains(s.grafanaVersion, "-") { - s.latestVersion = latest.Testing - s.hasUpdate = !strings.HasPrefix(s.grafanaVersion, latest.Testing) - } else { - s.latestVersion = latest.Stable - s.hasUpdate = latest.Stable != s.grafanaVersion + // only check for updates in stable versions + if !strings.Contains(s.grafanaVersion, "-") { + s.latestVersion = latest.Version + s.hasUpdate = latest.Version != s.grafanaVersion } currVersion, err1 := version.NewVersion(s.grafanaVersion) diff --git a/scripts/drone/events/main.star b/scripts/drone/events/main.star index ee47392ee5c..d199c214d47 100644 --- a/scripts/drone/events/main.star +++ b/scripts/drone/events/main.star @@ -55,7 +55,6 @@ trigger = { "exclude": [ "*.md", "docs/**", - "latest.json", ], }, "repo": [ diff --git a/scripts/drone/events/pr.star b/scripts/drone/events/pr.star index 08472c20592..faf44075030 100644 --- a/scripts/drone/events/pr.star +++ b/scripts/drone/events/pr.star @@ -62,7 +62,6 @@ trigger = { "exclude": [ "*.md", "docs/**", - "latest.json", ], }, } diff --git a/scripts/drone/pipelines/docs.star b/scripts/drone/pipelines/docs.star index 536749b9e04..066eb195171 100644 --- a/scripts/drone/pipelines/docs.star +++ b/scripts/drone/pipelines/docs.star @@ -24,7 +24,6 @@ docs_paths = { "*.md", "docs/**", "packages/**/*.md", - "latest.json", ], } diff --git a/scripts/drone/pipelines/shellcheck.star b/scripts/drone/pipelines/shellcheck.star index 7f56c553976..db99416ff5e 100644 --- a/scripts/drone/pipelines/shellcheck.star +++ b/scripts/drone/pipelines/shellcheck.star @@ -20,7 +20,6 @@ trigger = { "exclude": [ "*.md", "docs/**", - "latest.json", ], "include": ["scripts/**/*.sh"], }, diff --git a/scripts/drone/pipelines/trigger_downstream.star b/scripts/drone/pipelines/trigger_downstream.star index fdff59792ed..ad428f89eed 100644 --- a/scripts/drone/pipelines/trigger_downstream.star +++ b/scripts/drone/pipelines/trigger_downstream.star @@ -20,7 +20,6 @@ trigger = { "exclude": [ "*.md", "docs/**", - "latest.json", ], }, "repo": [ diff --git a/scripts/drone/rgm.star b/scripts/drone/rgm.star index ab852f3f273..939b0d1f207 100644 --- a/scripts/drone/rgm.star +++ b/scripts/drone/rgm.star @@ -55,7 +55,6 @@ docs_paths = { "*.md", "docs/**", "packages/**/*.md", - "latest.json", ], }