Skip to content

Commit

Permalink
add installation id after init (#983)
Browse files Browse the repository at this point in the history
* add installation id after init

* revert version change

* revert metadata.go

* revert collect metadata change

* revert installation id method

* fix tests

* fix lint
  • Loading branch information
johnnyaug committed Dec 1, 2020
1 parent 4f89db9 commit c152e2c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions api/api_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ func (c *Controller) SetupLakeFSHandler() setupop.SetupLakeFSHandler {
})
}

c.deps.Collector.CollectEvent("global", "init")

username := swag.StringValue(setupReq.User.Username)
var cred *model.Credential
if setupReq.User.Key == nil {
Expand All @@ -276,7 +274,13 @@ 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.CollectEvent("global", "init")
return setupop.NewSetupLakeFSOK().WithPayload(&models.CredentialsWithSecret{
AccessKeyID: cred.AccessKeyID,
AccessSecretKey: cred.AccessSecretKey,
Expand Down
2 changes: 2 additions & 0 deletions api/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func (m *mockCollector) CollectMetadata(_ *stats.Metadata) {}

func (m *mockCollector) CollectEvent(_, _ string) {}

func (m *mockCollector) SetInstallationID(_ string) {}

func getHandler(t *testing.T, blockstoreType string, opts ...testutil.GetDBOption) (http.Handler, *dependencies) {
conn, handlerDatabaseURI := testutil.GetDB(t, databaseURI, opts...)
var blockAdapter block.Adapter
Expand Down
2 changes: 2 additions & 0 deletions gateway/playback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func (m *mockCollector) CollectMetadata(accountMetadata *stats.Metadata) {}

func (m *mockCollector) CollectEvent(class, action string) {}

func (m *mockCollector) SetInstallationID(_ string) {}

func getBasicHandlerPlayback(t *testing.T) (http.Handler, *dependencies) {
authService := newGatewayAuthFromFile(t, simulator.PlaybackParams.RecordingDir)
return getBasicHandler(t, authService)
Expand Down
2 changes: 2 additions & 0 deletions loadtest/local_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func (m *mockCollector) CollectMetadata(_ *stats.Metadata) {}

func (m *mockCollector) CollectEvent(_, _ string) {}

func (m *mockCollector) SetInstallationID(_ string) {}

func TestLocalLoad(t *testing.T) {
if testing.Short() {
t.Skip("Skipping loadtest tests in short mode")
Expand Down
5 changes: 5 additions & 0 deletions stats/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
type Collector interface {
CollectEvent(class, action string)
CollectMetadata(accountMetadata *Metadata)
SetInstallationID(installationID string)
}

type Metric struct {
Expand Down Expand Up @@ -218,6 +219,10 @@ func (s *BufferedCollector) collectHeartbeat(ctx context.Context) {
}
}

func (s *BufferedCollector) SetInstallationID(installationID string) {
s.installationID = installationID
}

func getBufferedCollectorArgs(c *config.Config) (processID string, opts []BufferedCollectorOpts) {
if c == nil {
return "", nil
Expand Down

0 comments on commit c152e2c

Please sign in to comment.