* fix fileutils.TestFindFile on MacOS

* introduce model.ExternalServiceEnvironment

* pick license public key from external service env

* pick Stripe public key from external service env

* pick Rudder key from external service env

* configure Sentry DSN from external service env

* always log external_service_environment, Unsetenv

* clear faked BuildEnv, improve logging

* strip out unset GOTAGS

* fix Sentry tests

* simplify to just ServiceEnvironment

* relocate ServiceEnvironment in client config

* initialize CWS URLs based on service environment

* unset rudder key for boards dev

* harden service environment to avoid accidental production

* fix TestSentry again

* fix DEFAULT -> ENTERPRISE

* s/dev/test when naming playbooks rudder key

* simplify boards rudder key switch

* use uniform rudderKey variable names

* retain compatibility with existing pipeline

* reduce to just production/test

* unit test with valid test license

* simplify Playbooks telemetry initialization

* restore dev service environment

* emit ServiceEnvironment when running e2e tests
Этот коммит содержится в:
Jesse Hallam
2023-06-07 10:15:33 -03:00
коммит произвёл GitHub
родитель 6c82605df0
Коммит 305fac6507
37 изменённых файлов: 552 добавлений и 304 удалений

Просмотреть файл

@@ -640,6 +640,9 @@ func TestNoticeValidation(t *testing.T) {
model.BuildNumber = tt.args.serverVersion
if model.BuildNumber == "" {
model.BuildNumber = "5.26.1"
defer func() {
model.BuildNumber = ""
}()
}
if ok, err := noticeMatchesConditions(
th.App.Config(),

Просмотреть файл

@@ -74,8 +74,12 @@ import (
"github.com/mattermost/mattermost-server/server/v8/platform/shared/templates"
)
// declaring this as var to allow overriding in tests
var SentryDSN = "placeholder_sentry_dsn"
var SentryDSN = "https://9d7c9cccf549479799f880bcf4f26323@o94110.ingest.sentry.io/5212327"
// This is a placeholder to allow the existing release pipelines to run without failing to insert
// the key that's now hard-coded above. Remove this once we converge on the unified delivery
// pipeline in GitHub.
var _ = "placeholder_sentry_dsn"
type Server struct {
// RootRouter is the starting point for all HTTP requests to the server.
@@ -294,9 +298,10 @@ func NewServer(options ...Option) (*Server, error) {
// -------------------------------------------------------------------------
if *s.platform.Config().LogSettings.EnableDiagnostics && *s.platform.Config().LogSettings.EnableSentry {
if strings.Contains(SentryDSN, "placeholder") {
mlog.Warn("Sentry reporting is enabled, but SENTRY_DSN is not set. Disabling reporting.")
} else {
switch model.GetServiceEnvironment() {
case model.ServiceEnvironmentDev:
mlog.Warn("Sentry reporting is enabled, but service environment is dev. Disabling reporting.")
case model.ServiceEnvironmentProduction, model.ServiceEnvironmentTest:
if err2 := sentry.Init(sentry.ClientOptions{
Dsn: SentryDSN,
Release: model.BuildHash,
@@ -424,6 +429,7 @@ func NewServer(options ...Option) (*Server, error) {
mlog.String("build_date", model.BuildDate),
mlog.String("build_hash", model.BuildHash),
mlog.String("build_hash_enterprise", model.BuildHashEnterprise),
mlog.String("service_environment", model.GetServiceEnvironment()),
)
if model.BuildEnterpriseReady == "true" {
mlog.Info("Enterprise Build", mlog.Bool("enterprise_build", true))
@@ -907,11 +913,15 @@ func (s *Server) Start() error {
var handler http.Handler = s.RootRouter
if *s.platform.Config().LogSettings.EnableDiagnostics && *s.platform.Config().LogSettings.EnableSentry && !strings.Contains(SentryDSN, "placeholder") {
sentryHandler := sentryhttp.New(sentryhttp.Options{
Repanic: true,
})
handler = sentryHandler.Handle(handler)
switch model.GetServiceEnvironment() {
case model.ServiceEnvironmentProduction, model.ServiceEnvironmentTest:
if *s.platform.Config().LogSettings.EnableDiagnostics && *s.platform.Config().LogSettings.EnableSentry {
sentryHandler := sentryhttp.New(sentryhttp.Options{
Repanic: true,
})
handler = sentryHandler.Handle(handler)
}
case model.ServiceEnvironmentDev:
}
if allowedOrigins := *s.platform.Config().ServiceSettings.AllowCorsFrom; allowedOrigins != "" {

Просмотреть файл

@@ -395,6 +395,22 @@ func TestSentry(t *testing.T) {
}}
testDir, _ := fileutils.FindDir("tests")
setSentryDSN := func(t *testing.T, dsn *sentry.Dsn) {
os.Setenv("MM_SERVICEENVIRONMENT", model.ServiceEnvironmentTest)
// Allow Playbooks to startup
oldBuildHash := model.BuildHash
model.BuildHash = "dev"
oldSentryDSN := SentryDSN
SentryDSN = dsn.String()
t.Cleanup(func() {
os.Unsetenv("MM_SERVICEENVIRONMENT")
model.BuildHash = oldBuildHash
SentryDSN = oldSentryDSN
})
}
t.Run("sentry is disabled, should not receive a report", func(t *testing.T) {
data := make(chan bool, 1)
@@ -408,7 +424,7 @@ func TestSentry(t *testing.T) {
_, port, _ := net.SplitHostPort(server.Listener.Addr().String())
dsn, err := sentry.NewDsn(fmt.Sprintf("http://test:test@localhost:%s/123", port))
require.NoError(t, err)
SentryDSN = dsn.String()
setSentryDSN(t, dsn)
s, err := newServerWithConfig(t, func(cfg *model.Config) {
*cfg.ServiceSettings.ListenAddress = "localhost:0"
@@ -452,7 +468,7 @@ func TestSentry(t *testing.T) {
_, port, _ := net.SplitHostPort(server.Listener.Addr().String())
dsn, err := sentry.NewDsn(fmt.Sprintf("http://test:test@localhost:%s/123", port))
require.NoError(t, err)
SentryDSN = dsn.String()
setSentryDSN(t, dsn)
s, err := newServerWithConfig(t, func(cfg *model.Config) {
*cfg.ServiceSettings.ListenAddress = "localhost:0"