Skip to content

Commit

Permalink
Allow creating blobstore without env (#8237)
Browse files Browse the repository at this point in the history
  • Loading branch information
bduffany authored Jan 23, 2025
1 parent edaddfc commit 106e2ee
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion server/backends/blobstore/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ go_library(
"//server/backends/blobstore/disk",
"//server/backends/blobstore/gcs",
"//server/backends/blobstore/util",
"//server/environment",
"//server/interfaces",
"//server/real_environment",
"//server/util/log",
],
)
22 changes: 15 additions & 7 deletions server/backends/blobstore/blobstore.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
package blobstore

import (
"context"
"fmt"

"github.com/buildbuddy-io/buildbuddy/server/backends/blobstore/aws"
"github.com/buildbuddy-io/buildbuddy/server/backends/blobstore/azure"
"github.com/buildbuddy-io/buildbuddy/server/backends/blobstore/disk"
"github.com/buildbuddy-io/buildbuddy/server/backends/blobstore/gcs"
"github.com/buildbuddy-io/buildbuddy/server/backends/blobstore/util"
"github.com/buildbuddy-io/buildbuddy/server/environment"
"github.com/buildbuddy-io/buildbuddy/server/interfaces"
"github.com/buildbuddy-io/buildbuddy/server/real_environment"
"github.com/buildbuddy-io/buildbuddy/server/util/log"
)

// Returns whatever blobstore is specified in the config.
func GetConfiguredBlobstore(env environment.Env) (interfaces.Blobstore, error) {
bs, err := getBlobstore(env)
func Register(env *real_environment.RealEnv) error {
bs, err := NewFromConfig(env.GetServerContext())
if err != nil {
return bs, err
return err
}
env.SetBlobstore(bs)
return nil
}

// NewFromConfig returns whatever blobstore is specified in the config.
func NewFromConfig(ctx context.Context) (interfaces.Blobstore, error) {
bs, err := getBlobstore(ctx)
if err != nil {
return bs, err
}
return util.NewDefaultPrefixBlobstore(bs), nil
}

func getBlobstore(env environment.Env) (interfaces.Blobstore, error) {
func getBlobstore(ctx context.Context) (interfaces.Blobstore, error) {
log.Debug("Configuring blobstore")
ctx := env.GetServerContext()
if gcs.UseGCSBlobStore() {
log.Debug("Configuring GCS blobstore")
return gcs.NewGCSBlobStore(ctx, true /*=enableCompression*/)
Expand Down
4 changes: 1 addition & 3 deletions server/libmain/libmain.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,9 @@ func GetConfiguredEnvironmentOrDie(healthChecker *healthcheck.HealthChecker, app
realEnv.SetDBHandle(dbHandle)
realEnv.SetInvocationDB(invocationdb.NewInvocationDB(realEnv, dbHandle))

bs, err := blobstore.GetConfiguredBlobstore(realEnv)
if err != nil {
if err := blobstore.Register(realEnv); err != nil {
log.Fatalf("Error configuring blobstore: %s", err)
}
realEnv.SetBlobstore(bs)

realEnv.SetWebhooks(make([]interfaces.Webhook, 0))
if err := slack.Register(realEnv); err != nil {
Expand Down
1 change: 0 additions & 1 deletion server/telemetry/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//proto:telemetry_go_proto",
"//server/backends/blobstore",
"//server/endpoint_urls/build_buddy_url",
"//server/environment",
"//server/nullauth",
Expand Down
7 changes: 3 additions & 4 deletions server/telemetry/telemetry_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"time"

"github.com/buildbuddy-io/buildbuddy/server/backends/blobstore"
"github.com/buildbuddy-io/buildbuddy/server/endpoint_urls/build_buddy_url"
"github.com/buildbuddy-io/buildbuddy/server/environment"
"github.com/buildbuddy-io/buildbuddy/server/nullauth"
Expand Down Expand Up @@ -139,9 +138,9 @@ func (t *TelemetryClient) logTelemetryData() {

func getInstallationUUID(env environment.Env) string {
ctx := env.GetServerContext()
store, err := blobstore.GetConfiguredBlobstore(env)
if err != nil {
log.Debugf("Error getting blobstore: %s", err)
store := env.GetBlobstore()
if store == nil {
log.Debugf("Missing blobstore in environment")
return unknownFieldValue
}

Expand Down
8 changes: 3 additions & 5 deletions server/testutil/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,12 @@ func GetTestEnv(t testing.TB) *real_environment.RealEnv {
flags.Set(t, "olap_database.data_source", testclickhouse.GetOrStart(t, *reuseServer))
err := clickhouse.Register(te)
if err != nil {
log.Fatalf("Error configuring ClickHouse: %s", err)
t.Fatalf("Error configuring ClickHouse: %s", err)
}
}
bs, err := blobstore.GetConfiguredBlobstore(te)
if err != nil {
log.Fatalf("Error configuring blobstore: %s", err)
if err := blobstore.Register(te); err != nil {
t.Fatalf("Error configuring blobstore: %s", err)
}
te.SetBlobstore(bs)
te.SetAuthenticator(&nullauth.NullAuthenticator{})
require.NoError(t, buildbuddy_server.Register(te))

Expand Down
2 changes: 1 addition & 1 deletion tools/replay_invocation/replay_invocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func main() {
return nil
})

bs, err := blobstore.GetConfiguredBlobstore(env)
bs, err := blobstore.NewFromConfig(ctx)
if err != nil {
log.Fatalf("Error configuring blobstore: %s", err.Error())
}
Expand Down

0 comments on commit 106e2ee

Please sign in to comment.