Skip to content

Commit

Permalink
Collect block storage type during setup (when started using run) (#1430)
Browse files Browse the repository at this point in the history
  • Loading branch information
itaiad200 authored Feb 9, 2021
1 parent 1998b8a commit a72168d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 41 deletions.
44 changes: 15 additions & 29 deletions api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/treeverse/lakefs/auth/model"
"github.com/treeverse/lakefs/block"
"github.com/treeverse/lakefs/catalog"
"github.com/treeverse/lakefs/cloud"
"github.com/treeverse/lakefs/db"
"github.com/treeverse/lakefs/graveler"
"github.com/treeverse/lakefs/httputil"
Expand All @@ -52,14 +53,15 @@ const (
)

type Dependencies struct {
ctx context.Context
Cataloger catalog.Cataloger
Auth auth.Service
BlockAdapter block.Adapter
MetadataManager auth.MetadataManager
Migrator db.Migrator
Collector stats.Collector
Logger logging.Logger
ctx context.Context
Cataloger catalog.Cataloger
Auth auth.Service
BlockAdapter block.Adapter
MetadataManager auth.MetadataManager
Migrator db.Migrator
Collector stats.Collector
CloudMetadataProvider cloud.MetadataProvider
Logger logging.Logger
}

func (d *Dependencies) WithContext(ctx context.Context) *Dependencies {
Expand Down Expand Up @@ -239,14 +241,12 @@ func (c *Controller) SetupLakeFSHandler() setupop.SetupLakeFSHandler {
return setupop.NewSetupLakeFSDefault(http.StatusInternalServerError).
WithPayload(&models.Error{Message: err.Error()})
}
metadata, err := c.deps.MetadataManager.Write()
if err != nil {
c.deps.Logger.Error("failed to write metadata after setup")
} else {
c.deps.Collector.SetInstallationID(metadata[auth.InstallationIDKeyName])
c.deps.Collector.CollectMetadata(convertMetadata(metadata))
}

metadata := stats.NewMetadata(c.deps.Logger, c.deps.BlockAdapter.BlockstoreType(), c.deps.MetadataManager, c.deps.CloudMetadataProvider)
c.deps.Collector.SetInstallationID(metadata.InstallationID)
c.deps.Collector.CollectMetadata(metadata)
c.deps.Collector.CollectEvent("global", "init")

return setupop.NewSetupLakeFSOK().WithPayload(&models.CredentialsWithSecret{
AccessKeyID: cred.AccessKeyID,
AccessSecretKey: cred.AccessSecretKey,
Expand All @@ -255,20 +255,6 @@ func (c *Controller) SetupLakeFSHandler() setupop.SetupLakeFSHandler {
})
}

func convertMetadata(metadata map[string]string) *stats.Metadata {
res := &stats.Metadata{
InstallationID: metadata[auth.InstallationIDKeyName],
}

for k, v := range metadata {
res.Entries = append(res.Entries, stats.MetadataEntry{
Name: k,
Value: v,
})
}
return res
}

func (c *Controller) GetCurrentUserHandler() authop.GetCurrentUserHandler {
return authop.GetCurrentUserHandlerFunc(func(params authop.GetCurrentUserParams, user *models.User) middleware.Responder {
return authop.NewGetCurrentUserOK().WithPayload(&authop.GetCurrentUserOKBody{
Expand Down
15 changes: 15 additions & 0 deletions api/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/treeverse/lakefs/catalog"
"github.com/treeverse/lakefs/db"
"github.com/treeverse/lakefs/httputil"
"github.com/treeverse/lakefs/stats"
"github.com/treeverse/lakefs/testutil"
"github.com/treeverse/lakefs/upload"
)
Expand Down Expand Up @@ -1431,6 +1432,20 @@ func TestController_SetupLakeFSHandler(t *testing.T) {
if len(deps.collector.metadata[0].Entries) < 5 {
t.Fatalf("There should be at least 5 metadata entries: %s", deps.collector.metadata[0].Entries)
}

hasBlockStoreType := false
for _, ent := range deps.collector.metadata[0].Entries {
if ent.Name == stats.BlockstoreTypeKey {
hasBlockStoreType = true
if ent.Value == "" {
t.Fatalf("Blockstorage key exists but with empty value: %s", deps.collector.metadata[0].Entries)
}
break
}
}
if !hasBlockStoreType {
t.Fatalf("missing blockstorage key: %s", deps.collector.metadata[0].Entries)
}
})

if c.errorDefaultCode == 0 {
Expand Down
17 changes: 9 additions & 8 deletions cmd/lakefs/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var runCmd = &cobra.Command{
cfg.GetAuthCacheConfig())
authMetadataManager := auth.NewDBMetadataManager(config.Version, dbPool)
cloudMetadataProvider := stats.BuildMetadataProvider(logger, cfg)
metadata := stats.NewMetadata(logger, cfg, authMetadataManager, cloudMetadataProvider)
metadata := stats.NewMetadata(logger, cfg.GetBlockstoreType(), authMetadataManager, cloudMetadataProvider)
bufferedCollector := stats.NewBufferedCollector(metadata.InstallationID, cfg)

// send metadata
Expand All @@ -104,13 +104,14 @@ var runCmd = &cobra.Command{
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)

apiHandler := api.Serve(api.Dependencies{
Cataloger: cataloger,
Auth: authService,
BlockAdapter: blockStore,
MetadataManager: authMetadataManager,
Migrator: migrator,
Collector: bufferedCollector,
Logger: logger.WithField("service", "api_gateway"),
Cataloger: cataloger,
Auth: authService,
BlockAdapter: blockStore,
MetadataManager: authMetadataManager,
CloudMetadataProvider: cloudMetadataProvider,
Migrator: migrator,
Collector: bufferedCollector,
Logger: logger.WithField("service", "api_gateway"),
})

// init gateway server
Expand Down
2 changes: 1 addition & 1 deletion cmd/lakefs/cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var setupCmd = &cobra.Command{
cfg.GetAuthCacheConfig())
metadataManager := auth.NewDBMetadataManager(config.Version, dbPool)
cloudMetadataProvider := stats.BuildMetadataProvider(logging.Default(), cfg)
metadata := stats.NewMetadata(logging.Default(), cfg, metadataManager, cloudMetadataProvider)
metadata := stats.NewMetadata(logging.Default(), cfg.GetBlockstoreType(), metadataManager, cloudMetadataProvider)

credentials, err := auth.CreateInitialAdminUserWithKeys(authService, metadataManager, userName, &accessKeyID, &secretAccessKey)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/lakefs/cmd/superuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var superuserCmd = &cobra.Command{
cfg.GetAuthCacheConfig())
authMetadataManager := auth.NewDBMetadataManager(config.Version, dbPool)
metadataProvider := stats.BuildMetadataProvider(logging.Default(), cfg)
metadata := stats.NewMetadata(logging.Default(), cfg, authMetadataManager, metadataProvider)
metadata := stats.NewMetadata(logging.Default(), cfg.GetBlockstoreType(), authMetadataManager, metadataProvider)
credentials, err := auth.AddAdminUser(authService, &model.SuperuserConfiguration{
User: model.User{
CreatedAt: time.Now(),
Expand Down
3 changes: 1 addition & 2 deletions stats/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Metadata struct {
Entries []MetadataEntry `json:"entries"`
}

func NewMetadata(logger logging.Logger, c *config.Config, authMetadataManager auth.MetadataManager, cloudMetadataProvider cloud.MetadataProvider) *Metadata {
func NewMetadata(logger logging.Logger, blockstoreType string, authMetadataManager auth.MetadataManager, cloudMetadataProvider cloud.MetadataProvider) *Metadata {
res := &Metadata{}
authMetadata, err := authMetadataManager.Write()
if err != nil {
Expand All @@ -41,7 +41,6 @@ func NewMetadata(logger logging.Logger, c *config.Config, authMetadataManager au
res.Entries = append(res.Entries, MetadataEntry{Name: k, Value: v})
}
}
blockstoreType := c.GetBlockstoreType()
res.Entries = append(res.Entries, MetadataEntry{Name: BlockstoreTypeKey, Value: blockstoreType})
return res
}
Expand Down

0 comments on commit a72168d

Please sign in to comment.