Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into lporoli/fix-mergerclustertopologies
Browse files Browse the repository at this point in the history
  • Loading branch information
leoporoli authored Aug 26, 2024
2 parents c16ce0c + d1df468 commit d597fa7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
11 changes: 4 additions & 7 deletions kontrol-service/api/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ const (
)

// NewAnalyticsWrapper creates a new AnalyticsWrapper
func NewAnalyticsWrapper(isDevMode bool) *AnalyticsWrapper {
if !isDevMode {
// This is the Segment write key for the "kontrol-service" project. It is not
// a sensitive value, but it could be extracted to an env var in the future
// to separate dev and prod traffic if desired.
client := analytics.New("1TeZVRY3ta9VYaNknKTCCKBZtcBllE6U")
func NewAnalyticsWrapper(isDevMode bool, writeKey string) *AnalyticsWrapper {
if !isDevMode && writeKey != "" {
client := analytics.New(writeKey)
logrus.Info("Segment analytics client initialized")
return &AnalyticsWrapper{client: &client}
}
logrus.Info("Dev mode: Segment analytics client not initialized")
logrus.Info("Dev mode or write key not set: Segment analytics client not initialized")
return &AnalyticsWrapper{client: nil}
}

Expand Down
16 changes: 12 additions & 4 deletions kontrol-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ import (
)

func main() {
devMode := flag.Bool("dev-mode", false, "Allow to run the service in local mode.")
var devMode bool
devMode = *flag.Bool("dev-mode", false, "Allow to run the service in local mode.")
if !devMode {
devModeEnvVarStr := os.Getenv("DEV_MODE")
if devModeEnvVarStr == "true" {
devMode = true
}
}

flag.Parse()

if *devMode {
if devMode {
logrus.Warn("Running in dev mode. CORS fully open.")
logrus.SetLevel(logrus.DebugLevel)
}

startServer(*devMode)
startServer(devMode)
}

func startServer(isDevMode bool) {
Expand Down Expand Up @@ -64,7 +71,8 @@ func startServer(isDevMode bool) {

// Create a new Segment analytics client instance.
// analyticsClient is not initialized in dev mode so events are not reported to Segment
analyticsWrapper := api.NewAnalyticsWrapper(isDevMode)
analyticsWriteKeyEnvVarStr := os.Getenv("ANALYTICS_WRITE_KEY")
analyticsWrapper := api.NewAnalyticsWrapper(isDevMode, analyticsWriteKeyEnvVarStr)
defer analyticsWrapper.Close()

// create a type that satisfies the `api.ServerInterface`, which contains an implementation of every operation from the generated code
Expand Down

0 comments on commit d597fa7

Please sign in to comment.