forked from pingcap/tiup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
telemetry.go
101 lines (86 loc) · 2.16 KB
/
telemetry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package cmd
import (
"fmt"
"github.com/pingcap/tiup/pkg/environment"
"github.com/pingcap/tiup/pkg/telemetry"
"github.com/spf13/cobra"
)
func newTelemetryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "telemetry",
Short: "Controls things about telemetry",
}
cmd.AddCommand(&cobra.Command{
Use: "reset",
Short: "Reset the uuid used for telemetry",
RunE: func(cmd *cobra.Command, args []string) error {
teleCommand = cmd.CommandPath()
env := environment.GlobalEnv()
teleMeta, fname, err := telemetry.GetMeta(env)
if err != nil {
return err
}
teleMeta.UUID = telemetry.NewUUID()
err = teleMeta.SaveTo(fname)
if err != nil {
return err
}
fmt.Printf("Reset uuid as: %s success\n", teleMeta.UUID)
return nil
},
})
cmd.AddCommand(&cobra.Command{
Use: "enable",
Short: "Enable telemetry of tiup",
RunE: func(cmd *cobra.Command, args []string) error {
teleCommand = cmd.CommandPath()
env := environment.GlobalEnv()
teleMeta, fname, err := telemetry.GetMeta(env)
if err != nil {
return err
}
teleMeta.Status = telemetry.EnableStatus
err = teleMeta.SaveTo(fname)
if err != nil {
return err
}
fmt.Printf("Enable telemetry success\n")
return nil
},
})
cmd.AddCommand(&cobra.Command{
Use: "disable",
Short: "Disable telemetry of tiup",
RunE: func(cmd *cobra.Command, args []string) error {
teleCommand = cmd.CommandPath()
env := environment.GlobalEnv()
teleMeta, fname, err := telemetry.GetMeta(env)
if err != nil {
return err
}
teleMeta.Status = telemetry.DisableStatus
err = teleMeta.SaveTo(fname)
if err != nil {
return err
}
fmt.Printf("Disable telemetry success\n")
return nil
},
})
cmd.AddCommand(&cobra.Command{
Use: "status",
Short: "Display the current status of tiup telemetry",
RunE: func(cmd *cobra.Command, args []string) error {
teleCommand = cmd.CommandPath()
env := environment.GlobalEnv()
teleMeta, _, err := telemetry.GetMeta(env)
if err != nil {
return err
}
fmt.Printf("status: %s\n", teleMeta.Status)
fmt.Printf("uuid: %s\n", teleMeta.UUID)
return nil
},
})
return cmd
}