Skip to content

Commit aed07de

Browse files
author
Simon Emms
committed
[telemetry]: initial commit
1 parent 8e79e27 commit aed07de

File tree

8 files changed

+896
-0
lines changed

8 files changed

+896
-0
lines changed

components/telemetry/BUILD.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
packages:
2+
- name: telemetry
3+
type: go
4+
srcs:
5+
- go.mod
6+
- go.sum
7+
- "**/*.go"
8+
env:
9+
- CGO_ENABLED=0
10+
config:
11+
packaging: app
12+
buildCommand: [
13+
"go",
14+
"build",
15+
"-trimpath",
16+
"-ldflags",
17+
# todo(sje): change "commit-${__git_commit}" for the segment token
18+
"-buildid= -w -s -X 'github.com/gitpod-io/gitpod/telemetry/cmd.segmentIOToken=commit-${__git_commit}'",
19+
]

components/telemetry/OWNERS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
options:
3+
no_parent_owners: true
4+
5+
approvers:
6+
- engineering-self-hosted
7+
8+
labels:
9+
- "team: self-hosted"

components/telemetry/cmd/root.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
package cmd
6+
7+
import "github.com/spf13/cobra"
8+
9+
// rootCmd represents the base command when called without any subcommands
10+
var rootCmd = &cobra.Command{
11+
Use: "telemetry",
12+
Short: "This service sends telemetry information back to Gitpod",
13+
}
14+
15+
func Execute() {
16+
cobra.CheckErr(rootCmd.Execute())
17+
}
18+
19+
func init() {
20+
rootCmd.AddCommand(runCmd)
21+
}

components/telemetry/cmd/run.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
package cmd
6+
7+
import (
8+
"fmt"
9+
"os"
10+
11+
"github.com/spf13/cobra"
12+
"gopkg.in/segmentio/analytics-go.v3"
13+
)
14+
15+
var segmentIOToken string
16+
17+
var runCmd = &cobra.Command{
18+
Use: "run",
19+
Short: "Sends telemetry data",
20+
RunE: func(cmd *cobra.Command, args []string) (err error) {
21+
if segmentIOToken == "" {
22+
return fmt.Errorf("segmentIOToken build variable not set")
23+
}
24+
25+
userId := os.Getenv("GITPOD_INSTALLATION_ID")
26+
if userId == "" {
27+
return fmt.Errorf("GITPOD_INSTALLATION_ID envvar not set")
28+
}
29+
30+
versionId := os.Getenv("GITPOD_INSTALLATION_VERSION")
31+
if versionId == "" {
32+
return fmt.Errorf("GITPOD_INSTALLATION_VERSION envvar not set")
33+
}
34+
35+
client, err := analytics.NewWithConfig(segmentIOToken, analytics.Config{})
36+
defer func() {
37+
err = client.Close()
38+
}()
39+
40+
client.Enqueue(analytics.Track{
41+
UserId: userId,
42+
Event: "Installation telemetry",
43+
Properties: analytics.NewProperties().
44+
Set("version", versionId),
45+
})
46+
47+
return err
48+
},
49+
}

components/telemetry/go.mod

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module github.com/gitpod-io/gitpod/telemetry
2+
3+
go 1.17
4+
5+
require (
6+
github.com/spf13/cobra v1.3.0
7+
gopkg.in/segmentio/analytics-go.v3 v3.1.0
8+
)
9+
10+
require (
11+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
12+
github.com/segmentio/backo-go v1.0.0 // indirect
13+
github.com/spf13/pflag v1.0.5 // indirect
14+
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
15+
)

components/telemetry/go.sum

Lines changed: 764 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2021 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+
FROM alpine:3.15
6+
COPY telemetry--app/telemetry telemetry--app/provenance-bundle.jsonl /app/
7+
ENTRYPOINT [ "/app/telemetry" ]
8+
CMD [ "help" ]

components/telemetry/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
package main
6+
7+
import "github.com/gitpod-io/gitpod/telemetry/cmd"
8+
9+
func main() {
10+
cmd.Execute()
11+
}

0 commit comments

Comments
 (0)