From a050df2a07f1a313e190528444655779868adca1 Mon Sep 17 00:00:00 2001 From: Erik Seliger Date: Mon, 19 Feb 2024 14:13:26 +0100 Subject: [PATCH] Cleanup internalapi after gRPC migration (#60572) We no longer need this endpoint. Also found a few other things related to internalapi on the way that could use a cleanup. ## Test plan Integration tests should verify that conf works just as before. --- cmd/frontend/internal/httpapi/httpapi.go | 15 ++++++--------- cmd/frontend/internal/httpapi/internal.go | 12 ------------ internal/api/BUILD.bazel | 5 +---- internal/api/httpapi_schema.go | 7 ------- internal/api/internalapi/client.go | 6 +----- internal/codemonitors/background/email.go | 4 ++-- internal/conf/client.go | 19 ++++--------------- internal/env/env.go | 11 ----------- internal/txemail/txemail.go | 3 --- internal/txemail/txtypes/types.go | 7 ------- 10 files changed, 14 insertions(+), 75 deletions(-) delete mode 100644 internal/api/httpapi_schema.go diff --git a/cmd/frontend/internal/httpapi/httpapi.go b/cmd/frontend/internal/httpapi/httpapi.go index 8bda8585ef6..b26d2a09d51 100644 --- a/cmd/frontend/internal/httpapi/httpapi.go +++ b/cmd/frontend/internal/httpapi/httpapi.go @@ -262,14 +262,14 @@ func RegisterInternalServices( WriteErrBody: true, }) - // zoekt-indexserver endpoints - gsClient := gitserver.NewClient("http.zoektindexerserver") + gsClient := gitserver.NewClient("http.internalapi") + // zoekt-indexserver endpoints indexer := &searchIndexerServer{ db: db, logger: logger.Scoped("searchIndexerServer"), - gitserverClient: gsClient, - ListIndexable: backend.NewRepos(logger, db, gsClient).ListIndexable, + gitserverClient: gsClient.Scoped("zoektindexerserver"), + ListIndexable: backend.NewRepos(logger, db, gsClient.Scoped("zoektindexerserver")).ListIndexable, RepoStore: db.Repos(), SearchContextsRepoRevs: func(ctx context.Context, repoIDs []api.RepoID) (map[api.RepoID][]string, error) { return searchcontexts.RepoRevs(ctx, db, repoIDs) @@ -279,13 +279,10 @@ func RegisterInternalServices( MinLastChangedDisabled: os.Getenv("SRC_SEARCH_INDEXER_EFFICIENT_POLLING_DISABLED") != "", } - gitService := &gitServiceHandler{Gitserver: gsClient} + gitService := &gitServiceHandler{Gitserver: gsClient.Scoped("gitservice")} m.Path("/git/{RepoName:.*}/info/refs").Methods("GET").Name(gitInfoRefs).Handler(trace.Route(handler(gitService.serveInfoRefs()))) m.Path("/git/{RepoName:.*}/git-upload-pack").Methods("GET", "POST").Name(gitUploadPack).Handler(trace.Route(handler(gitService.serveGitUploadPack()))) - // TODO: Can be removed after 5.3 is cut. - m.Path("/configuration").Methods("POST").Handler(trace.Route(handler(serveConfiguration))) - m.Path("/lsif/upload").Methods("POST").Handler(trace.Route(newCodeIntelUploadHandler(false))) m.Path("/scip/upload").Methods("POST").Handler(trace.Route(newCodeIntelUploadHandler(false))) m.Path("/scip/upload").Methods("HEAD").Handler(trace.Route(noopHandler)) @@ -375,5 +372,5 @@ var noopHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) var lsifDeprecationHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotImplemented) - w.Write([]byte("Sourcegraph v4.5+ no longer accepts LSIF uploads. The Sourcegraph CLI v4.4.2+ will translate LSIF to SCIP prior to uploading. Please check the version of the CLI utility used to upload this artifact.")) + _, _ = w.Write([]byte("Sourcegraph v4.5+ no longer accepts LSIF uploads. The Sourcegraph CLI v4.4.2+ will translate LSIF to SCIP prior to uploading. Please check the version of the CLI utility used to upload this artifact.")) }) diff --git a/cmd/frontend/internal/httpapi/internal.go b/cmd/frontend/internal/httpapi/internal.go index d6ded988fd4..09c63997334 100644 --- a/cmd/frontend/internal/httpapi/internal.go +++ b/cmd/frontend/internal/httpapi/internal.go @@ -2,7 +2,6 @@ package httpapi import ( "context" - "encoding/json" "net/http" "net/url" "path" @@ -12,19 +11,8 @@ import ( "github.com/sourcegraph/sourcegraph/internal/api" proto "github.com/sourcegraph/sourcegraph/internal/api/internalapi/v1" "github.com/sourcegraph/sourcegraph/internal/conf" - "github.com/sourcegraph/sourcegraph/lib/errors" ) -// TODO: Can be removed after 5.3 is cut. -func serveConfiguration(w http.ResponseWriter, _ *http.Request) error { - raw := conf.Raw() - err := json.NewEncoder(w).Encode(raw) - if err != nil { - return errors.Wrap(err, "Encode") - } - return nil -} - // configServer implements proto.ConfigServiceServer to serve config to other clients in the cluster. type configServer struct { proto.UnimplementedConfigServiceServer diff --git a/internal/api/BUILD.bazel b/internal/api/BUILD.bazel index 1b2c5e26e41..746ce833ceb 100644 --- a/internal/api/BUILD.bazel +++ b/internal/api/BUILD.bazel @@ -3,10 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( name = "api", - srcs = [ - "api.go", - "httpapi_schema.go", - ], + srcs = ["api.go"], importpath = "github.com/sourcegraph/sourcegraph/internal/api", visibility = ["//:__subpackages__"], deps = [ diff --git a/internal/api/httpapi_schema.go b/internal/api/httpapi_schema.go deleted file mode 100644 index 7ddd4e71302..00000000000 --- a/internal/api/httpapi_schema.go +++ /dev/null @@ -1,7 +0,0 @@ -package api - -type ExternalServiceConfigsRequest struct { - Kind string `json:"kind"` - Limit int `json:"limit"` - AfterID int `json:"after_id"` -} diff --git a/internal/api/internalapi/client.go b/internal/api/internalapi/client.go index ed3322070bc..bb26d3a1c6a 100644 --- a/internal/api/internalapi/client.go +++ b/internal/api/internalapi/client.go @@ -17,14 +17,10 @@ import ( ) var frontendInternal = func() *url.URL { - rawURL := env.Get("SRC_FRONTEND_INTERNAL", defaultFrontendInternal(), "HTTP address for internal frontend HTTP API.") + rawURL := env.Get("SRC_FRONTEND_INTERNAL", "sourcegraph-frontend-internal", "HTTP address for internal frontend HTTP API.") return mustParseSourcegraphInternalURL(rawURL) }() -func defaultFrontendInternal() string { - return "sourcegraph-frontend-internal" -} - type internalClient struct { // URL is the root to the internal API frontend server. URL string diff --git a/internal/codemonitors/background/email.go b/internal/codemonitors/background/email.go index 8e6fc77062d..c677847a624 100644 --- a/internal/codemonitors/background/email.go +++ b/internal/codemonitors/background/email.go @@ -124,7 +124,7 @@ func sendEmail(ctx context.Context, db database.DB, userID int32, template txtyp if errcode.IsNotFound(err) { return errors.Errorf("unable to send email to user ID %d with unknown email address", userID) } - return errors.Errorf("internalapi.Client.UserEmailsGetEmail for userID=%d: %w", userID, err) + return errors.Errorf("get primary email for userID=%d: %w", userID, err) } if !verified { return errors.Newf("unable to send email to user ID %d's unverified primary email address", userID) @@ -135,7 +135,7 @@ func sendEmail(ctx context.Context, db database.DB, userID int32, template txtyp Template: template, Data: data, }); err != nil { - return errors.Errorf("internalapi.Client.SendEmail to email=%q userID=%d: %w", email, userID, err) + return errors.Errorf("send mail to email=%q userID=%d: %w", email, userID, err) } return nil } diff --git a/internal/conf/client.go b/internal/conf/client.go index 009af7bbe6e..db3546b296b 100644 --- a/internal/conf/client.go +++ b/internal/conf/client.go @@ -3,7 +3,6 @@ package conf import ( "context" "math/rand" - "net" "sync" "sync/atomic" "time" @@ -257,20 +256,10 @@ func (c *client) continuouslyUpdate(optOnlySetByTests *continuousUpdateOptions) } isFrontendUnreachableError := func(err error) bool { - var e *net.OpError - if errors.As(err, &e) && e.Op == "dial" { - return true - } - - // If we're using gRPC to fetch configuration, gRPC clients will return - // a status code of "Unavailable" if the server is unreachable. See - // https://grpc.github.io/grpc/core/md_doc_statuscodes.html for more - // information. - if status.Code(err) == codes.Unavailable { - return true - } - - return false + // gRPC clients will return a status code of "Unavailable" if the server + // is unreachable. See https://grpc.github.io/grpc/core/md_doc_statuscodes.html + // for more information. + return status.Code(err) == codes.Unavailable } waitForSleep := func() <-chan struct{} { diff --git a/internal/env/env.go b/internal/env/env.go index 65042723aa7..1b25dad72cf 100644 --- a/internal/env/env.go +++ b/internal/env/env.go @@ -197,14 +197,3 @@ func HandleHelpFlag() { } } } - -// HackClearEnvironCache can be used to clear the environ cache if os.Setenv was called and you want -// subsequent env.Get calls to return the new value. It is a hack but useful because some env.Get -// calls are hard to remove from static init time, and the ones we've moved to post-init we want to -// be able to use the default values we set in package singleprogram. -// -// TODO(sqs): TODO(single-binary): this indicates our initialization order could be better, hence this -// is labeled as a hack. -func HackClearEnvironCache() { - environ = nil -} diff --git a/internal/txemail/txemail.go b/internal/txemail/txemail.go index cf645070e62..5a2ad2dd5df 100644 --- a/internal/txemail/txemail.go +++ b/internal/txemail/txemail.go @@ -72,9 +72,6 @@ func render(fromAddress, fromName string, message Message) (*email.Email, error) // should use this directly to send emails. Source is used to categorize metrics, and // should indicate the product feature that is sending this email. // -// Callers that do not live in the frontend should call internalapi.Client.SendEmail -// instead. -// // 🚨 SECURITY: If the email address is associated with a user, make sure to assess whether // the email should be verified or not, and conduct the appropriate checks before sending. // This helps reduce the chance that we damage email sender reputations when attempting to diff --git a/internal/txemail/txtypes/types.go b/internal/txemail/txtypes/types.go index 69bd9b76e9b..6062ca6c461 100644 --- a/internal/txemail/txtypes/types.go +++ b/internal/txemail/txtypes/types.go @@ -5,13 +5,6 @@ import ( texttemplate "text/template" ) -// InternalAPIMessage describes an email message to be sent via the 'internal.send-email' -// endpoint. -type InternalAPIMessage struct { - Source string - Message -} - // Message describes an email message to be sent. type Message struct { To []string // email "To" recipients