introduce ODO_DISABLE_TELEMETRY and skip telemetry question when there is no tty (#4580)

* introduce ODO_DISABLE_TELEMETRY env variable

* skip telemetry question if there is no terminal

* make sure that e2e and integrations test use ODO_DISABLE_TELEMETRY

* Update USAGE_DATA.adoc

Co-authored-by: Dharmit Shah <shahdharmit@gmail.com>

* add info about ODO_DISABLE_TELEMETRY overriding preference

* get env variable only once

Co-authored-by: Dharmit Shah <shahdharmit@gmail.com>
This commit is contained in:
Tomas Kral
2021-04-06 14:13:48 +02:00
committed by GitHub
parent 5199886e42
commit ba7161940c
14 changed files with 63 additions and 65 deletions

View File

@@ -27,3 +27,6 @@ Disable::
`odo preference set ConsentTelemetry false`
Note: If earlier the `ConsentTelemetry` preference was enabled, then the data will be collected about the disabling of the preference.
Alternatively you can disable telemetry by setting `ODO_DISABLE_TELEMETRY` environment variable to `true`.
This environment can override `ConsentTelemetry` value set by `odo preference`.

View File

@@ -24,6 +24,10 @@ var (
segmentClient *segment.Client
)
// disableTelemetryEnv is name of environment variable, if set to true it disables odo telemetry completely
// hiding even the question
const disableTelemetryEnv = "ODO_DISABLE_TELEMETRY"
type Runnable interface {
Complete(name string, cmd *cobra.Command, args []string) error
Validate() error
@@ -34,29 +38,40 @@ func GenericRun(o Runnable, cmd *cobra.Command, args []string) {
var err error
var startTime time.Time
cfg, _ := preference.New()
disableTelemetry := os.Getenv(disableTelemetryEnv)
// Prompt the user to consent for telemetry if a value is not set already
// Skip prompting if the preference command is called
// This prompt has been placed here so that it does not prompt the user when they call --help
if !cfg.IsSet(preference.ConsentTelemetrySetting) && cmd.Parent().Name() != "preference" {
var consentTelemetry bool
prompt := &survey.Confirm{Message: "Help odo improve by allowing it to collect usage data. Read about our privacy statement: https://developers.redhat.com/article/tool-data-collection. You can change your preference later by changing the ConsentTelemetry preference.", Default: false}
err = survey.AskOne(prompt, &consentTelemetry, nil)
ui.HandleError(err)
if err == nil {
if err1 := cfg.SetConfiguration(preference.ConsentTelemetrySetting, strconv.FormatBool(consentTelemetry)); err1 != nil {
klog.V(4).Info(err1.Error())
if !segment.RunningInTerminal() {
klog.V(4).Infof("Skipping telemetry question because there is no terminal (tty)\n")
} else if disableTelemetry == "true" {
klog.V(4).Infof("Skipping telemetry question due to %s=%s\n", disableTelemetryEnv, disableTelemetry)
} else {
var consentTelemetry bool
prompt := &survey.Confirm{Message: "Help odo improve by allowing it to collect usage data. Read about our privacy statement: https://developers.redhat.com/article/tool-data-collection. You can change your preference later by changing the ConsentTelemetry preference.", Default: false}
err = survey.AskOne(prompt, &consentTelemetry, nil)
ui.HandleError(err)
if err == nil {
if err1 := cfg.SetConfiguration(preference.ConsentTelemetrySetting, strconv.FormatBool(consentTelemetry)); err1 != nil {
klog.V(4).Info(err1.Error())
}
}
}
}
// Initiate the segment client if ConsentTelemetry preference is set to true
if cfg.GetConsentTelemetry() {
if segmentClient, err = segment.NewClient(cfg); err != nil {
klog.V(4).Infof("Cannot create a segment client, will not send any data: %s", err.Error())
if disableTelemetry == "true" {
log.Warningf("Sending telemetry disabled by %s=%s\n", disableTelemetryEnv, disableTelemetry)
} else {
if segmentClient, err = segment.NewClient(cfg); err != nil {
klog.V(4).Infof("Cannot create a segment client, will not send any data: %s", err.Error())
}
defer segmentClient.Close()
startTime = time.Now()
}
defer segmentClient.Close()
startTime = time.Now()
}
// CheckMachineReadableOutput
@@ -75,7 +90,9 @@ func GenericRun(o Runnable, cmd *cobra.Command, args []string) {
if err != nil {
uploadToSegmentAndLog(cmd, err, startTime)
}
uploadToSegmentAndLog(cmd, o.Run(), startTime)
err = o.Run()
uploadToSegmentAndLog(cmd, err, startTime)
}
// uploadToSegmentAndLog uploads the data to segment and logs the error

View File

@@ -3,12 +3,9 @@ package e2escenarios
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper/reporter"
"github.com/openshift/odo/tests/helper"
)
func TestE2eScenarios(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "odo e2e scenarios", []Reporter{reporter.JunitReport(t, "../../reports")})
helper.RunTestSpecs(t, "odo e2e scenarios")
}

View File

@@ -11,9 +11,11 @@ import (
"path/filepath"
"strconv"
"strings"
"testing"
"time"
"github.com/openshift/odo/pkg/preference"
"github.com/openshift/odo/tests/helper/reporter"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -342,3 +344,10 @@ func SetProjectName() string {
projectName := currGinkgoTestFileName + currGinkgoTestLineNum + RandString(3)
return projectName
}
// RunTestSpecs defines a common way how test specs in test suite are executed
func RunTestSpecs(t *testing.T, description string) {
os.Setenv("ODO_DISABLE_TELEMETRY", "true")
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, description, []Reporter{reporter.JunitReport(t, "../../reports/")})
}

View File

@@ -360,10 +360,6 @@ var _ = Describe("odo preference and config command tests", func() {
output = helper.CmdShouldPass("odo", "preference", "unset", "buildtimeout", "-f")
Expect(output).ToNot(ContainSubstring(promtMessageSubString))
})
It("prompt should appear when non-preference command is run", func() {
output := helper.CmdShouldPass("odo", "create", "nodejs", "--context", commonVar.Context)
Expect(output).To(ContainSubstring(promtMessageSubString))
})
})
Context("Prompt should not appear when", func() {

View File

@@ -3,12 +3,9 @@ package debug
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper/reporter"
"github.com/openshift/odo/tests/helper"
)
func TestDebug(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Debug Suite", []Reporter{reporter.JunitReport(t, "../../../reports")})
helper.RunTestSpecs(t, "Debug Suite")
}

View File

@@ -3,12 +3,9 @@ package debug
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper/reporter"
"github.com/openshift/odo/tests/helper"
)
func TestDebug(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Project Suite", []Reporter{reporter.JunitReport(t, "../../../reports")})
helper.RunTestSpecs(t, "Project Suite")
}

View File

@@ -3,12 +3,9 @@ package devfile
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper/reporter"
"github.com/openshift/odo/tests/helper"
)
func TestDevfiles(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Project Suite", []Reporter{reporter.JunitReport(t, "../../../reports")})
helper.RunTestSpecs(t, "Devfile Suite")
}

View File

@@ -5,12 +5,9 @@ package integration
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper/reporter"
"github.com/openshift/odo/tests/helper"
)
func TestIntegration(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Integration Suite", []Reporter{reporter.JunitReport(t, "../../reports/")})
helper.RunTestSpecs(t, "Integration Suite")
}

