diff options
| author | Nicholas S. Husin <nsh@golang.org> | 2025-10-23 18:58:45 -0400 |
|---|---|---|
| committer | Nicholas Husin <nsh@golang.org> | 2025-10-28 11:40:29 -0700 |
| commit | 917c7a43f8b9f9e6231871c341fea2e965dff3c9 (patch) | |
| tree | 303cbe427f7d26d62a6c87c6a80d296a55e20254 | |
| parent | 4bd6c634f204f1469ab5130fc5b65eb843e98aac (diff) | |
| download | go-x-pkgsite-917c7a43f8b9f9e6231871c341fea2e965dff3c9.tar.xz | |
all: remove code for the decommissioned beta environment
The beta environment is no longer in use. This change removes related
logic and references, such as the middleware redirect to
beta.pkg.go.dev.
Change-Id: I0c6ebbe11d5689ccf2abf8c722399d8dc339db89
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/715321
kokoro-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
| -rw-r--r-- | cmd/frontend/main.go | 1 | ||||
| -rw-r--r-- | cmd/worker/main.go | 24 | ||||
| -rwxr-xr-x | deploy/config.sh | 2 | ||||
| -rwxr-xr-x | deploy/frontend.sh | 8 | ||||
| -rwxr-xr-x | deploy/pagecheck.sh | 2 | ||||
| -rwxr-xr-x | deploy/screentest.sh | 2 | ||||
| -rwxr-xr-x | deploy/worker.sh | 6 | ||||
| -rw-r--r-- | doc/config.md | 2 | ||||
| -rw-r--r-- | internal/config/config.go | 2 | ||||
| -rw-r--r-- | internal/config/serverconfig/config.go | 1 | ||||
| -rw-r--r-- | internal/middleware/betaRedirect.go | 75 | ||||
| -rw-r--r-- | internal/middleware/betaRedirect_test.go | 90 | ||||
| -rw-r--r-- | internal/worker/server.go | 28 |
13 files changed, 26 insertions, 217 deletions
diff --git a/cmd/frontend/main.go b/cmd/frontend/main.go index ad946ec5..7e070aa6 100644 --- a/cmd/frontend/main.go +++ b/cmd/frontend/main.go @@ -221,7 +221,6 @@ func main() { middleware.RequestInfo(), middleware.RequestLog(cmdconfig.Logger(ctx, cfg, "frontend-log")), middleware.AcceptRequests(http.MethodGet, http.MethodPost, http.MethodHead), // accept only GETs, POSTs and HEADs - middleware.BetaPkgGoDevRedirect(), middleware.GodocOrgRedirect(), middleware.Quota(cfg.Quota, redisClient), middleware.SecureHeaders(!*disableCSP), // must come before any caching for nonces to work diff --git a/cmd/worker/main.go b/cmd/worker/main.go index c93a145b..2917d499 100644 --- a/cmd/worker/main.go +++ b/cmd/worker/main.go @@ -102,19 +102,17 @@ func main() { return octrace.StartSpan(ctx, name) }) redisCacheClient := getCacheRedis(ctx, cfg) - redisBetaCacheClient := getBetaCacheRedis(ctx, cfg) experimenter := cmdconfig.Experimenter(ctx, cfg, expg, reporter) server, err := worker.NewServer(cfg, worker.ServerConfig{ - DB: db, - IndexClient: indexClient, - ProxyClient: proxyClient, - SourceClient: sourceClient, - RedisCacheClient: redisCacheClient, - RedisBetaCacheClient: redisBetaCacheClient, - Queue: fetchQueue, - Reporter: reporter, - StaticPath: template.TrustedSourceFromFlag(flag.Lookup("static").Value), - GetExperiments: experimenter.Experiments, + DB: db, + IndexClient: indexClient, + ProxyClient: proxyClient, + SourceClient: sourceClient, + RedisCacheClient: redisCacheClient, + Queue: fetchQueue, + Reporter: reporter, + StaticPath: template.TrustedSourceFromFlag(flag.Lookup("static").Value), + GetExperiments: experimenter.Experiments, }) if err != nil { log.Fatal(ctx, err) @@ -167,10 +165,6 @@ func getCacheRedis(ctx context.Context, cfg *config.Config) *redis.Client { return getRedis(ctx, cfg.RedisCacheHost, cfg.RedisCachePort, 0, 6*time.Second) } -func getBetaCacheRedis(ctx context.Context, cfg *config.Config) *redis.Client { - return getRedis(ctx, cfg.RedisBetaCacheHost, cfg.RedisCachePort, 0, 6*time.Second) -} - func getRedis(ctx context.Context, host, port string, writeTimeout, readTimeout time.Duration) *redis.Client { if host == "" { return nil diff --git a/deploy/config.sh b/deploy/config.sh index b09f0f34..7ffaeba8 100755 --- a/deploy/config.sh +++ b/deploy/config.sh @@ -10,7 +10,7 @@ source private/devtools/lib.sh || { echo "Are you at repo root?"; exit 1; } usage() { >&2 cat <<EOUSAGE - Usage: $0 [exp|dev|staging|prod|beta] + Usage: $0 [exp|dev|staging|prod] Copy the dynamic config to the cloud storage bucket for the given environment. diff --git a/deploy/frontend.sh b/deploy/frontend.sh index 20d04cc6..4889ce79 100755 --- a/deploy/frontend.sh +++ b/deploy/frontend.sh @@ -10,7 +10,7 @@ source private/devtools/lib.sh || { echo "Are you at repo root?"; exit 1; } usage() { >&2 cat <<EOUSAGE - Usage: $0 [exp|dev|staging|prod|beta] NAME:TAG + Usage: $0 [exp|dev|staging|prod] NAME:TAG Deploy a frontend image to Cloud Run for the given environment. @@ -31,11 +31,7 @@ main() { local tok=$(private/devtools/idtoken.sh $env) local hdr="Authorization: Bearer $tok" info "Clearing the redis cache." - if [[ $env == "beta" ]]; then - curl -H "$hdr" $(worker_url prod)/clear-beta-cache - else - curl -H "$hdr" $(worker_url $env)/clear-cache - fi + curl -H "$hdr" $(worker_url $env)/clear-cache info "Running warmups." private/devtools/warmups.sh $env $tok } diff --git a/deploy/pagecheck.sh b/deploy/pagecheck.sh index 72108edf..ae33f713 100755 --- a/deploy/pagecheck.sh +++ b/deploy/pagecheck.sh @@ -17,7 +17,7 @@ source devtools/lib.sh || { echo "Are you at repo root?"; exit 1; } usage() { cat >&2 <<END - Usage: $0 [exp|dev|staging|prod|beta] IDTOKEN + Usage: $0 [exp|dev|staging|prod] IDTOKEN Run the pagecheck tests against the given environment diff --git a/deploy/screentest.sh b/deploy/screentest.sh index fd003d0b..130a3520 100755 --- a/deploy/screentest.sh +++ b/deploy/screentest.sh @@ -10,7 +10,7 @@ source private/devtools/lib.sh || { echo "Are you at repo root?"; exit 1; } usage() { >&2 cat <<EOUSAGE - Usage: $0 [OPTIONS] [exp|dev|staging|prod|beta] [IDTOKEN] + Usage: $0 [OPTIONS] [exp|dev|staging|prod] [IDTOKEN] Run the screentest check against a live instance of the given environment. These tests will only pass against staging and prod. diff --git a/deploy/worker.sh b/deploy/worker.sh index f1051e57..26804ec3 100755 --- a/deploy/worker.sh +++ b/deploy/worker.sh @@ -10,7 +10,7 @@ source private/devtools/lib.sh || { echo "Are you at repo root?"; exit 1; } usage() { >&2 cat <<EOUSAGE - Usage: $0 [exp|dev|staging|prod|beta] NAME:TAG + Usage: $0 [exp|dev|staging|prod] NAME:TAG Deploy a worker image to gke for the given environment. @@ -23,10 +23,6 @@ main() { local image=$2 check_env $env check_image $image - if [[ $env = "beta" ]]; then - info "skipping worker deploy for $env" - return - fi runcmd docker run -v $(pwd)/private:/private cuelang/cue:0.4.0 cmd \ -t env=$env \ -t app=worker \ diff --git a/doc/config.md b/doc/config.md index 81d280bb..12a2751b 100644 --- a/doc/config.md +++ b/doc/config.md @@ -10,7 +10,7 @@ Pkgsite uses these environment variables: | GO_DISCOVERY_DATABASE_HOST | Database server hostname. | | GO_DISCOVERY_DATABASE_NAME | Name of database within the server. | | GO_DISCOVERY_DATABASE_PASSWORD | Password for database. | -| GO_DISCOVERY_DATABASE_SECONDARY_HOST | If `GO_DISCOVERY_DATABASE_HOST` is unreachable, use this host. Used only by prod and beta frontends. | +| GO_DISCOVERY_DATABASE_SECONDARY_HOST | If `GO_DISCOVERY_DATABASE_HOST` is unreachable, use this host. Used only by prod frontends. | | GO_DISCOVERY_DATABASE_USER | Used for frontend, worker and scripts. | | GO_DISCOVERY_DISABLE_ERROR_REPORTING | Disables calls to GCP errorreporting API. Set only in dev. | | GO_DISCOVERY_E2E_AUTHORIZATION | Auth token for e2e tests. | diff --git a/internal/config/config.go b/internal/config/config.go index cc60ec97..73924c42 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -86,7 +86,7 @@ type Config struct { DBPassword string `json:"-" yaml:"-"` // Configuration for redis page cache. - RedisCacheHost, RedisBetaCacheHost, RedisCachePort string + RedisCacheHost, RedisCachePort string // UseProfiler specifies whether to enable Stackdriver Profiler. UseProfiler bool diff --git a/internal/config/serverconfig/config.go b/internal/config/serverconfig/config.go index 196e9e93..643453b3 100644 --- a/internal/config/serverconfig/config.go +++ b/internal/config/serverconfig/config.go @@ -150,7 +150,6 @@ func Init(ctx context.Context) (_ *config.Config, err error) { DBSecret: os.Getenv("GO_DISCOVERY_DATABASE_SECRET"), DBSSL: GetEnv("GO_DISCOVERY_DATABASE_SSL", "disable"), RedisCacheHost: os.Getenv("GO_DISCOVERY_REDIS_HOST"), - RedisBetaCacheHost: os.Getenv("GO_DISCOVERY_REDIS_BETA_HOST"), RedisCachePort: GetEnv("GO_DISCOVERY_REDIS_PORT", "6379"), Quota: config.QuotaSettings{ Enable: os.Getenv("GO_DISCOVERY_ENABLE_QUOTA") == "true", diff --git a/internal/middleware/betaRedirect.go b/internal/middleware/betaRedirect.go deleted file mode 100644 index 975ef13d..00000000 --- a/internal/middleware/betaRedirect.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2020 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package middleware - -import ( - "net/http" - "net/url" -) - -const ( - betaPkgGoDevRedirectCookie = "betapkggodev-redirect" - betaPkgGoDevRedirectParam = "betaredirect" - betaPkgGoDevRedirectOn = "on" - betaPkgGoDevRedirectOff = "off" - betaPkgGoDevHost = "beta.pkg.go.dev" -) - -// BetaPkgGoDevRedirect redirects requests from pkg.go.dev to beta.pkg.go.dev, -// based on whether a cookie is set for betapkggodev-redirect. The cookie -// can be turned on/off using a query param. -func BetaPkgGoDevRedirect() Middleware { - return func(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if userReturningFromBetaPkgGoDev(r) { - h.ServeHTTP(w, r) - return - } - - redirectParam := r.FormValue(betaPkgGoDevRedirectParam) - - if redirectParam == betaPkgGoDevRedirectOn { - cookie := &http.Cookie{Name: betaPkgGoDevRedirectCookie, Value: redirectParam, Path: "/"} - http.SetCookie(w, cookie) - } - if redirectParam == betaPkgGoDevRedirectOff { - cookie := &http.Cookie{Name: betaPkgGoDevRedirectCookie, Value: "", MaxAge: -1, Path: "/"} - http.SetCookie(w, cookie) - } - - if !shouldRedirectToBetaPkgGoDev(r) { - h.ServeHTTP(w, r) - return - } - - http.Redirect(w, r, betaPkgGoDevURL(r.URL).String(), http.StatusFound) - }) - } -} - -func userReturningFromBetaPkgGoDev(req *http.Request) bool { - return req.FormValue("utm_source") == "backtopkggodev" -} - -func shouldRedirectToBetaPkgGoDev(req *http.Request) bool { - redirectParam := req.FormValue(betaPkgGoDevRedirectParam) - if redirectParam == betaPkgGoDevRedirectOn || redirectParam == betaPkgGoDevRedirectOff { - return redirectParam == betaPkgGoDevRedirectOn - } - cookie, err := req.Cookie(betaPkgGoDevRedirectCookie) - return (err == nil && cookie.Value == betaPkgGoDevRedirectOn) -} - -func betaPkgGoDevURL(sourceURL *url.URL) *url.URL { - values := sourceURL.Query() - values.Del(betaPkgGoDevRedirectParam) - values.Set("utm_source", "pkggodev") - return &url.URL{ - Scheme: "https", - Host: betaPkgGoDevHost, - Path: sourceURL.Path, - RawQuery: values.Encode(), - } -} diff --git a/internal/middleware/betaRedirect_test.go b/internal/middleware/betaRedirect_test.go deleted file mode 100644 index f689c5ef..00000000 --- a/internal/middleware/betaRedirect_test.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2020 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package middleware - -import ( - "net/http" - "net/http/httptest" - "testing" -) - -func TestHandleBetaPkgGoDevRedirect(t *testing.T) { - handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}) - - h := BetaPkgGoDevRedirect()(handler) - - for _, test := range []struct { - name, url, wantLocationHeader, wantSetCookieHeader string - wantStatusCode int - cookie *http.Cookie - }{ - { - name: "test betapkggodev-redirect param is on", - url: "https://pkg.go.dev/net/http?tab=doc&betaredirect=on", - wantLocationHeader: "https://beta.pkg.go.dev/net/http?tab=doc&utm_source=pkggodev", - wantSetCookieHeader: "betapkggodev-redirect=on; Path=/", - wantStatusCode: http.StatusFound, - }, - { - name: "test betapkggodev-redirect param is off", - url: "https://pkg.go.dev/net/http?betaredirect=off", - wantLocationHeader: "", - wantSetCookieHeader: "betapkggodev-redirect=; Path=/; Max-Age=0", - wantStatusCode: http.StatusOK, - }, - { - name: "test betapkggodev-redirect param is unset", - url: "https://pkg.go.dev/net/http", - wantLocationHeader: "", - wantSetCookieHeader: "", - wantStatusCode: http.StatusOK, - }, - { - name: "toggle enabled betapkggodev-redirect cookie", - url: "https://pkg.go.dev/net/http?betaredirect=off", - cookie: &http.Cookie{Name: "betapkggodev-redirect", Value: "true"}, - wantLocationHeader: "", - wantSetCookieHeader: "betapkggodev-redirect=; Path=/; Max-Age=0", - wantStatusCode: http.StatusOK, - }, - { - name: "betapkggodev-redirect enabled cookie should redirect", - url: "https://pkg.go.dev/net/http", - cookie: &http.Cookie{Name: "betapkggodev-redirect", Value: "on"}, - wantLocationHeader: "https://beta.pkg.go.dev/net/http?utm_source=pkggodev", - wantSetCookieHeader: "", - wantStatusCode: http.StatusFound, - }, - { - name: "do not redirect if user is returning from beta.pkg.go.dev", - url: "https://pkg.go.dev/net/http?utm_source=backtopkggodev", - cookie: &http.Cookie{Name: "betapkggodev-redirect", Value: "on"}, - wantStatusCode: http.StatusOK, - }, - } { - t.Run(test.name, func(t *testing.T) { - req := httptest.NewRequest("GET", test.url, nil) - if test.cookie != nil { - req.AddCookie(test.cookie) - } - - w := httptest.NewRecorder() - h.ServeHTTP(w, req) - resp := w.Result() - - if got, want := resp.Header.Get("Location"), test.wantLocationHeader; got != want { - t.Errorf("Location header mismatch: got %q; want %q", got, want) - } - - if got, want := resp.Header.Get("Set-Cookie"), test.wantSetCookieHeader; got != want { - t.Errorf("Set-Cookie header mismatch: got %q; want %q", got, want) - } - - if got, want := resp.StatusCode, test.wantStatusCode; got != want { - t.Errorf("Status code mismatch: got %d; want %d", got, want) - } - }) - } -} diff --git a/internal/worker/server.go b/internal/worker/server.go index 0ad2b5b1..d01e69fb 100644 --- a/internal/worker/server.go +++ b/internal/worker/server.go @@ -51,7 +51,6 @@ type Server struct { proxyClient *proxy.Client sourceClient *source.Client cache *cache.Cache - betaCache *cache.Cache db *postgres.DB queue queue.Queue reporter derrors.Reporter @@ -64,16 +63,15 @@ type Server struct { // ServerConfig contains everything needed by a Server. type ServerConfig struct { - DB *postgres.DB - IndexClient *index.Client - ProxyClient *proxy.Client - SourceClient *source.Client - RedisCacheClient *redis.Client - RedisBetaCacheClient *redis.Client - Queue queue.Queue - Reporter derrors.Reporter - StaticPath template.TrustedSource - GetExperiments func() []*internal.Experiment + DB *postgres.DB + IndexClient *index.Client + ProxyClient *proxy.Client + SourceClient *source.Client + RedisCacheClient *redis.Client + Queue queue.Queue + Reporter derrors.Reporter + StaticPath template.TrustedSource + GetExperiments func() []*internal.Experiment } const ( @@ -100,10 +98,6 @@ func NewServer(cfg *config.Config, scfg ServerConfig) (_ *Server, err error) { if scfg.RedisCacheClient != nil { c = cache.New(scfg.RedisCacheClient) } - var bc *cache.Cache - if scfg.RedisBetaCacheClient != nil { - bc = cache.New(scfg.RedisBetaCacheClient) - } // Update information about DB locks, etc. every few seconds. p := poller.New(&postgres.UserInfo{}, func(ctx context.Context) (any, error) { @@ -118,7 +112,6 @@ func NewServer(cfg *config.Config, scfg ServerConfig) (_ *Server, err error) { proxyClient: scfg.ProxyClient, sourceClient: scfg.SourceClient, cache: c, - betaCache: bc, queue: scfg.Queue, reporter: scfg.Reporter, templates: templates, @@ -226,9 +219,6 @@ func (s *Server) Install(handle func(string, http.Handler)) { // manual: clear-cache clears the redis cache. handle("/clear-cache", rmw(s.clearCache(s.cache))) - // manual: clear-beta-cache clears the redis beta cache. - handle("/clear-beta-cache", rmw(s.clearCache(s.betaCache))) - // manual: delete the specified module version. handle("/delete/", http.StripPrefix("/delete", rmw(s.errorHandler(s.handleDelete)))) |
