Skip to content

[installation-telemetry]: initial commit plus installer setup #7503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .werft/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export async function build(context, version) {
if (withContrib || publishRelease) {
exec(`leeway build --docker-build-options network=host --werft=true -c remote ${dontTest ? '--dont-test' : ''} -Dversion=${version} -DimageRepoBase=${imageRepo} contrib:all`);
}
exec(`leeway build --docker-build-options network=host --werft=true -c remote ${dontTest ? '--dont-test' : ''} ${retag} --coverage-output-path=${coverageOutput} -Dversion=${version} -DremoveSources=false -DimageRepoBase=${imageRepo} -DlocalAppVersion=${localAppVersion} -DnpmPublishTrigger=${publishToNpm ? Date.now() : 'false'}`);
exec(`leeway build --docker-build-options network=host --werft=true -c remote ${dontTest ? '--dont-test' : ''} ${retag} --coverage-output-path=${coverageOutput} -Dversion=${version} -DremoveSources=false -DimageRepoBase=${imageRepo} -DlocalAppVersion=${localAppVersion} -DSEGMENT_IO_TOKEN=${process.env.SEGMENT_IO_TOKEN} -DnpmPublishTrigger=${publishToNpm ? Date.now() : 'false'}`);
if (publishRelease) {
try {
werft.phase("publish", "checking version semver compliance...");
Expand Down
5 changes: 5 additions & 0 deletions .werft/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ pod:
secretKeyRef:
name: honeycomb-api-key
key: apikey
- name: SEGMENT_IO_TOKEN
valueFrom:
secretKeyRef:
name: self-hosted
key: segmentIOToken
command:
- bash
- -c
Expand Down
2 changes: 2 additions & 0 deletions components/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ packages:
- components/server:docker
- components/service-waiter:docker
- components/supervisor:docker
- components/installation-telemetry:docker
- components/workspacekit:docker
- components/ws-daemon:docker
- components/ws-daemon/seccomp-profile-installer:docker
Expand Down Expand Up @@ -98,6 +99,7 @@ packages:
- components/service-waiter:app
- components/supervisor:app
- components/supervisor/frontend:app
- components/installation-telemetry:app
- components/workspacekit:app
- components/ws-daemon:app
- components/ws-manager-bridge:app
Expand Down
42 changes: 42 additions & 0 deletions components/installation-telemetry/BUILD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
# Licensed under the GNU Affero General Public License (AGPL).
# See License-AGPL.txt in the project root for license information.

packages:
- name: app
type: go
deps:
- components/common-go:lib
argdeps:
- SEGMENT_IO_TOKEN
srcs:
- go.mod
- go.sum
- "**/*.go"
env:
- CGO_ENABLED=0
config:
packaging: app
buildCommand:
[
"go",
"build",
"-trimpath",
"-ldflags",
"-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=${SEGMENT_IO_TOKEN}'",
]
- name: docker
type: docker
deps:
- :app
argdeps:
- imageRepoBase
config:
buildArgs:
VERSION: ${version}
dockerfile: leeway.Dockerfile
metadata:
helm-component: installationTelemetry
image:
- ${imageRepoBase}/installation-telemetry:${version}
- ${imageRepoBase}/installation-telemetry:commit-${__git_commit}
9 changes: 9 additions & 0 deletions components/installation-telemetry/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

options:
no_parent_owners: true

approvers:
- engineering-self-hosted

labels:
- "team: self-hosted"
38 changes: 38 additions & 0 deletions components/installation-telemetry/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package cmd

import (
"github.com/gitpod-io/gitpod/common-go/log"
"github.com/spf13/cobra"
)

var (
// ServiceName is the name we use for tracing/logging
ServiceName = "installation-telemetry"
// Version of this service - set during build
Version = ""
)

var jsonLog bool
var verbose bool

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: ServiceName,
Short: "This service sends telemetry information back to Gitpod",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
log.Init(ServiceName, Version, jsonLog, verbose)
},
}

func Execute() {
cobra.CheckErr(rootCmd.Execute())
}

func init() {
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")
}
63 changes: 63 additions & 0 deletions components/installation-telemetry/cmd/send.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package cmd

import (
"fmt"
"os"

"github.com/gitpod-io/gitpod/common-go/log"
"github.com/spf13/cobra"
"gopkg.in/segmentio/analytics-go.v3"
)

var segmentIOToken string

var sendCmd = &cobra.Command{
Use: "send",
Short: "Sends telemetry data",
RunE: func(cmd *cobra.Command, args []string) (err error) {
// @todo(sje): replace with a database call to get status
canSendData := false
if !canSendData {
log.Info("installation-telemetry is not permitted to send - exiting")
return nil
}

if segmentIOToken == "" {
return fmt.Errorf("segmentIOToken build variable not set")
}

domainHash := os.Getenv("GITPOD_DOMAIN_HASH")
if domainHash == "" {
return fmt.Errorf("GITPOD_DOMAIN_HASH envvar not set")
}

versionId := os.Getenv("GITPOD_INSTALLATION_VERSION")
if versionId == "" {
return fmt.Errorf("GITPOD_INSTALLATION_VERSION envvar not set")
}

client, err := analytics.NewWithConfig(segmentIOToken, analytics.Config{})
defer func() {
err = client.Close()
}()

client.Enqueue(analytics.Track{
UserId: domainHash,
Event: "Installation telemetry",
Properties: analytics.NewProperties().
Set("version", versionId),
})

log.Info("installation-telemetry has successfully sent data - exiting")

return err
},
}

func init() {
rootCmd.AddCommand(sendCmd)
}
21 changes: 21 additions & 0 deletions components/installation-telemetry/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module github.com/gitpod-io/gitpod/installation-telemetry

go 1.17

require (
github.com/gitpod-io/gitpod/common-go v0.0.0-00010101000000-000000000000
github.com/spf13/cobra v1.3.0
gopkg.in/segmentio/analytics-go.v3 v3.1.0
)

require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/segmentio/backo-go v1.0.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
)

replace github.com/gitpod-io/gitpod/common-go => ../common-go // leeway
Loading