mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:51:57 +00:00
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:
parent
3413c37c64
commit
32e58ad055
@ -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)
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user