chore: Deglobalize oneclickexporter instance (#64066)

This PR removes the requirement that a global variable is initialized in
the frontend main function. Instead, we create a data exporter where
it's used.

Test plan: CI passes, code review.
This commit is contained in:
Erik Seliger 2024-07-31 04:34:12 +02:00 committed by GitHub
parent 3413c37c64
commit 32e58ad055
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 3 additions and 12 deletions

View File

@ -30,7 +30,7 @@ func oneClickExportHandler(db database.DB, logger log.Logger) http.HandlerFunc {
return
}
archive, err := oce.GlobalExporter.Export(ctx, request)
archive, err := oce.NewDataExporter(db, logger).Export(ctx, request)
if err != nil {
logger.Error("OneClickExport", log.Error(err))
w.WriteHeader(http.StatusInternalServerError)

View File

@ -10,6 +10,7 @@ import (
"testing"
"github.com/sourcegraph/log/logtest"
oce "github.com/sourcegraph/sourcegraph/cmd/frontend/oneclickexport"
"github.com/sourcegraph/sourcegraph/internal/actor"
@ -32,11 +33,6 @@ func TestOneClickExportHandler(t *testing.T) {
})
t.Run("admins can download the archive", func(t *testing.T) {
oce.GlobalExporter = oce.NewDataExporter(db, logger)
t.Cleanup(func() {
oce.GlobalExporter = nil
})
request := oce.ExportRequest{
IncludeSiteConfig: true,
IncludeCodeHostConfig: true,

View File

@ -33,7 +33,6 @@ go_library(
"//cmd/frontend/internal/cli/middleware",
"//cmd/frontend/internal/highlight",
"//cmd/frontend/internal/httpapi",
"//cmd/frontend/oneclickexport",
"//internal/actor",
"//internal/api",
"//internal/auth",

View File

@ -26,7 +26,6 @@ import (
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/bg"
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/highlight"
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/httpapi"
oce "github.com/sourcegraph/sourcegraph/cmd/frontend/oneclickexport"
"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/authz/providers"
"github.com/sourcegraph/sourcegraph/internal/conf"
@ -244,8 +243,6 @@ func Main(ctx context.Context, observationCtx *observation.Context, ready servic
routines = append(routines, internalAPI)
}
oce.GlobalExporter = oce.NewDataExporter(db, logger)
debugserverEndpoints.GlobalRateLimiterState = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
info, err := ratelimit.GetGlobalLimiterState(r.Context())
if err != nil {

View File

@ -9,6 +9,7 @@ import (
"path/filepath"
"github.com/sourcegraph/log"
"github.com/sourcegraph/sourcegraph/internal/database"
)
@ -20,8 +21,6 @@ type Exporter interface {
var _ Exporter = &DataExporter{}
var GlobalExporter Exporter
type DataExporter struct {
logger log.Logger
configProcessors map[string]Processor[ConfigRequest]