From c17ce973810765026639e4af8eccd96617cd53b0 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Tue, 8 Mar 2022 23:04:58 -0800 Subject: [PATCH] telemetry: ensure events are not dropped - Move chan sync code immediately after operation - Fix git hashing when not in a git repo Signed-off-by: Andrea Luzzardi --- cmd/dagger/cmd/common/track.go | 17 ++++++++++------- cmd/dagger/cmd/do.go | 3 ++- cmd/dagger/cmd/project/init.go | 4 +--- cmd/dagger/cmd/project/update.go | 8 ++------ cmd/dagger/cmd/up.go | 3 +-- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/cmd/dagger/cmd/common/track.go b/cmd/dagger/cmd/common/track.go index ed0395eb..d57d034c 100644 --- a/cmd/dagger/cmd/common/track.go +++ b/cmd/dagger/cmd/common/track.go @@ -19,15 +19,18 @@ func TrackCommand(ctx context.Context, cmd *cobra.Command, props ...*telemetry.P Name: "command", Value: commandName(cmd), }, - { - // Hash the repository URL for privacy - Name: "git_repository_hash", - Value: hash(gitRepoURL(".")), - }, }, props...) - projectDir, found := pkg.GetCueModParent() - if found { + if repo := gitRepoURL("."); repo != "" { + props = append(props, &telemetry.Property{ + // Hash the repository URL for privacy + Name: "git_repository_hash", + Value: hash(repo), + }) + } + + if projectDir, found := pkg.GetCueModParent(); found { + // Hash the project path for privacy props = append(props, &telemetry.Property{ Name: "project_path_hash", Value: hash(projectDir), diff --git a/cmd/dagger/cmd/do.go b/cmd/dagger/cmd/do.go index d3922b66..8194c10d 100644 --- a/cmd/dagger/cmd/do.go +++ b/cmd/dagger/cmd/do.go @@ -70,10 +70,11 @@ var doCmd = &cobra.Command{ return p.Do(ctx, getTargetPath(args), s) }) + <-doneCh + if err != nil { lg.Fatal().Err(err).Msg("failed to execute plan") } - <-doneCh }, } diff --git a/cmd/dagger/cmd/project/init.go b/cmd/dagger/cmd/project/init.go index dabae3d4..86ff36b5 100644 --- a/cmd/dagger/cmd/project/init.go +++ b/cmd/dagger/cmd/project/init.go @@ -36,13 +36,11 @@ var initCmd = &cobra.Command{ name := viper.GetString("name") doneCh := common.TrackCommand(ctx, cmd) - err := pkg.CueModInit(ctx, dir, name) + <-doneCh if err != nil { lg.Fatal().Err(err).Msg("failed to initialize project") } - - <-doneCh }, } diff --git a/cmd/dagger/cmd/project/update.go b/cmd/dagger/cmd/project/update.go index 45d40141..a8cf39e3 100644 --- a/cmd/dagger/cmd/project/update.go +++ b/cmd/dagger/cmd/project/update.go @@ -7,7 +7,6 @@ import ( "go.dagger.io/dagger/cmd/dagger/logger" "go.dagger.io/dagger/mod" "go.dagger.io/dagger/pkg" - "go.dagger.io/dagger/telemetry" ) var updateCmd = &cobra.Command{ @@ -41,6 +40,7 @@ var updateCmd = &cobra.Command{ var update = viper.GetBool("update") + doneCh := common.TrackCommand(ctx, cmd) var processedRequires []*mod.Require if update && len(args) == 0 { @@ -62,16 +62,12 @@ var updateCmd = &cobra.Command{ } } - doneCh := common.TrackCommand(ctx, cmd, &telemetry.Property{ - Name: "num_packages", - Value: len(processedRequires), - }) + <-doneCh if err != nil { lg.Error().Err(err).Msg("error installing/updating packages") } - <-doneCh }, } diff --git a/cmd/dagger/cmd/up.go b/cmd/dagger/cmd/up.go index b2288c58..8073380e 100644 --- a/cmd/dagger/cmd/up.go +++ b/cmd/dagger/cmd/up.go @@ -61,15 +61,14 @@ var upCmd = &cobra.Command{ } doneCh := common.TrackCommand(ctx, cmd) - err = cl.Do(ctx, p.Context(), func(ctx context.Context, s solver.Solver) error { return p.Do(ctx, cue.ParsePath(viper.GetString("target")), s) }) + <-doneCh if err != nil { lg.Fatal().Err(err).Msg("failed to up environment") } - <-doneCh }, }