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.
This commit is contained in:
Erik Seliger 2024-02-19 14:13:26 +01:00 committed by GitHub
parent 4165adc4de
commit a050df2a07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 14 additions and 75 deletions

View File

@ -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."))
})

View File

@ -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

View File

@ -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 = [

View File

@ -1,7 +0,0 @@
package api
type ExternalServiceConfigsRequest struct {
Kind string `json:"kind"`
Limit int `json:"limit"`
AfterID int `json:"after_id"`
}

View File

@ -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

View File

@ -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
}

View File

@ -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{} {

11
internal/env/env.go vendored
View File

@ -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
}

View File

@ -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

View File

@ -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