Skip to content

Commit 62f576f

Browse files
Pothulapatiroboquat
authored andcommitted
[local-preview] Send telemetry for each event
Currently, The telemetry of `local-preview` is the same as any self-hosted install which means that these telemetry cronjob is run daily, and also once when the installation is ready. This information isn't as useful, as the properties aren't that important for a short-lived installation. Instead, It would make sense to have telemetry on each event of the `local-preview` command itself so that we can measure the Installation success rate, Time taken, etc to improve the overall UX of `local-preview`. This will be more important for us to understand the usage of `local-preview` itself. This PR fixes that by attaching a telemetry event to be sent, for each status update in `local-preview`. For this to work, A anonymous User ID is generated and used for all status updates. Event Schema: ``` analytics.track({ userId: userId, event: "localpreview_status", properties: { status: "checking prerequisites" | "starting gitpod" | "gitpod ready" } }) ``` Signed-off-by: Tarun Pothulapati <tarun@gitpod.io>
1 parent 77d57bc commit 62f576f

File tree

7 files changed

+99
-27
lines changed

7 files changed

+99
-27
lines changed

install/preview/BUILD.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ packages:
33
type: docker
44
deps:
55
- install/installer:app
6+
- install/preview/prettylog:app
67
argdeps:
78
- imageRepoBase
89
srcs:
910
- "entrypoint.sh"
1011
- "manifests/*.yaml"
11-
- "prettylog/main.go"
12-
- "prettylog/go.sum"
13-
- "prettylog/go.mod"
1412
config:
1513
dockerfile: leeway.Dockerfile
1614
image:

install/preview/entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ if [ -z "${DOMAIN}" ]; then
99
export DOMAIN="127-0-0-1.nip.io"
1010
fi
1111

12+
# Create a USER_ID to be used everywhere
13+
USER_ID="$(od -x /dev/urandom | head -1 | awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}')"
14+
export USER_ID
15+
1216
if [ "$1" != "logging" ]; then
1317
$0 logging 2>&1 | /prettylog
1418
exit

install/preview/leeway.Dockerfile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
22
# Licensed under the MIT License. See License-MIT.txt in the project root for license information.
33

