-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
mrsimonemms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
|
||
log.Info("installation-telemetry has successfully sent data - exiting") | ||
|
||
return err | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(sendCmd) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.