Tarun Pothulapati 5f6114c282 telemetry: add more fields to data
Fixes https://github.com/gitpod-io/gitpod/issues/7866

This PR updates the `installation-admin-controller` to also retrieve
more data to send with telemetry. These are not part of the
`installationAdminDb` as we do not want to store this in the database
but lazily retrieve whenever a request is sent to `/data` endpoint
of the `installation-admin` express app unlike the `uuid` and settings
which need to be stored and updated.

The following fields are added:
- `totalUsers` : specifies the total number of users in the instance
- `totalWorkspaces`: specifies the total number of **regular** workspaces in the instance
- `totalInstances`: specifies the total number of **regular** workspace instances in the gitpod instance

Signed-off-by: Tarun Pothulapati <tarun@gitpod.io>
2022-02-17 12:08:57 +01:00

74 lines
1.8 KiB
Go

// 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/gitpod-io/gitpod/installation-telemetry/pkg/common"
"github.com/gitpod-io/gitpod/installation-telemetry/pkg/server"
"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) {
config, err := common.NewConfig()
if err != nil {
return err
}
data, err := server.GetInstallationAdminData(*config)
if err != nil {
return err
}
if !data.InstallationAdmin.Settings.SendTelemetry {
log.Info("installation-telemetry is not permitted to send - exiting")
return nil
}
if segmentIOToken == "" {
return fmt.Errorf("segmentIOToken build variable 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()
}()
telemetry := analytics.Track{
UserId: data.InstallationAdmin.ID,
Event: "Installation telemetry",
Properties: analytics.NewProperties().
Set("version", versionId).
Set("totalUsers", data.TotalUsers).
Set("totalWorkspaces", data.TotalWorkspaces).
Set("totalInstances", data.TotalInstances),
}
client.Enqueue(telemetry)
log.WithField("telemetry", telemetry).Info("installation-telemetry has successfully sent data - exiting")
return err
},
}
func init() {
rootCmd.AddCommand(sendCmd)
}