infer topic based on version set in telemetry struct (#1511)

This commit is contained in:
Shahidh K Muhammed
2019-01-29 10:37:22 +05:30
committed by GitHub
parent 3caff9b924
commit 0bb233e825
2 changed files with 20 additions and 12 deletions

View File

@@ -5,7 +5,7 @@ import (
"sync"
"time"
"github.com/hasura/graphql-engine/cli/version"
"github.com/Masterminds/semver"
"github.com/parnurzeal/gorequest"
"github.com/sirupsen/logrus"
)
@@ -19,13 +19,6 @@ const Endpoint = "https://telemetry.hasura.io/v1/http"
// Topic is the name under which telemetry is sent.
var Topic = "cli_test"
func init() {
var v = version.New()
if v.CLISemver != nil {
Topic = "cli"
}
}
type requestPayload struct {
Topic string `json:"topic"`
Data `json:"data"`
@@ -98,10 +91,18 @@ func (d *Data) Beam() {
}
}
func getTopic(v string) string {
topic := "cli_test"
if _, err := semver.NewVersion(v); err == nil {
topic = "cli"
}
return topic
}
func beam(d *Data, log *logrus.Logger) {
d.IsBeamed = true
p := requestPayload{
Topic: Topic,
Topic: getTopic(d.Version),
Data: *d,
}
tick := time.Now()

View File

@@ -4,12 +4,19 @@ import (
"testing"
"github.com/hasura/graphql-engine/cli/telemetry"
"github.com/hasura/graphql-engine/cli/version"
)
func TestBeam(t *testing.T) {
func TestBeamDev(t *testing.T) {
tm := telemetry.BuildEvent()
tm.Version = version.BuildVersion
tm.Version = "dev"
tm.Command = "TEST"
tm.CanBeam = true
tm.Beam()
}
func TestBeamProd(t *testing.T) {
tm := telemetry.BuildEvent()
tm.Version = "v1.0.0-a-valid-semver"
tm.Command = "TEST"
tm.CanBeam = true
tm.Beam()