Skip to content

Commit

Permalink
chore: update flag name, update logic (#141)
Browse files Browse the repository at this point in the history
Signed-off-by: João Vanzuita <joao@kubeshop.io>
  • Loading branch information
João Paulo Vanzuita authored Jul 20, 2022
1 parent 7ef6272 commit e947e50
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 41 deletions.
19 changes: 12 additions & 7 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,24 @@ to quickly create a Cobra application.`,
if err != nil {
log.Panic(err)
}
disableTelemetry, err := cmd.Flags().GetBool("disable-telemetry")

useTelemetry, err := cmd.Flags().GetBool("use-telemetry")
if err != nil {
log.Panic(err)
}


if !useTelemetry {
log.Println("telemetry is disabled")
return
}

infoCmd.Run(cmd, args)
progressPrinter.IncrementTracker("step-0", 1)

progressPrinter.AddTracker("step-softserve", "Prepare Temporary Repo ", 4)
sendStartedInstallTelemetry(dryRun, disableTelemetry)
sendStartedInstallTelemetry(dryRun, useTelemetry)
progressPrinter.IncrementTracker("step-softserve", 1)
if(disableTelemetry){
if useTelemetry {
informUser("Telemetry Disabled")
}
directory := fmt.Sprintf("%s/gitops/terraform/base", config.K1FolderPath)
Expand Down Expand Up @@ -352,7 +357,7 @@ to quickly create a Cobra application.`,
viper.WriteConfig()
}

sendCompleteInstallTelemetry(dryRun,disableTelemetry)
sendCompleteInstallTelemetry(dryRun, useTelemetry)
time.Sleep(time.Millisecond * 100)

// prepare data for the handoff report
Expand Down Expand Up @@ -400,8 +405,8 @@ func init() {
createCmd.Flags().Bool("destroy", false, "destroy resources")
createCmd.Flags().Bool("dry-run", false, "set to dry-run mode, no changes done on cloud provider selected")
createCmd.Flags().Bool("skip-gitlab", false, "Skip GitLab lab install and vault setup")
createCmd.Flags().Bool("skip-vault", false, "Skip post-gitClient lab install and vault setup")
createCmd.Flags().Bool("disable-telemetry", false, "Installer will not send telemetry about this installation")
createCmd.Flags().Bool("skip-vault", false, "Skip post-gitClient lab install and vault setup")
createCmd.Flags().Bool("use-telemetry", true, "installer will not send telemetry about this installation")

progressPrinter.GetInstance()
progressPrinter.SetupProgress(4)
Expand Down
8 changes: 4 additions & 4 deletions cmd/createUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ func setArgocdCreds(dryRun bool) {
viper.WriteConfig()
}

func sendStartedInstallTelemetry(dryRun bool, disableTelemetry bool) {
func sendStartedInstallTelemetry(dryRun bool, useTelemetry bool) {
metricName := "kubefirst.mgmt_cluster_install.started"
if !dryRun {
telemetry.SendTelemetry(disableTelemetry, viper.GetString("aws.hostedzonename"), metricName)
telemetry.SendTelemetry(useTelemetry, viper.GetString("aws.hostedzonename"), metricName)
} else {
log.Printf("[#99] Dry-run mode, telemetry skipped: %s", metricName)
}
}

func sendCompleteInstallTelemetry(dryRun bool, disableTelemetry bool) {
func sendCompleteInstallTelemetry(dryRun bool, useTelemetry bool) {
metricName := "kubefirst.mgmt_cluster_install.completed"
if !dryRun {
telemetry.SendTelemetry(disableTelemetry, viper.GetString("aws.hostedzonename"), metricName)
telemetry.SendTelemetry(useTelemetry, viper.GetString("aws.hostedzonename"), metricName)
} else {
log.Printf("[#99] Dry-run mode, telemetry skipped: %s", metricName)
}
Expand Down
14 changes: 8 additions & 6 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ to quickly create a Cobra application.`,
log.Panic(err)
}

disableTelemetry, err := cmd.Flags().GetBool("disable-telemetry")
useTelemetry, err := cmd.Flags().GetBool("use-telemetry")
if err != nil {
log.Panic(err)
}
if(disableTelemetry){
log.Println("Telemetry Disabled")

if !useTelemetry {
log.Println("telemetry is disabled")
return
}

log.Println("dry run enabled:", dryRun)
Expand All @@ -61,7 +63,7 @@ to quickly create a Cobra application.`,
metricDomain := hostedZoneName

if !dryRun {
telemetry.SendTelemetry(disableTelemetry, metricDomain, metricName)
telemetry.SendTelemetry(useTelemetry, metricDomain, metricName)
} else {
log.Printf("[#99] Dry-run mode, telemetry skipped: %s", metricName)
}
Expand Down Expand Up @@ -183,7 +185,7 @@ to quickly create a Cobra application.`,
metricName = "kubefirst.init.completed"

if !dryRun {
telemetry.SendTelemetry(disableTelemetry, metricDomain, metricName)
telemetry.SendTelemetry(useTelemetry, metricDomain, metricName)
} else {
log.Printf("[#99] Dry-run mode, telemetry skipped: %s", metricName)
}
Expand Down Expand Up @@ -229,5 +231,5 @@ func init() {

initCmd.Flags().String("cluster-name", "kubefirst", "the cluster name, used to identify resources on cloud provider")
initCmd.Flags().String("version-gitops", "main", "version/branch used on git clone")
initCmd.Flags().Bool("disable-telemetry", false, "Installer will not send telemetry about this installation")
initCmd.Flags().Bool("use-telemetry", true, "installer will not send telemetry about this installation")
}
50 changes: 26 additions & 24 deletions internal/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,39 @@ import (
)

// SendTelemetry post telemetry data
func SendTelemetry(disableTelemetry bool, domain string, metricName string) {
if !disableTelemetry {
log.Println("SendTelemetry (working...)")
func SendTelemetry(useTelemetry bool, domain string, metricName string) {

url := "https://metaphor-go-production.kubefirst.io/telemetry"
method := "POST"
if !useTelemetry {
log.Println("Telemetry disable by user choice, nothing was sent")
return
}

payload := strings.NewReader(fmt.Sprintf(`{"domain": "%s","name": "%s"}`, domain, metricName))
log.Println("SendTelemetry (working...)")

client := &http.Client{}
req, err := http.NewRequest(method, url, payload)
url := "https://metaphor-go-production.kubefirst.io/telemetry"
method := "POST"

if err != nil {
log.Println(err)
}
payload := strings.NewReader(fmt.Sprintf(`{"domain": "%s","name": "%s"}`, domain, metricName))

req.Header.Add("Content-Type", "application/json")
// TODO need to add authentication or a header of some sort?
// req.Header.Add("auth?", os.Getenv("K1_KEY"))
client := &http.Client{}
req, err := http.NewRequest(method, url, payload)

res, err := client.Do(req)
if err != nil {
log.Println("error")
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Println(err)
}

log.Println(string(body))
req.Header.Add("Content-Type", "application/json")
// TODO need to add authentication or a header of some sort?
// req.Header.Add("auth?", os.Getenv("K1_KEY"))

log.Println("SendTelemetry (done)")
} else {
log.Println("Telemetry disable by user choice, nothing was sent")
res, err := client.Do(req)
if err != nil {
log.Println("error")
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)

log.Println(string(body))

log.Println("SendTelemetry (done)")
}

0 comments on commit e947e50

Please sign in to comment.