mirror of
https://github.com/zhigang1992/graphql-engine.git
synced 2026-04-28 20:15:01 +08:00
infer topic based on version set in telemetry struct (#1511)
This commit is contained in:
committed by
GitHub
parent
3caff9b924
commit
0bb233e825
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user