4-
FROM golang:1.18 as prettylog
5-
6-
WORKDIR /app
7-
COPY prettylog/* ./
8-
RUN CGO_ENABLED=0 go build .
9-
104
FROM rancher/k3s:v1.21.12-k3s1
115

126
ADD https://github.com/FiloSottile/mkcert/releases/download/v1.4.4/mkcert-v1.4.4-linux-amd64 /bin/mkcert
@@ -20,7 +14,7 @@ RUN chmod +x /bin/yq
2014

2115
COPY manifests/* /app/manifests/
2216
COPY install-installer--app/installer /gitpod-installer
23-
COPY --from=prettylog /app/prettylog /prettylog
17+
COPY install-preview-prettylog--app/prettylog /prettylog
2418

2519
COPY entrypoint.sh /entrypoint.sh
2620

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
# Licensed under the GNU Affero General Public License (AGPL).
3+
# See License-AGPL.txt in the project root for license information.
4+
5+
packages:
6+
- name: app
7+
type: go
8+
argdeps:
9+
- SEGMENT_IO_TOKEN
10+
srcs:
11+
- "main.go"
12+
- "go.sum"
13+
- "go.mod"
14+
env:
15+
- CGO_ENABLED=0
16+
config:
17+
packaging: app
18+
buildCommand:
19+
[
20+
"go",
21+
"build",
22+
"-trimpath",
23+
"-ldflags",
24+
"-buildid= -w -s -X 'main.segmentIOToken=${SEGMENT_IO_TOKEN}'",
25+
]

install/preview/prettylog/go.mod

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
module github.com/gitpod-io/gitpod/olpi/prettylog
1+
module github.com/gitpod-io/gitpod/install/preview/prettylog
22

33
go 1.18
44

5-
require github.com/pterm/pterm v0.12.41
6-
75
require (
6+
github.com/pterm/pterm v0.12.41
87
github.com/atomicgo/cursor v0.0.1 // indirect
98
github.com/gookit/color v1.5.0 // indirect
109
github.com/mattn/go-runewidth v0.0.13 // indirect
1110
github.com/rivo/uniseg v0.2.0 // indirect
1211
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
1312
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect
1413
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
14+
gopkg.in/segmentio/analytics-go.v3 v3.1.0
15+
)
16+
17+
require (
18+
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
19+
github.com/segmentio/backo-go v1.0.1 // indirect
20+
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
1521
)

install/preview/prettylog/go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/MarvinJWendt/testza v0.3.5 h1:g9krITRRlIsF1eO9sUKXtiTw670gZIIk6T08Kee
88
github.com/MarvinJWendt/testza v0.3.5/go.mod h1:ExbTpWmA1z2E9HSskvrNcwApoX4F9bID692s10nuHRY=
99
github.com/atomicgo/cursor v0.0.1 h1:xdogsqa6YYlLfM+GyClC/Lchf7aiMerFiZQn7soTOoU=
1010
github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk=
11+
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
12+
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
1113
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1214
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1315
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -18,8 +20,10 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
1820
github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
1921
github.com/klauspost/cpuid/v2 v2.0.12 h1:p9dKCg8i4gmOxtv35DvrYoWqYzQrvEVdjQ762Y0OqZE=
2022
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
23+
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
2124
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
2225
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
26+
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
2327
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
2428
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
2529
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
@@ -36,6 +40,8 @@ github.com/pterm/pterm v0.12.41 h1:e2BRfFo1H9nL8GY0S3ImbZqfZ/YimOk9XtkhoobKJVs=
3640
github.com/pterm/pterm v0.12.41/go.mod h1:LW/G4J2A42XlTaPTAGRPvbBfF4UXvHWhC6SN7ueU4jU=
3741
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
3842
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
43+
github.com/segmentio/backo-go v1.0.1 h1:68RQccglxZeyURy93ASB/2kc9QudzgIDexJ927N++y4=
44+
github.com/segmentio/backo-go v1.0.1/go.mod h1:9/Rh6yILuLysoQnZ2oNooD2g7aBnvM7r/fNVxRNWfBc=
3945
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
4046
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
4147
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -45,6 +51,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
4551
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
4652
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
4753
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
54+
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c h1:3lbZUMbMiGUW/LMkfsEABsc5zNT9+b1CvsJx47JzJ8g=
55+
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c/go.mod h1:UrdRz5enIKZ63MEE3IF9l2/ebyx59GyGgPi+tICQdmM=
4856
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4957
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
5058
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -57,6 +65,8 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+
5765
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
5866
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5967
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
68+
gopkg.in/segmentio/analytics-go.v3 v3.1.0 h1:UzxH1uaGZRpMKDhJyBz0pexz6yUoBU3x8bJsRk/HV6U=
69+
gopkg.in/segmentio/analytics-go.v3 v3.1.0/go.mod h1:4QqqlTlSSpVlWA9/9nDcPw+FkM2yv1NQoYjUbL9/JAw=
6070
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
6171
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
6272
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

install/preview/prettylog/main.go

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,30 @@ import (
1212
"strings"
1313

1414
"github.com/pterm/pterm"
15+
"gopkg.in/segmentio/analytics-go.v3"
1516
)
1617

17-
var msgs = []struct {
18-
Fail string
19-
Success string
20-
21-
Msg string
22-
}{
23-
{Msg: "checking prerequisites", Fail: "requires a system with at least", Success: "Gitpod Domain:"},
24-
{Msg: "preparing system", Success: "extracting images to download ahead"},
25-
{Msg: "downloading images", Success: "--output-split-files"},
26-
{Msg: "preparing Gitpod preview installation", Success: "rm -rf /var/lib/rancher/k3s/server/manifests/gitpod"},
27-
{Msg: "starting Gitpod", Success: "Gitpod pods are ready"},
28-
{Msg: fmt.Sprintf("Gitpod is running. Visit https://%s to access the dashboard", os.Getenv("DOMAIN"))},
29-
}
18+
const (
19+
telemetryEvent = "localpreview_status"
20+
)
21+
22+
var (
23+
segmentIOToken string
24+
msgs = []struct {
25+
Fail string
26+
Success string
27+
Status string
28+
29+
Msg string
30+
}{
31+
{Msg: "checking prerequisites", Fail: "requires a system with at least", Success: "Gitpod Domain:", Status: "checking prerequisites"},
32+
{Msg: "preparing system", Success: "extracting images to download ahead"},
33+
{Msg: "downloading images", Success: "--output-split-files"},
34+
{Msg: "preparing Gitpod preview installation", Success: "rm -rf /var/lib/rancher/k3s/server/manifests/gitpod"},
35+
{Msg: "starting Gitpod", Success: "Gitpod pods are ready", Status: "starting gitpod"},
36+
{Msg: fmt.Sprintf("Gitpod is running. Visit https://%s to access the dashboard", os.Getenv("DOMAIN")), Status: "gitpod ready"},
37+
}
38+
)
3039

3140
func main() {
3241
dmp, err := os.OpenFile("logs.txt", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
@@ -40,10 +49,11 @@ func main() {
4049
scan := bufio.NewScanner(r)
4150
var msgIdx int
4251
lastSpinner, _ := pterm.DefaultSpinner.Start(msgs[msgIdx].Msg)
52+
// send Telemetry update for the first phase
53+
send_telemetry(msgs[msgIdx].Status)
4354
for scan.Scan() {
4455
line := scan.Text()
4556
msg := msgs[msgIdx]
46-
4757
var next bool
4858
switch {
4959
case msg.Fail != "" && strings.Contains(line, msg.Fail):
@@ -63,6 +73,9 @@ func main() {
6373
return
6474
}
6575
lastSpinner, _ = pterm.DefaultSpinner.Start(msgs[msgIdx].Msg)
76+
// send Telemetry for phase update
77+
send_telemetry(msgs[msgIdx].Status)
78+
6679
}
6780
err = scan.Err()
6881
if errors.Is(err, io.EOF) {
@@ -72,3 +85,25 @@ func main() {
7285
panic(err)
7386
}
7487
}
88+
89+
func send_telemetry(status string) {
90+
if os.Getenv("DO_NOT_TRACK") != "1" && status != "" {
91+
if segmentIOToken == "" {
92+
panic("No segmentIOToken set during build")
93+
}
94+
95+
client, _ := analytics.NewWithConfig(segmentIOToken, analytics.Config{})
96+
defer func() {
97+
client.Close()
98+
99+
}()
100+
101+
telemetry := analytics.Track{
102+
UserId: os.Getenv("USER_ID"),
103+
Event: telemetryEvent,
104+
Properties: analytics.NewProperties().
105+
Set("status", status),
106+
}
107+
client.Enqueue(telemetry)
108+
}
109+
}

0 commit comments

Comments
 (0)