Skip to content

Commit

Permalink
fix(telemetry): repair turn-off telemetry switch
Browse files Browse the repository at this point in the history
Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Sep 7, 2022
1 parent b8efbbd commit f8559e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
15 changes: 11 additions & 4 deletions pkg/telemetry/telemetry.go
Expand Up @@ -13,7 +13,8 @@ import (
)

const (
TracesURL = "https://telemetry.werf.io/v1/traces"
TracesURL = "https://telemetry.werf.io/v1/traces"
TelemetryEnv = "WERF_TELEMETRY"
)

var (
Expand Down Expand Up @@ -94,9 +95,15 @@ func GetTraceUrl() string {
}

func IsEnabled() bool {
isDevVersion := werf.Version == "dev" || werf.Version == "0.0.0"
envVal := util.GetBoolEnvironmentDefaultFalse("WERF_TELEMETRY")
return envVal || !isDevVersion
val, isSet := util.LookupBoolEnvironment(TelemetryEnv)
if isSet && val != nil {
return *val
}

if werf.Version == "dev" || werf.Version == "0.0.0" {
return false
}
return true
}

func LogF(f string, args ...interface{}) {
Expand Down
19 changes: 14 additions & 5 deletions pkg/util/env.go
Expand Up @@ -8,17 +8,26 @@ import (
"strings"
)

func GetBoolEnvironment(environmentName string) *bool {
switch os.Getenv(environmentName) {
func LookupBoolEnvironment(environmentName string) (*bool, bool) {
value, isSet := os.LookupEnv(environmentName)
if !isSet {
return nil, false
}

switch value {
case "1", "true", "yes":
t := true
return &t
return &t, true
case "0", "false", "no":
f := false
return &f
return &f, true
}
return nil, true
}

return nil
func GetBoolEnvironment(environmentName string) *bool {
val, _ := LookupBoolEnvironment(environmentName)
return val
}

func GetBoolEnvironmentDefaultFalse(environmentName string) bool {
Expand Down

0 comments on commit f8559e9

Please sign in to comment.