File tree 3 files changed +70
-3
lines changed
components/installation-telemetry
3 files changed +70
-3
lines changed Original file line number Diff line number Diff line change 9
9
"os"
10
10
11
11
"github.com/gitpod-io/gitpod/common-go/log"
12
+ "github.com/gitpod-io/gitpod/installation-telemetry/pkg/common"
13
+ "github.com/gitpod-io/gitpod/installation-telemetry/pkg/server"
12
14
"github.com/spf13/cobra"
13
15
"gopkg.in/segmentio/analytics-go.v3"
14
16
)
@@ -19,9 +21,17 @@ var sendCmd = &cobra.Command{
19
21
Use : "send" ,
20
22
Short : "Sends telemetry data" ,
21
23
RunE : func (cmd * cobra.Command , args []string ) (err error ) {
22
- // @todo(sje): replace with a database call to get status
23
- canSendData := false
24
- if ! canSendData {
24
+ config , err := common .NewConfig ()
25
+ if err != nil {
26
+ return err
27
+ }
28
+
29
+ data , err := server .GetInstallationAdminData (* config )
30
+ if err != nil {
31
+ return err
32
+ }
33
+
34
+ if ! data .SendTelemetry {
25
35
log .Info ("installation-telemetry is not permitted to send - exiting" )
26
36
return nil
27
37
}
Original file line number Diff line number Diff line change
1
+ package common
2
+
3
+ import (
4
+ "fmt"
5
+ "os"
6
+ )
7
+
8
+ type Config struct {
9
+ Server string
10
+ }
11
+
12
+ func NewConfig () (* Config , error ) {
13
+ config := Config {
14
+ Server : os .Getenv ("SERVER_URL" ),
15
+ }
16
+
17
+ if config .Server == "" {
18
+ return nil , fmt .Errorf ("SERVER_URL required" )
19
+ }
20
+
21
+ return & config , nil
22
+ }
Original file line number Diff line number Diff line change
1
+ package server
2
+
3
+ import (
4
+ "encoding/json"
5
+ "fmt"
6
+ "io/ioutil"
7
+ "net/http"
8
+
9
+ "github.com/gitpod-io/gitpod/installation-telemetry/pkg/common"
10
+ )
11
+
12
+ type InstallationAdminData struct {
13
+ SendTelemetry bool `json:"sendTelemetry"`
14
+ }
15
+
16
+ func GetInstallationAdminData (config common.Config ) (* InstallationAdminData , error ) {
17
+ resp , err := http .Get (fmt .Sprintf ("%s/installation-admin/data" , config .Server ))
18
+ if err != nil {
19
+ return nil , err
20
+ }
21
+
22
+ defer resp .Body .Close ()
23
+
24
+ body , err := ioutil .ReadAll (resp .Body )
25
+ if err != nil {
26
+ return nil , err
27
+ }
28
+
29
+ var data InstallationAdminData
30
+ if err := json .Unmarshal (body , & data ); err != nil {
31
+ return nil , err
32
+ }
33
+
34
+ return & data , nil
35
+ }
You can’t perform that action at this time.
0 commit comments