mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 18:43:10 -06:00
Some more clean up
This commit is contained in:
parent
d900f6c499
commit
ac2d3cdf8d
|
|
@ -177,7 +177,7 @@ func startup() {
|
|||
if err := cfg.Derive(); err != nil {
|
||||
logrus.Fatalf("Failed to derive values from config: %s", err)
|
||||
}
|
||||
base := base.NewBaseDendrite(cfg, "Monolith")
|
||||
base := base.NewBaseDendrite(cfg)
|
||||
defer base.Close() // nolint: errcheck
|
||||
|
||||
rsAPI := roomserver.NewInternalAPI(base)
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ func (m *DendriteMonolith) Start() {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
base := base.NewBaseDendrite(cfg, "Monolith")
|
||||
base := base.NewBaseDendrite(cfg)
|
||||
base.ConfigureAdminEndpoints()
|
||||
m.processContext = base.ProcessContext
|
||||
defer base.Close() // nolint: errcheck
|
||||
|
|
|
|||
|
|
@ -121,9 +121,9 @@ func (p *P2PMonolith) SetupPinecone(sk ed25519.PrivateKey) {
|
|||
|
||||
func (p *P2PMonolith) SetupDendrite(cfg *config.Dendrite, port int, enableRelaying bool, enableMetrics bool, enableWebsockets bool) {
|
||||
if enableMetrics {
|
||||
p.BaseDendrite = base.NewBaseDendrite(cfg, "Monolith")
|
||||
p.BaseDendrite = base.NewBaseDendrite(cfg)
|
||||
} else {
|
||||
p.BaseDendrite = base.NewBaseDendrite(cfg, "Monolith", base.DisableMetrics)
|
||||
p.BaseDendrite = base.NewBaseDendrite(cfg, base.DisableMetrics)
|
||||
}
|
||||
p.port = port
|
||||
p.BaseDendrite.ConfigureAdminEndpoints()
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ func main() {
|
|||
cfg.Global.ServerName = gomatrixserverlib.ServerName(hex.EncodeToString(pk))
|
||||
cfg.Global.KeyID = gomatrixserverlib.KeyID(signing.KeyID)
|
||||
|
||||
base := base.NewBaseDendrite(cfg, "Monolith")
|
||||
base := base.NewBaseDendrite(cfg)
|
||||
base.ConfigureAdminEndpoints()
|
||||
defer base.Close() // nolint: errcheck
|
||||
|
||||
|
|
@ -157,13 +157,11 @@ func main() {
|
|||
serverKeyAPI := &signing.YggdrasilKeys{}
|
||||
keyRing := serverKeyAPI.KeyRing()
|
||||
|
||||
rsComponent := roomserver.NewInternalAPI(
|
||||
rsAPI := roomserver.NewInternalAPI(
|
||||
base,
|
||||
)
|
||||
|
||||
keyAPI := keyserver.NewInternalAPI(base, &base.Cfg.KeyServer, federation, rsComponent)
|
||||
|
||||
rsAPI := rsComponent
|
||||
keyAPI := keyserver.NewInternalAPI(base, &base.Cfg.KeyServer, federation, rsAPI)
|
||||
|
||||
userAPI := userapi.NewInternalAPI(base, &cfg.UserAPI, nil, keyAPI, rsAPI, base.PushGatewayHTTPClient())
|
||||
keyAPI.SetUserAPI(userAPI)
|
||||
|
|
@ -174,7 +172,7 @@ func main() {
|
|||
base, federation, rsAPI, base.Caches, keyRing, true,
|
||||
)
|
||||
|
||||
rsComponent.SetFederationAPI(fsAPI, keyRing)
|
||||
rsAPI.SetFederationAPI(fsAPI, keyRing)
|
||||
|
||||
monolith := setup.Monolith{
|
||||
Config: base.Cfg,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ package main
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
|
|
@ -36,7 +35,6 @@ var (
|
|||
httpsBindAddr = flag.String("https-bind-address", ":8448", "The HTTPS listening port for the server")
|
||||
certFile = flag.String("tls-cert", "", "The PEM formatted X509 certificate to use for TLS")
|
||||
keyFile = flag.String("tls-key", "", "The PEM private key to use for TLS")
|
||||
traceInternal = os.Getenv("DENDRITE_TRACE_INTERNAL") == "1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -45,7 +43,7 @@ func main() {
|
|||
httpsAddr := config.HTTPAddress("https://" + *httpsBindAddr)
|
||||
options := []basepkg.BaseDendriteOptions{}
|
||||
|
||||
base := basepkg.NewBaseDendrite(cfg, "Monolith", options...)
|
||||
base := basepkg.NewBaseDendrite(cfg, options...)
|
||||
defer base.Close() // nolint: errcheck
|
||||
|
||||
federation := base.CreateFederationClient()
|
||||
|
|
@ -58,8 +56,7 @@ func main() {
|
|||
|
||||
keyRing := fsAPI.KeyRing()
|
||||
|
||||
keyImpl := keyserver.NewInternalAPI(base, &base.Cfg.KeyServer, fsAPI, rsAPI)
|
||||
keyAPI := keyImpl
|
||||
keyAPI := keyserver.NewInternalAPI(base, &base.Cfg.KeyServer, fsAPI, rsAPI)
|
||||
|
||||
pgClient := base.PushGatewayHTTPClient()
|
||||
userAPI := userapi.NewInternalAPI(base, &cfg.UserAPI, cfg.Derived.ApplicationServices, keyAPI, rsAPI, pgClient)
|
||||
|
|
@ -72,7 +69,7 @@ func main() {
|
|||
rsAPI.SetFederationAPI(fsAPI, keyRing)
|
||||
rsAPI.SetAppserviceAPI(asAPI)
|
||||
rsAPI.SetUserAPI(userAPI)
|
||||
keyImpl.SetUserAPI(userAPI)
|
||||
keyAPI.SetUserAPI(userAPI)
|
||||
|
||||
monolith := setup.Monolith{
|
||||
Config: base.Cfg,
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ func main() {
|
|||
Level: "error",
|
||||
})
|
||||
cfg.ClientAPI.RegistrationDisabled = true
|
||||
base := base.NewBaseDendrite(cfg, "ResolveState", base.DisableMetrics)
|
||||
base := base.NewBaseDendrite(cfg, base.DisableMetrics)
|
||||
args := flag.Args()
|
||||
|
||||
fmt.Println("Room version", *roomVersion)
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ func TestMain(m *testing.M) {
|
|||
)
|
||||
|
||||
// Finally, build the server key APIs.
|
||||
sbase := base.NewBaseDendrite(cfg, "Monolith", base.DisableMetrics)
|
||||
sbase := base.NewBaseDendrite(cfg, base.DisableMetrics)
|
||||
s.api = NewInternalAPI(sbase, s.fedclient, nil, s.cache, nil, true)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) {
|
|||
cfg.Global.ServerName = gomatrixserverlib.ServerName("localhost")
|
||||
cfg.Global.PrivateKey = privKey
|
||||
cfg.Global.JetStream.InMemory = true
|
||||
b := base.NewBaseDendrite(cfg, "Monolith", base.DisableMetrics)
|
||||
b := base.NewBaseDendrite(cfg, base.DisableMetrics)
|
||||
keyRing := &test.NopJSONVerifier{}
|
||||
// TODO: This is pretty fragile, as if anything calls anything on these nils this test will break.
|
||||
// Unfortunately, it makes little sense to instantiate these dependencies when we just want to test routing.
|
||||
|
|
|
|||
|
|
@ -98,9 +98,7 @@ const (
|
|||
)
|
||||
|
||||
// NewBaseDendrite creates a new instance to be used by a component.
|
||||
// The componentName is used for logging purposes, and should be a friendly name
|
||||
// of the compontent running, e.g. "SyncAPI"
|
||||
func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...BaseDendriteOptions) *BaseDendrite {
|
||||
func NewBaseDendrite(cfg *config.Dendrite, options ...BaseDendriteOptions) *BaseDendrite {
|
||||
platformSanityChecks()
|
||||
enableMetrics := true
|
||||
for _, opt := range options {
|
||||
|
|
@ -129,7 +127,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base
|
|||
logrus.Warn("Open registration is enabled")
|
||||
}
|
||||
|
||||
closer, err := cfg.SetupTracing("Dendrite" + componentName)
|
||||
closer, err := cfg.SetupTracing()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Panicf("failed to start opentracing")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -411,14 +411,6 @@ func checkNotEmpty(configErrs *ConfigErrors, key, value string) {
|
|||
}
|
||||
}
|
||||
|
||||
// checkNotZero verifies the given value is not zero in the configuration.
|
||||
// If it is, adds an error to the list.
|
||||
func checkNotZero(configErrs *ConfigErrors, key string, value int64) {
|
||||
if value == 0 {
|
||||
configErrs.Add(fmt.Sprintf("missing config key %q", key))
|
||||
}
|
||||
}
|
||||
|
||||
// checkPositive verifies the given value is positive (zero included)
|
||||
// in the configuration. If it is not, adds an error to the list.
|
||||
func checkPositive(configErrs *ConfigErrors, key string, value int64) {
|
||||
|
|
@ -427,26 +419,6 @@ func checkPositive(configErrs *ConfigErrors, key string, value int64) {
|
|||
}
|
||||
}
|
||||
|
||||
// checkURL verifies that the parameter is a valid URL
|
||||
func checkURL(configErrs *ConfigErrors, key, value string) {
|
||||
if value == "" {
|
||||
configErrs.Add(fmt.Sprintf("missing config key %q", key))
|
||||
return
|
||||
}
|
||||
url, err := url.Parse(value)
|
||||
if err != nil {
|
||||
configErrs.Add(fmt.Sprintf("config key %q contains invalid URL (%s)", key, err.Error()))
|
||||
return
|
||||
}
|
||||
switch url.Scheme {
|
||||
case "http":
|
||||
case "https":
|
||||
default:
|
||||
configErrs.Add(fmt.Sprintf("config key %q URL should be http:// or https://", key))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// checkLogging verifies the parameters logging.* are valid.
|
||||
func (config *Dendrite) checkLogging(configErrs *ConfigErrors) {
|
||||
for _, logrusHook := range config.Logging {
|
||||
|
|
@ -525,12 +497,12 @@ func readKeyPEM(path string, data []byte, enforceKeyIDFormat bool) (gomatrixserv
|
|||
}
|
||||
|
||||
// SetupTracing configures the opentracing using the supplied configuration.
|
||||
func (config *Dendrite) SetupTracing(serviceName string) (closer io.Closer, err error) {
|
||||
func (config *Dendrite) SetupTracing() (closer io.Closer, err error) {
|
||||
if !config.Tracing.Enabled {
|
||||
return io.NopCloser(bytes.NewReader([]byte{})), nil
|
||||
}
|
||||
return config.Tracing.Jaeger.InitGlobalTracer(
|
||||
serviceName,
|
||||
"Dendrite",
|
||||
jaegerconfig.Logger(logrusLogger{logrus.StandardLogger()}),
|
||||
jaegerconfig.Metrics(jaegermetrics.NullFactory),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, f
|
|||
MaxIdleConnections: 2,
|
||||
ConnMaxLifetimeSeconds: 60,
|
||||
}
|
||||
base := base.NewBaseDendrite(&cfg, "Test", base.DisableMetrics)
|
||||
base := base.NewBaseDendrite(&cfg, base.DisableMetrics)
|
||||
return base, func() {
|
||||
base.ShutdownDendrite()
|
||||
base.WaitForShutdown()
|
||||
|
|
@ -86,7 +86,7 @@ func CreateBaseDendrite(t *testing.T, dbType test.DBType) (*base.BaseDendrite, f
|
|||
cfg.UserAPI.AccountDatabase.ConnectionString = config.DataSource(filepath.Join("file://", tempDir, "userapi.db"))
|
||||
cfg.RelayAPI.Database.ConnectionString = config.DataSource(filepath.Join("file://", tempDir, "relayapi.db"))
|
||||
|
||||
base := base.NewBaseDendrite(&cfg, "Test", base.DisableMetrics)
|
||||
base := base.NewBaseDendrite(&cfg, base.DisableMetrics)
|
||||
return base, func() {
|
||||
base.ShutdownDendrite()
|
||||
base.WaitForShutdown()
|
||||
|
|
@ -109,7 +109,7 @@ func Base(cfg *config.Dendrite) (*base.BaseDendrite, nats.JetStreamContext, *nat
|
|||
cfg.Global.JetStream.InMemory = true
|
||||
cfg.SyncAPI.Fulltext.InMemory = true
|
||||
cfg.FederationAPI.KeyPerspectives = nil
|
||||
base := base.NewBaseDendrite(cfg, "Tests", base.DisableMetrics)
|
||||
base := base.NewBaseDendrite(cfg, base.DisableMetrics)
|
||||
js, jc := base.NATS.Prepare(base.ProcessContext, &cfg.Global.JetStream)
|
||||
return base, js, jc
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue