Skip to content

Commit 57b9d46

Browse files
author
Simon Emms
committed
[installation-telemetry]: get installationAdmin data from server
1 parent 62ca783 commit 57b9d46

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

components/installation-telemetry/cmd/send.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"os"
1010

1111
"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"
1214
"github.com/spf13/cobra"
1315
"gopkg.in/segmentio/analytics-go.v3"
1416
)
@@ -19,9 +21,17 @@ var sendCmd = &cobra.Command{
1921
Use: "send",
2022
Short: "Sends telemetry data",
2123
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 {
2535
log.Info("installation-telemetry is not permitted to send - exiting")
2636
return nil
2737
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

0 commit comments

Comments
 (0)