Skip to content

Commit 96af4ca

Browse files
author
Simon Emms
committed
[installation-telemetry]: initial commit
1 parent eb2ce5d commit 96af4ca

File tree

9 files changed

+1092
-3
lines changed

9 files changed

+1092
-3
lines changed

components/BUILD.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ packages:
5656
- components/server:docker
5757
- components/service-waiter:docker
5858
- components/supervisor:docker
59+
- components/installation-telemetry:docker
5960
- components/workspacekit:docker
6061
- components/ws-daemon:docker
6162
- components/ws-daemon/seccomp-profile-installer:docker
@@ -68,9 +69,13 @@ packages:
6869
- dev/version-manifest:app
6970
config:
7071
commands:
71-
- ["sh", "-c", "echo \"commit: ${__git_commit}\" > versions.yaml"]
72-
- ["sh", "-c", "echo \"version: ${version}\" >> versions.yaml"]
73-
- ["sh", "-c", "dev-version-manifest--app/version-manifest >> versions.yaml"]
72+
- ["sh", "-c", 'echo "commit: ${__git_commit}" > versions.yaml']
73+
- ["sh", "-c", 'echo "version: ${version}" >> versions.yaml']
74+
- [
75+
"sh",
76+
"-c",
77+
"dev-version-manifest--app/version-manifest >> versions.yaml",
78+
]
7479
- ["sh", "-c", "rm -r components* dev-*"]
7580
- name: publish-api
7681
type: generic
@@ -98,6 +103,7 @@ packages:
98103
- components/service-waiter:app
99104
- components/supervisor:app
100105
- components/supervisor/frontend:app
106+
- components/installation-telemetry:app
101107
- components/workspacekit:app
102108
- components/ws-daemon:app
103109
- components/ws-manager-bridge:app
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+
packages:
6+
- name: lib
7+
type: go
8+
deps:
9+
- components/common-go:lib
10+
srcs:
11+
- "**"
12+
config:
13+
packaging: library
14+
dontTest: false
15+
- name: app
16+
type: go
17+
deps:
18+
- components/common-go:lib
19+
srcs:
20+
- go.mod
21+
- go.sum
22+
- "**/*.go"
23+
env:
24+
- CGO_ENABLED=0
25+
config:
26+
packaging: app
27+
buildCommand: [
28+
"go",
29+
"build",
30+
"-trimpath",
31+
"-ldflags",
32+
# todo(sje): add the segment token from a leeway secret
33+
"-buildid= -w -s -X 'github.com/gitpod-io/gitpod/installation-telemetry/cmd.Version=commit-${__git_commit}' -X 'github.com/gitpod-io/gitpod/installation-telemetry/cmd.segmentIOToken=my-token'",
34+
]
35+
- name: docker
36+
type: docker
37+
deps:
38+
- :app
39+
argdeps:
40+
- imageRepoBase
41+
config:
42+
buildArgs:
43+
VERSION: ${version}
44+
dockerfile: leeway.Dockerfile
45+
metadata:
46+
helm-component: installationTelemetry
47+
image:
48+
- ${imageRepoBase}/installation-telemetry:${version}
49+
- ${imageRepoBase}/installation-telemetry:commit-${__git_commit}
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"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
"github.com/gitpod-io/gitpod/common-go/log"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var (
13+
// ServiceName is the name we use for tracing/logging
14+
ServiceName = "installation-telemetry"
15+
// Version of this service - set during build
16+
Version = ""
17+
)
18+
19+
var jsonLog bool
20+
var verbose bool
21+
22+
// rootCmd represents the base command when called without any subcommands
23+
var rootCmd = &cobra.Command{
24+
Use: "telemetry",
25+
Short: "This service sends telemetry information back to Gitpod",
26+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
27+
log.Init(ServiceName, Version, jsonLog, verbose)
28+
},
29+
}
30+
31+
func Execute() {
32+
cobra.CheckErr(rootCmd.Execute())
33+
}
34+
35+
func init() {
36+
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
37+
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")
38+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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/gitpod-io/gitpod/common-go/log"
12+
"github.com/spf13/cobra"
13+
"gopkg.in/segmentio/analytics-go.v3"
14+
)
15+
16+
var segmentIOToken string
17+
18+
var sendCmd = &cobra.Command{
19+
Use: "send",
20+
Short: "Sends telemetry data",
21+
RunE: func(cmd *cobra.Command, args []string) (err error) {
22+
if segmentIOToken == "" {
23+
return fmt.Errorf("segmentIOToken build variable not set")
24+
}
25+
26+
userId := os.Getenv("GITPOD_INSTALLATION_ID")
27+
if userId == "" {
28+
return fmt.Errorf("GITPOD_INSTALLATION_ID envvar not set")
29+
}
30+
31+
versionId := os.Getenv("GITPOD_INSTALLATION_VERSION")
32+
if versionId == "" {
33+
return fmt.Errorf("GITPOD_INSTALLATION_VERSION envvar not set")
34+
}
35+
36+
client, err := analytics.NewWithConfig(segmentIOToken, analytics.Config{})
37+
defer func() {
38+
err = client.Close()
39+
}()
40+
41+
client.Enqueue(analytics.Track{
42+
UserId: userId,
43+
Event: "Installation telemetry",
44+
Properties: analytics.NewProperties().
45+
Set("version", versionId),
46+
})
47+
48+
log.Info("installation-telemetry has successfully sent data - exiting")
49+
50+
return err
51+
},
52+
}
53+
54+
func init() {
55+
rootCmd.AddCommand(sendCmd)
56+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module github.com/gitpod-io/gitpod/installation-telemetry
2+
3+
go 1.17
4+
5+
require (
6+
github.com/gitpod-io/gitpod/common-go v0.0.0-00010101000000-000000000000
7+
github.com/spf13/cobra v1.3.0
8+
gopkg.in/segmentio/analytics-go.v3 v3.1.0
9+
)
10+
11+
require (
12+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
13+
github.com/kr/text v0.2.0 // indirect
14+
github.com/segmentio/backo-go v1.0.0 // indirect
15+
github.com/sirupsen/logrus v1.8.1 // indirect
16+
github.com/spf13/pflag v1.0.5 // indirect
17+
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
18+
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
19+
)
20+
21+
replace github.com/gitpod-io/gitpod/common-go => ../common-go // leeway

0 commit comments

Comments
 (0)