Skip to content

Commit

Permalink
telemetry: disable telemetry on server daemon command (#1374)
Browse files Browse the repository at this point in the history
Signed-off-by: Toma Puljak <[email protected]>
  • Loading branch information
Tpuljak authored Nov 26, 2024
1 parent 6b2b52d commit 2966736
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 4 additions & 5 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func Execute() error {
rootCmd.AddCommand(DeleteCmd)
rootCmd.AddCommand(ProjectConfigCmd)
rootCmd.AddCommand(ServeCmd)
rootCmd.AddCommand(DaemonServeCmd)
rootCmd.AddCommand(ServerCmd)
rootCmd.AddCommand(ApiKeyCmd)
rootCmd.AddCommand(ContainerRegistryCmd)
Expand Down Expand Up @@ -237,10 +238,8 @@ func PreRun(rootCmd *cobra.Command, args []string, telemetryEnabled bool, client

cmd, flags, isCompletion, err := validateCommands(rootCmd, os.Args[1:])
if err != nil && !isCompletion {
if telemetryEnabled {
if telemetryEnabled && !strings.HasSuffix(cmd.CommandPath(), "daemon-serve") {
props := GetCmdTelemetryData(cmd, flags)
props["command"] = os.Args[1]
props["called_as"] = os.Args[1]
err := telemetryService.TrackCliEvent(telemetry.CliEventInvalidCmd, clientId, props)
if err != nil {
log.Trace(err)
Expand All @@ -251,7 +250,7 @@ func PreRun(rootCmd *cobra.Command, args []string, telemetryEnabled bool, client
return telemetryService, cmd, flags, isCompletion, err
}

if telemetryEnabled && !isCompletion {
if telemetryEnabled && !strings.HasSuffix(cmd.CommandPath(), "daemon-serve") && !isCompletion {
err := telemetryService.TrackCliEvent(telemetry.CliEventCmdStart, clientId, GetCmdTelemetryData(cmd, flags))
if err != nil {
log.Trace(err)
Expand Down Expand Up @@ -282,7 +281,7 @@ func PreRun(rootCmd *cobra.Command, args []string, telemetryEnabled bool, client
}

func PostRun(cmd *cobra.Command, cmdErr error, telemetryService telemetry.TelemetryService, clientId string, startTime time.Time, endTime time.Time, flags []string) {
if telemetryService != nil {
if telemetryService != nil && !strings.HasSuffix(cmd.CommandPath(), "daemon-serve") {
execTime := endTime.Sub(startTime)
props := GetCmdTelemetryData(cmd, flags)
props["exec time (µs)"] = execTime.Microseconds()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/server/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func getServiceConfig() (*service.Config, error) {
Name: serviceName,
DisplayName: "Daytona Server",
Description: "Daytona Server daemon.",
Arguments: []string{"serve"},
Arguments: []string{"daemon-serve"},
}

switch runtime.GOOS {
Expand Down
8 changes: 8 additions & 0 deletions pkg/cmd/server/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ import (
"github.com/spf13/cobra"
)

var DaemonServeCmd = &cobra.Command{
Use: "daemon-serve",
Short: "Used by the daemon to start the Daytona Server",
Args: cobra.NoArgs,
Hidden: true,
RunE: ServeCmd.RunE,
}

var ServeCmd = &cobra.Command{
Use: "serve",
Short: "Run the server process in the current terminal session",
Expand Down

0 comments on commit 2966736

Please sign in to comment.