MM-23568: Add rudder to server diagnostics. (#14151)
* MM-23568: Add rudder to server diagnostics. * Add unit test. * Go mod tidy. * CSP Header fix. * Fix review comments. * Update web/handlers.go Co-Authored-By: Jesse Hallam <jesse.hallam@gmail.com> * Partially address review comments. * fix tests. * Finish implementing review suggestions and then fixing tests. * Fix CSP Header tests. Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
26310720be
Коммит
6cabc40e62
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/cors"
|
||||
rudder "github.com/rudderlabs/analytics-go"
|
||||
analytics "github.com/segmentio/analytics-go"
|
||||
"github.com/throttled/throttled"
|
||||
"golang.org/x/crypto/acme/autocert"
|
||||
@@ -115,6 +116,7 @@ type Server struct {
|
||||
|
||||
diagnosticId string
|
||||
diagnosticClient analytics.Client
|
||||
rudderClient rudder.Client
|
||||
|
||||
phase2PermissionsMigrationComplete bool
|
||||
|
||||
@@ -874,13 +876,47 @@ func (s *Server) initDiagnostics(endpoint string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) initRudder(endpoint string) {
|
||||
if s.rudderClient == nil {
|
||||
config := rudder.Config{}
|
||||
config.Logger = rudder.StdLogger(s.Log.StdLog(mlog.String("source", "rudder")))
|
||||
config.Endpoint = endpoint
|
||||
// For testing
|
||||
if endpoint != RUDDER_DATAPLANE_URL {
|
||||
config.Verbose = true
|
||||
config.BatchSize = 1
|
||||
}
|
||||
client, err := rudder.NewWithConfig(RUDDER_KEY, config)
|
||||
if err != nil {
|
||||
mlog.Error("Failed to create Rudder instance", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
client.Enqueue(rudder.Identify{
|
||||
UserId: s.diagnosticId,
|
||||
})
|
||||
|
||||
s.rudderClient = client
|
||||
}
|
||||
}
|
||||
|
||||
// shutdownDiagnostics closes the diagnostic client.
|
||||
func (s *Server) shutdownDiagnostics() error {
|
||||
var segmentErr, rudderErr error
|
||||
if s.diagnosticClient != nil {
|
||||
return s.diagnosticClient.Close()
|
||||
segmentErr = s.diagnosticClient.Close()
|
||||
}
|
||||
|
||||
return nil
|
||||
if s.rudderClient != nil {
|
||||
rudderErr = s.rudderClient.Close()
|
||||
}
|
||||
|
||||
if segmentErr != nil && rudderErr != nil {
|
||||
return errors.New(fmt.Sprintf("%s, %s", segmentErr.Error(), rudderErr.Error()))
|
||||
} else if segmentErr != nil {
|
||||
return segmentErr
|
||||
}
|
||||
|
||||
return rudderErr
|
||||
}
|
||||
|
||||
// GetHubs returns the list of hubs. This method is safe
|
||||
|
||||
Ссылка в новой задаче
Block a user