Merge pull request #1726 from aluzzardi/telemetry-ensure

telemetry: ensure events are not dropped
This commit is contained in:
Andrea Luzzardi 2022-03-08 23:36:40 -08:00 committed by GitHub
commit d170ff29a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 21 deletions

View File

@ -19,15 +19,18 @@ func TrackCommand(ctx context.Context, cmd *cobra.Command, props ...*telemetry.P
Name: "command", Name: "command",
Value: commandName(cmd), Value: commandName(cmd),
}, },
{
// Hash the repository URL for privacy
Name: "git_repository_hash",
Value: hash(gitRepoURL(".")),
},
}, props...) }, props...)
projectDir, found := pkg.GetCueModParent() if repo := gitRepoURL("."); repo != "" {
if found { 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{ props = append(props, &telemetry.Property{
Name: "project_path_hash", Name: "project_path_hash",
Value: hash(projectDir), Value: hash(projectDir),

View File

@ -60,20 +60,22 @@ var doCmd = &cobra.Command{
if err != nil { if err != nil {
lg.Fatal().Err(err).Msg("failed to load plan") lg.Fatal().Err(err).Msg("failed to load plan")
} }
target := getTargetPath(args)
doneCh := common.TrackCommand(ctx, cmd, &telemetry.Property{ doneCh := common.TrackCommand(ctx, cmd, &telemetry.Property{
Name: "action", Name: "action",
Value: p.Action().Path.String(), Value: target.String(),
}) })
err = cl.Do(ctx, p.Context(), func(ctx context.Context, s solver.Solver) error { err = cl.Do(ctx, p.Context(), func(ctx context.Context, s solver.Solver) error {
return p.Do(ctx, getTargetPath(args), s) return p.Do(ctx, target, s)
}) })
<-doneCh
if err != nil { if err != nil {
lg.Fatal().Err(err).Msg("failed to execute plan") lg.Fatal().Err(err).Msg("failed to execute plan")
} }
<-doneCh
}, },
} }

View File

@ -36,13 +36,11 @@ var initCmd = &cobra.Command{
name := viper.GetString("name") name := viper.GetString("name")
doneCh := common.TrackCommand(ctx, cmd) doneCh := common.TrackCommand(ctx, cmd)
err := pkg.CueModInit(ctx, dir, name) err := pkg.CueModInit(ctx, dir, name)
<-doneCh
if err != nil { if err != nil {
lg.Fatal().Err(err).Msg("failed to initialize project") lg.Fatal().Err(err).Msg("failed to initialize project")
} }
<-doneCh
}, },
} }

View File

@ -7,7 +7,6 @@ import (
"go.dagger.io/dagger/cmd/dagger/logger" "go.dagger.io/dagger/cmd/dagger/logger"
"go.dagger.io/dagger/mod" "go.dagger.io/dagger/mod"
"go.dagger.io/dagger/pkg" "go.dagger.io/dagger/pkg"
"go.dagger.io/dagger/telemetry"
) )
var updateCmd = &cobra.Command{ var updateCmd = &cobra.Command{
@ -41,6 +40,7 @@ var updateCmd = &cobra.Command{
var update = viper.GetBool("update") var update = viper.GetBool("update")
doneCh := common.TrackCommand(ctx, cmd)
var processedRequires []*mod.Require var processedRequires []*mod.Require
if update && len(args) == 0 { if update && len(args) == 0 {
@ -62,16 +62,12 @@ var updateCmd = &cobra.Command{
} }
} }
doneCh := common.TrackCommand(ctx, cmd, &telemetry.Property{ <-doneCh
Name: "num_packages",
Value: len(processedRequires),
})
if err != nil { if err != nil {
lg.Error().Err(err).Msg("error installing/updating packages") lg.Error().Err(err).Msg("error installing/updating packages")
} }
<-doneCh
}, },
} }

View File

@ -61,15 +61,14 @@ var upCmd = &cobra.Command{
} }
doneCh := common.TrackCommand(ctx, cmd) doneCh := common.TrackCommand(ctx, cmd)
err = cl.Do(ctx, p.Context(), func(ctx context.Context, s solver.Solver) error { err = cl.Do(ctx, p.Context(), func(ctx context.Context, s solver.Solver) error {
return p.Do(ctx, cue.ParsePath(viper.GetString("target")), s) return p.Do(ctx, cue.ParsePath(viper.GetString("target")), s)
}) })
<-doneCh
if err != nil { if err != nil {
lg.Fatal().Err(err).Msg("failed to up environment") lg.Fatal().Err(err).Msg("failed to up environment")
} }
<-doneCh
}, },
} }

View File

@ -4,8 +4,10 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors"
"net/http" "net/http"
"os" "os"
"path/filepath"
"runtime" "runtime"
"time" "time"
@ -147,6 +149,14 @@ func getDeviceID() (string, error) {
} }
id, err := os.ReadFile(idFile) id, err := os.ReadFile(idFile)
if err != nil { if err != nil {
if !errors.Is(err, os.ErrNotExist) {
return "", err
}
if err := os.MkdirAll(filepath.Dir(idFile), 0755); err != nil {
return "", err
}
id = []byte(uuid.New().String()) id = []byte(uuid.New().String())
if err := os.WriteFile(idFile, id, 0600); err != nil { if err := os.WriteFile(idFile, id, 0600); err != nil {
return "", err return "", err