View File

@@ -3,12 +3,9 @@ package integration
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper/reporter"
"github.com/openshift/odo/tests/helper"
)
func TestLoginlogout(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Loginlogout Suite", []Reporter{reporter.JunitReport(t, "../../../reports")})
helper.RunTestSpecs(t, "Login Logout Suite")
}

View File

@@ -3,11 +3,9 @@ package integration_test
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper"
)
func TestOperatorhub(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Operatorhub Suite")
helper.RunTestSpecs(t, "Operatorhub Suite")
}

View File

@@ -3,12 +3,9 @@ package project
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper/reporter"
"github.com/openshift/odo/tests/helper"
)
func TestProject(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Project Suite", []Reporter{reporter.JunitReport(t, "../../../reports")})
helper.RunTestSpecs(t, "Project Suite")
}

View File

@@ -3,12 +3,9 @@ package integration
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper/reporter"
"github.com/openshift/odo/tests/helper"
)
func TestServicecatalog(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t, "Servicecatalog Suite", []Reporter{reporter.JunitReport(t, "../../../reports")})
helper.RunTestSpecs(t, "Servicecatalog Suite")
}

View File

@@ -3,11 +3,10 @@ package template
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/odo/tests/helper"
)
func TestTemplate(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "TestTemplate Suite")
helper.RunTestSpecs(t, "TestTemplate Suite")
}