cmd: add prompt for enabling tracing during uplink cli setup
We want to make tracing to be opt-in. For now, we will use `tracing.sample` as the toggle config to enable or disable tracing and default to sample every traces from uplink cli. If user wants to change the default sampling rate, they can do so by using the `--tracing.sample` flag to override the default value Change-Id: I6f25dac0f43024c50a8aaf6c549e6a514211f834
This commit is contained in:
parent
805e328c47
commit
0b8699bcb5
@ -166,3 +166,31 @@ func PromptForEncryptionPassphrase() (string, error) {
|
||||
|
||||
return string(encKey), nil
|
||||
}
|
||||
|
||||
// PromptForTracing handles user input for consent to turn on tracing to be used with wizards.
|
||||
func PromptForTracing() (bool, error) {
|
||||
_, err := fmt.Printf(`
|
||||
With your permission, Tardigrade can automatically collect analytics information from your uplink CLI and send it to Storj Labs (makers of Tardigrade) to help improve the quality and performance of our products. This information is sent only with your consent and is submitted anonymously to Storj Labs: (y/n)
|
||||
`)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
var userConsent string
|
||||
n, err := fmt.Scanln(&userConsent)
|
||||
if err != nil {
|
||||
if n != 0 {
|
||||
return false, err
|
||||
}
|
||||
// fmt.Scanln cannot handle empty input
|
||||
userConsent = "n"
|
||||
}
|
||||
|
||||
switch userConsent {
|
||||
case "y", "yes", "Y", "Yes":
|
||||
return true, nil
|
||||
default:
|
||||
return false, nil
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,3 +25,7 @@ func withTelemetry(cmd *cobra.Command) (context.Context, context.CancelFunc) {
|
||||
ctx, _ := process.Ctx(cmd)
|
||||
return telemetry.Enable(ctx)
|
||||
}
|
||||
|
||||
func enableTracing(config map[string]interface{}) {
|
||||
config["tracing.sample"] = 1
|
||||
}
|
||||
|
@ -115,13 +115,23 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
return Error.Wrap(err)
|
||||
}
|
||||
|
||||
overrides := make(map[string]interface{})
|
||||
tracingEnabled, err := wizard.PromptForTracing()
|
||||
if err != nil {
|
||||
return Error.Wrap(err)
|
||||
}
|
||||
if tracingEnabled {
|
||||
enableTracing(overrides)
|
||||
}
|
||||
|
||||
// NB: accesses should always be `map[string]interface{}` for "conventional"
|
||||
// config serialization/flattening.
|
||||
accesses := toStringMapE(setupCfg.Accesses)
|
||||
accesses[accessName] = accessData
|
||||
overrides["accesses"] = accesses
|
||||
|
||||
saveCfgOpts := []process.SaveConfigOption{
|
||||
process.SaveConfigWithOverride("accesses", accesses),
|
||||
process.SaveConfigWithOverrides(overrides),
|
||||
process.SaveConfigRemovingDeprecated(),
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user