Skip to content

Commit

Permalink
Gitpod CLI: Improve Segment logging (#19064)
Browse files Browse the repository at this point in the history
* Gitpod CLI: Improve Segment logging

* Set empty logger correctly

* Proxy all files in the `static/bin/` folder

* copy all files

* Revert gzip change and fix proxy dep

* Update folder for artefacts
  • Loading branch information
filiptronicek authored Nov 17, 2023
1 parent 4b78a99 commit c00f28a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion components/ide-proxy/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ packages:
- "conf/**"
- "static/**"
deps:
- components/local-app:app
- components/local-app:app-with-manifest
argdeps:
- imageRepoBase
config:
Expand Down
2 changes: 1 addition & 1 deletion components/ide-proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FROM cgr.dev/chainguard/wolfi-base:latest@sha256:5fd82be4dfccc650c1985d57847f1af
RUN apk add brotli gzip

# Gitpod CLI and Local App
COPY components-local-app--app/bin/* /bin/
COPY components-local-app--app-with-manifest/bin/* /bin/

RUN for FILE in `ls /bin/gitpod-local-companion*`;do \
gzip -v -f -9 -k "$FILE"; \
Expand Down
2 changes: 1 addition & 1 deletion components/local-app/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var rootCmd = &cobra.Command{
if gpctx, err := cfg.GetActiveContext(); err == nil && gpctx != nil {
telemetryEnabled = telemetryEnabled && gpctx.Host.String() == "https://gitpod.io"
}
telemetry.Init(telemetryEnabled, cfg.Telemetry.Identity, constants.Version.String())
telemetry.Init(telemetryEnabled, cfg.Telemetry.Identity, constants.Version.String(), level)
telemetry.RecordCommand(cmd)

if !isVersionCommand(cmd) {
Expand Down
19 changes: 16 additions & 3 deletions components/local-app/pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"crypto/sha256"
"errors"
"fmt"
"io"
"log"
"log/slog"
"math/rand"
"net"
Expand All @@ -33,8 +35,8 @@ var opts struct {
client segment.Client
}

// Init initialises the telemetry
func Init(enabled bool, identity, version string) {
// Init initializes the telemetry
func Init(enabled bool, identity, version string, logLevel slog.Level) {
opts.Enabled = enabled
if !enabled {
return
Expand All @@ -44,7 +46,18 @@ func Init(enabled bool, identity, version string) {
opts.Identity = identity

if segmentKey != "" {
opts.client = segment.New(segmentKey)
var logger segment.Logger
if logLevel == slog.LevelDebug {
logger = segment.StdLogger(log.New(os.Stderr, "telemetry ", log.LstdFlags))
} else {
// we don't want to log anything
log := log.New(os.Stderr, "telemetry ", log.LstdFlags)
log.SetOutput(io.Discard)
logger = segment.StdLogger(log)
}
opts.client, _ = segment.NewWithConfig(segmentKey, segment.Config{
Logger: logger,
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/proxy/conf/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ https://{$GITPOD_DOMAIN} {
}

@ide_bin {
path /static/bin/gitpod-*
path /static/bin/*
}
handle @ide_bin {
import compression
Expand Down

0 comments on commit c00f28a

Please sign in to comment.