Update config

This commit is contained in:
Till Faelligen 2022-05-03 20:51:57 +02:00 committed by Till Faelligen
parent af3fc7daa8
commit b5b635f923
3 changed files with 27 additions and 10 deletions

View file

@ -71,11 +71,8 @@ type Global struct {
// ServerNotices configuration used for sending server notices
ServerNotices ServerNotices `yaml:"server_notices"`
// ReportStats configures anonymous usage stats of the server
ReportStats bool `yaml:"report_stats"`
// ReportStatsEndpoint configuration
ReportStatsEndpoint string `yaml:"report_stats_endpoint"`
// ReportStats configures opt-in anonymous stats reporting.
ReportStats ReportStats `yaml:"report_stats"`
}
func (c *Global) Defaults(generate bool) {
@ -86,14 +83,13 @@ func (c *Global) Defaults(generate bool) {
c.KeyID = "ed25519:auto"
}
c.KeyValidityPeriod = time.Hour * 24 * 7
c.ReportStats = false
c.ReportStatsEndpoint = "https://matrix.org/report-usage-stats/push"
c.JetStream.Defaults(generate)
c.Metrics.Defaults(generate)
c.DNSCache.Defaults()
c.Sentry.Defaults()
c.ServerNotices.Defaults(generate)
c.ReportStats.Defaults()
}
func (c *Global) Verify(configErrs *ConfigErrors, isMonolith bool) {
@ -105,6 +101,7 @@ func (c *Global) Verify(configErrs *ConfigErrors, isMonolith bool) {
c.Sentry.Verify(configErrs, isMonolith)
c.DNSCache.Verify(configErrs, isMonolith)
c.ServerNotices.Verify(configErrs, isMonolith)
c.ReportStats.Verify(configErrs, isMonolith)
}
type OldVerifyKeys struct {
@ -171,6 +168,26 @@ func (c *ServerNotices) Defaults(generate bool) {
func (c *ServerNotices) Verify(errors *ConfigErrors, isMonolith bool) {}
// ReportStats configures opt-in anonymous stats reporting.
type ReportStats struct {
// Enabled configures anonymous usage stats of the server
Enabled bool `yaml:"enabled"`
// Endpoint the endpoint to report stats to
Endpoint string `yaml:"endpoint"`
}
func (c *ReportStats) Defaults() {
c.Enabled = false
c.Endpoint = "https://matrix.org/report-usage-stats/push"
}
func (c *ReportStats) Verify(configErrs *ConfigErrors, isMonolith bool) {
if c.Enabled {
checkNotEmpty(configErrs, "global.report_stats.endpoint", c.Endpoint)
}
}
// The configuration to use for Sentry error reporting
type Sentry struct {
Enabled bool `yaml:"enabled"`

View file

@ -105,7 +105,7 @@ func NewInternalAPI(
}
time.AfterFunc(time.Minute, cleanOldNotifs)
if base.Cfg.Global.ReportStats {
if base.Cfg.Global.ReportStats.Enabled {
go util.StartPhoneHomeCollector(time.Now(), base.Cfg, db)
}

View file

@ -142,9 +142,9 @@ func (p *phoneHomeStats) collect() {
return
}
logrus.Infof("Reporting stats to %s: %s", p.cfg.Global.ReportStatsEndpoint, output.String())
logrus.Infof("Reporting stats to %s: %s", p.cfg.Global.ReportStats.Endpoint, output.String())
request, err := http.NewRequest("POST", p.cfg.Global.ReportStatsEndpoint, &output)
request, err := http.NewRequest(http.MethodPost, p.cfg.Global.ReportStats.Endpoint, &output)
if err != nil {
logrus.WithError(err).Error("unable to create phone home stats request")
return