satellite/overlay: add email-sending functionality to overlay service
We want to send emails to SNOs. Node status changes go through the overlay service, so it's a good place to add the mail service. Add the mailservice.Service, satellite address, and satellite name to overlay service. Also add feature flag --overlay.send-node-emails Change-Id: I3bd2cb3bf22f9724954ce2374f8b651b902b3a24
This commit is contained in:
parent
419fb9cf20
commit
a52f766273
@ -153,7 +153,7 @@ func verifySegmentsRange(cmd *cobra.Command, args []string) error {
|
||||
dialer := rpc.NewDefaultDialer(tlsOptions)
|
||||
|
||||
// setup dependencies for verification
|
||||
overlay, err := overlay.NewService(log.Named("overlay"), db.OverlayCache(), satelliteCfg.Overlay)
|
||||
overlay, err := overlay.NewService(log.Named("overlay"), db.OverlayCache(), nil, "", "", satelliteCfg.Overlay)
|
||||
if err != nil {
|
||||
return Error.Wrap(err)
|
||||
}
|
||||
|
@ -271,10 +271,22 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB,
|
||||
})
|
||||
}
|
||||
|
||||
{ // setup mailservice
|
||||
peer.Mail.Service, err = setupMailService(peer.Log, *config)
|
||||
if err != nil {
|
||||
return nil, errs.Combine(err, peer.Close())
|
||||
}
|
||||
|
||||
peer.Services.Add(lifecycle.Item{
|
||||
Name: "mail:service",
|
||||
Close: peer.Mail.Service.Close,
|
||||
})
|
||||
}
|
||||
|
||||
{ // setup overlay
|
||||
peer.Overlay.DB = peer.DB.OverlayCache()
|
||||
|
||||
peer.Overlay.Service, err = overlay.NewService(peer.Log.Named("overlay"), peer.Overlay.DB, config.Overlay)
|
||||
peer.Overlay.Service, err = overlay.NewService(peer.Log.Named("overlay"), peer.Overlay.DB, peer.Mail.Service, config.Console.ExternalAddress, config.Console.SatelliteName, config.Overlay)
|
||||
if err != nil {
|
||||
return nil, errs.Combine(err, peer.Close())
|
||||
}
|
||||
@ -473,18 +485,6 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB,
|
||||
}
|
||||
}
|
||||
|
||||
{ // setup mailservice
|
||||
peer.Mail.Service, err = setupMailService(peer.Log, *config)
|
||||
if err != nil {
|
||||
return nil, errs.Combine(err, peer.Close())
|
||||
}
|
||||
|
||||
peer.Services.Add(lifecycle.Item{
|
||||
Name: "mail:service",
|
||||
Close: peer.Mail.Service.Close,
|
||||
})
|
||||
}
|
||||
|
||||
{ // setup payments
|
||||
pc := config.Payments
|
||||
|
||||
|
@ -252,7 +252,7 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB,
|
||||
|
||||
{ // setup overlay
|
||||
peer.Overlay.DB = peer.DB.OverlayCache()
|
||||
peer.Overlay.Service, err = overlay.NewService(peer.Log.Named("overlay"), peer.Overlay.DB, config.Overlay)
|
||||
peer.Overlay.Service, err = overlay.NewService(peer.Log.Named("overlay"), peer.Overlay.DB, peer.Mail.Service, config.Console.ExternalAddress, config.Console.SatelliteName, config.Overlay)
|
||||
if err != nil {
|
||||
return nil, errs.Combine(err, peer.Close())
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ func BenchmarkNodeSelection(b *testing.B) {
|
||||
}
|
||||
})
|
||||
|
||||
service, err := overlay.NewService(zap.NewNop(), overlaydb, overlay.Config{
|
||||
service, err := overlay.NewService(zap.NewNop(), overlaydb, nil, "", "", overlay.Config{
|
||||
Node: nodeSelectionConfig,
|
||||
NodeSelectionCache: overlay.UploadSelectionCacheConfig{
|
||||
Staleness: time.Hour,
|
||||
|
@ -26,6 +26,7 @@ type Config struct {
|
||||
UpdateStatsBatchSize int `help:"number of update requests to process per transaction" default:"100"`
|
||||
NodeCheckInWaitPeriod time.Duration `help:"the amount of time to wait before accepting a redundant check-in from a node (unmodified info since last check-in)" default:"2h" testDefault:"30s"`
|
||||
RepairExcludedCountryCodes []string `help:"list of country codes to exclude nodes from target repair selection" default:"" testDefault:"FR,BE"`
|
||||
SendNodeEmails bool `help:"whether to send emails to nodes" default:"false"`
|
||||
}
|
||||
|
||||
// AsOfSystemTimeConfig is a configuration struct to enable 'AS OF SYSTEM TIME' for CRDB queries.
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
"storj.io/common/storj/location"
|
||||
"storj.io/common/sync2"
|
||||
"storj.io/storj/satellite/geoip"
|
||||
"storj.io/storj/satellite/mailservice"
|
||||
"storj.io/storj/satellite/metabase"
|
||||
)
|
||||
|
||||
@ -290,6 +291,9 @@ func (node *SelectedNode) Clone() *SelectedNode {
|
||||
type Service struct {
|
||||
log *zap.Logger
|
||||
db DB
|
||||
mail *mailservice.Service
|
||||
satelliteName string
|
||||
satelliteAddress string
|
||||
config Config
|
||||
|
||||
GeoIP geoip.IPToCountry
|
||||
@ -298,7 +302,7 @@ type Service struct {
|
||||
}
|
||||
|
||||
// NewService returns a new Service.
|
||||
func NewService(log *zap.Logger, db DB, config Config) (*Service, error) {
|
||||
func NewService(log *zap.Logger, db DB, mailService *mailservice.Service, satelliteAddr, satelliteName string, config Config) (*Service, error) {
|
||||
err := config.Node.AsOfSystemTime.isValid()
|
||||
if err != nil {
|
||||
return nil, errs.Wrap(err)
|
||||
@ -330,6 +334,9 @@ func NewService(log *zap.Logger, db DB, config Config) (*Service, error) {
|
||||
return &Service{
|
||||
log: log,
|
||||
db: db,
|
||||
mail: mailService,
|
||||
satelliteAddress: satelliteAddr,
|
||||
satelliteName: satelliteName,
|
||||
config: config,
|
||||
|
||||
GeoIP: geoIP,
|
||||
|
@ -74,7 +74,7 @@ func testCache(ctx *testcontext.Context, t *testing.T, store overlay.DB) {
|
||||
|
||||
serviceCtx, serviceCancel := context.WithCancel(ctx)
|
||||
defer serviceCancel()
|
||||
service, err := overlay.NewService(zaptest.NewLogger(t), store, serviceConfig)
|
||||
service, err := overlay.NewService(zaptest.NewLogger(t), store, nil, "", "", serviceConfig)
|
||||
require.NoError(t, err)
|
||||
ctx.Go(func() error { return service.Run(serviceCtx) })
|
||||
defer ctx.Check(service.Close)
|
||||
|
@ -23,7 +23,7 @@ func TestReliabilityCache_Concurrent(t *testing.T) {
|
||||
ctx := testcontext.New(t)
|
||||
defer ctx.Cleanup()
|
||||
|
||||
overlayCache, err := overlay.NewService(zap.NewNop(), fakeOverlayDB{}, overlay.Config{
|
||||
overlayCache, err := overlay.NewService(zap.NewNop(), fakeOverlayDB{}, nil, "", "", overlay.Config{
|
||||
NodeSelectionCache: overlay.UploadSelectionCacheConfig{
|
||||
Staleness: 2 * time.Nanosecond,
|
||||
},
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
version_checker "storj.io/storj/private/version/checker"
|
||||
"storj.io/storj/satellite/audit"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/mailservice"
|
||||
"storj.io/storj/satellite/metabase"
|
||||
"storj.io/storj/satellite/orders"
|
||||
"storj.io/storj/satellite/overlay"
|
||||
@ -56,6 +57,7 @@ type Repairer struct {
|
||||
Server *debug.Server
|
||||
}
|
||||
|
||||
Mail *mailservice.Service
|
||||
Overlay *overlay.Service
|
||||
Reputation *reputation.Service
|
||||
Orders struct {
|
||||
@ -139,9 +141,22 @@ func NewRepairer(log *zap.Logger, full *identity.FullIdentity,
|
||||
peer.Dialer = rpc.NewDefaultDialer(tlsOptions)
|
||||
}
|
||||
|
||||
{ // setup mail
|
||||
var err error
|
||||
peer.Mail, err = setupMailService(peer.Log, *config)
|
||||
if err != nil {
|
||||
return nil, errs.Combine(err, peer.Close())
|
||||
}
|
||||
|
||||
peer.Services.Add(lifecycle.Item{
|
||||
Name: "mail:service",
|
||||
Close: peer.Mail.Close,
|
||||
})
|
||||
}
|
||||
|
||||
{ // setup overlay
|
||||
var err error
|
||||
peer.Overlay, err = overlay.NewService(log.Named("overlay"), overlayCache, config.Overlay)
|
||||
peer.Overlay, err = overlay.NewService(log.Named("overlay"), overlayCache, peer.Mail, config.Console.ExternalAddress, config.Console.SatelliteName, config.Overlay)
|
||||
if err != nil {
|
||||
return nil, errs.Combine(err, peer.Close())
|
||||
}
|
||||
|
3
scripts/testdata/satellite-config.yaml.lock
vendored
3
scripts/testdata/satellite-config.yaml.lock
vendored
@ -697,6 +697,9 @@ identity.key-path: /root/.local/share/storj/identity/satellite/identity.key
|
||||
# list of country codes to exclude nodes from target repair selection
|
||||
# overlay.repair-excluded-country-codes: []
|
||||
|
||||
# whether to send emails to nodes
|
||||
# overlay.send-node-emails: false
|
||||
|
||||
# number of update requests to process per transaction
|
||||
# overlay.update-stats-batch-size: 100
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user