Rudder key and dataplane in Config (#15026)
* To allow for ease of testing telemetry changes, we should make it so that the rudder key and dataplane URL can be customized through the config or environment. * Instead of using a real config element that would be exposed to end users, we'll just use 'secret' environment variables to inject Rudder config data. Co-authored-by: Alex Dovenmuehle <alex.dovenmuehle@mattermost.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3fc9ed9871
Коммит
4791aca112
@@ -4,6 +4,7 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -69,13 +70,33 @@ const (
|
|||||||
// declaring this as var to allow overriding in tests
|
// declaring this as var to allow overriding in tests
|
||||||
var SENTRY_DSN = "placeholder_sentry_dsn"
|
var SENTRY_DSN = "placeholder_sentry_dsn"
|
||||||
|
|
||||||
|
type RudderConfig struct {
|
||||||
|
RudderKey string
|
||||||
|
DataplaneUrl string
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) SendDailyDiagnostics() {
|
func (s *Server) SendDailyDiagnostics() {
|
||||||
s.sendDailyDiagnostics(false)
|
s.sendDailyDiagnostics(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) getRudderConfig() RudderConfig {
|
||||||
|
if !strings.Contains(RUDDER_KEY, "placeholder") && !strings.Contains(RUDDER_DATAPLANE_URL, "placeholder") {
|
||||||
|
return RudderConfig{RUDDER_KEY, RUDDER_DATAPLANE_URL}
|
||||||
|
} else if os.Getenv("RUDDER_KEY") != "" && os.Getenv("RUDDER_DATAPLANE_URL") != "" {
|
||||||
|
return RudderConfig{os.Getenv("RUDDER_KEY"), os.Getenv("RUDDER_DATAPLANE_URL")}
|
||||||
|
} else {
|
||||||
|
return RudderConfig{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) diagnosticsEnabled() bool {
|
||||||
|
return *s.Config().LogSettings.EnableDiagnostics && s.IsLeader()
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) sendDailyDiagnostics(override bool) {
|
func (s *Server) sendDailyDiagnostics(override bool) {
|
||||||
if *s.Config().LogSettings.EnableDiagnostics && s.IsLeader() && ((!strings.Contains(RUDDER_KEY, "placeholder") && !strings.Contains(RUDDER_DATAPLANE_URL, "placeholder")) || override) {
|
config := s.getRudderConfig()
|
||||||
s.initDiagnostics(RUDDER_DATAPLANE_URL)
|
if s.diagnosticsEnabled() && ((config.DataplaneUrl != "" && config.RudderKey != "") || override) {
|
||||||
|
s.initDiagnostics(config.DataplaneUrl, config.RudderKey)
|
||||||
s.trackActivity()
|
s.trackActivity()
|
||||||
s.trackConfig()
|
s.trackConfig()
|
||||||
s.trackLicense()
|
s.trackLicense()
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -123,7 +124,7 @@ func TestRudderDiagnostics(t *testing.T) {
|
|||||||
|
|
||||||
diagnosticID := "test-diagnostic-id-12345"
|
diagnosticID := "test-diagnostic-id-12345"
|
||||||
th.App.SetDiagnosticId(diagnosticID)
|
th.App.SetDiagnosticId(diagnosticID)
|
||||||
th.Server.initDiagnostics(server.URL)
|
th.Server.initDiagnostics(server.URL, RUDDER_KEY)
|
||||||
|
|
||||||
assertPayload := func(t *testing.T, actual payload, event string, properties map[string]interface{}) {
|
assertPayload := func(t *testing.T, actual payload, event string, properties map[string]interface{}) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
@@ -334,4 +335,16 @@ func TestRudderDiagnostics(t *testing.T) {
|
|||||||
// Did not receive diagnostics
|
// Did not receive diagnostics
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("RudderConfigUsesConfigForValues", func(t *testing.T) {
|
||||||
|
os.Setenv("RUDDER_KEY", "abc123")
|
||||||
|
os.Setenv("RUDDER_DATAPLANE_URL", "arudderstackplace")
|
||||||
|
defer os.Unsetenv("RUDDER_KEY")
|
||||||
|
defer os.Unsetenv("RUDDER_DATAPLANE_URL")
|
||||||
|
|
||||||
|
config := th.App.Srv().getRudderConfig()
|
||||||
|
|
||||||
|
assert.Equal(t, "arudderstackplace", config.DataplaneUrl)
|
||||||
|
assert.Equal(t, "abc123", config.RudderKey)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1299,7 +1299,7 @@ func (s *Server) stopSearchEngine() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// initDiagnostics initialises the Rudder client for the diagnostics system.
|
// initDiagnostics initialises the Rudder client for the diagnostics system.
|
||||||
func (s *Server) initDiagnostics(endpoint string) {
|
func (s *Server) initDiagnostics(endpoint string, rudderKey string) {
|
||||||
if s.rudderClient == nil {
|
if s.rudderClient == nil {
|
||||||
config := rudder.Config{}
|
config := rudder.Config{}
|
||||||
config.Logger = rudder.StdLogger(s.Log.StdLog(mlog.String("source", "rudder")))
|
config.Logger = rudder.StdLogger(s.Log.StdLog(mlog.String("source", "rudder")))
|
||||||
@@ -1309,7 +1309,7 @@ func (s *Server) initDiagnostics(endpoint string) {
|
|||||||
config.Verbose = true
|
config.Verbose = true
|
||||||
config.BatchSize = 1
|
config.BatchSize = 1
|
||||||
}
|
}
|
||||||
client, err := rudder.NewWithConfig(RUDDER_KEY, endpoint, config)
|
client, err := rudder.NewWithConfig(rudderKey, endpoint, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Error("Failed to create Rudder instance", mlog.Err(err))
|
mlog.Error("Failed to create Rudder instance", mlog.Err(err))
|
||||||
return
|
return
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user