2019-06-20 12:52:32 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package console
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2019-11-08 20:40:39 +00:00
|
|
|
"github.com/spacemonkeygo/monkit/v3"
|
2019-06-20 12:52:32 +01:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/memory"
|
|
|
|
"storj.io/common/storj"
|
2020-03-23 19:30:31 +00:00
|
|
|
"storj.io/private/version"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/date"
|
|
|
|
"storj.io/storj/private/version/checker"
|
2019-06-20 12:52:32 +01:00
|
|
|
"storj.io/storj/storagenode/bandwidth"
|
2019-09-11 21:41:43 +01:00
|
|
|
"storj.io/storj/storagenode/contact"
|
2020-09-10 15:08:25 +01:00
|
|
|
"storj.io/storj/storagenode/payout/estimatedpayout"
|
2019-06-20 12:52:32 +01:00
|
|
|
"storj.io/storj/storagenode/pieces"
|
2020-04-10 15:03:14 +01:00
|
|
|
"storj.io/storj/storagenode/pricing"
|
2019-08-08 14:47:04 +01:00
|
|
|
"storj.io/storj/storagenode/reputation"
|
2020-04-10 15:03:14 +01:00
|
|
|
"storj.io/storj/storagenode/satellites"
|
2019-08-08 14:47:04 +01:00
|
|
|
"storj.io/storj/storagenode/storageusage"
|
|
|
|
"storj.io/storj/storagenode/trust"
|
2019-06-20 12:52:32 +01:00
|
|
|
)
|
|
|
|
|
2019-06-26 19:55:22 +01:00
|
|
|
var (
|
2019-08-14 13:17:11 +01:00
|
|
|
// SNOServiceErr defines sno service error.
|
2019-06-26 19:55:22 +01:00
|
|
|
SNOServiceErr = errs.Class("storage node dashboard service error")
|
|
|
|
|
|
|
|
mon = monkit.Package()
|
|
|
|
)
|
2019-06-24 16:15:31 +01:00
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
// Service is handling storage node operator related logic.
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Service
|
2019-06-20 12:52:32 +01:00
|
|
|
type Service struct {
|
2019-09-19 20:56:34 +01:00
|
|
|
log *zap.Logger
|
2019-08-08 14:47:04 +01:00
|
|
|
trust *trust.Pool
|
|
|
|
bandwidthDB bandwidth.DB
|
|
|
|
reputationDB reputation.DB
|
2019-08-14 13:17:11 +01:00
|
|
|
storageUsageDB storageusage.DB
|
2020-04-10 15:03:14 +01:00
|
|
|
pricingDB pricing.DB
|
|
|
|
satelliteDB satellites.DB
|
2019-08-08 14:47:04 +01:00
|
|
|
pieceStore *pieces.Store
|
2019-09-19 20:56:34 +01:00
|
|
|
contact *contact.Service
|
|
|
|
|
2020-09-08 16:15:08 +01:00
|
|
|
estimation *estimatedpayout.Service
|
|
|
|
version *checker.Service
|
|
|
|
pingStats *contact.PingStats
|
2019-06-20 12:52:32 +01:00
|
|
|
|
|
|
|
allocatedDiskSpace memory.Size
|
2019-09-19 20:56:34 +01:00
|
|
|
|
|
|
|
walletAddress string
|
|
|
|
startedAt time.Time
|
|
|
|
versionInfo version.Info
|
2019-06-20 12:52:32 +01:00
|
|
|
}
|
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
// NewService returns new instance of Service.
|
2019-10-20 08:56:23 +01:00
|
|
|
func NewService(log *zap.Logger, bandwidth bandwidth.DB, pieceStore *pieces.Store, version *checker.Service,
|
2020-02-12 21:19:42 +00:00
|
|
|
allocatedDiskSpace memory.Size, walletAddress string, versionInfo version.Info, trust *trust.Pool,
|
2020-09-08 16:15:08 +01:00
|
|
|
reputationDB reputation.DB, storageUsageDB storageusage.DB, pricingDB pricing.DB, satelliteDB satellites.DB, pingStats *contact.PingStats, contact *contact.Service, estimation *estimatedpayout.Service) (*Service, error) {
|
2019-06-20 12:52:32 +01:00
|
|
|
if log == nil {
|
|
|
|
return nil, errs.New("log can't be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if bandwidth == nil {
|
|
|
|
return nil, errs.New("bandwidth can't be nil")
|
|
|
|
}
|
|
|
|
|
2019-08-08 02:47:30 +01:00
|
|
|
if pieceStore == nil {
|
|
|
|
return nil, errs.New("pieceStore can't be nil")
|
2019-06-20 12:52:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if version == nil {
|
|
|
|
return nil, errs.New("version can't be nil")
|
|
|
|
}
|
|
|
|
|
2019-09-11 21:41:43 +01:00
|
|
|
if pingStats == nil {
|
|
|
|
return nil, errs.New("pingStats can't be nil")
|
2019-06-20 12:52:32 +01:00
|
|
|
}
|
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
if contact == nil {
|
|
|
|
return nil, errs.New("contact service can't be nil")
|
|
|
|
}
|
2020-02-21 17:41:54 +00:00
|
|
|
|
2020-09-08 16:15:08 +01:00
|
|
|
if estimation == nil {
|
|
|
|
return nil, errs.New("estimation service can't be nil")
|
|
|
|
}
|
|
|
|
|
2019-06-20 12:52:32 +01:00
|
|
|
return &Service{
|
|
|
|
log: log,
|
2019-08-14 13:17:11 +01:00
|
|
|
trust: trust,
|
2019-06-20 12:52:32 +01:00
|
|
|
bandwidthDB: bandwidth,
|
2019-08-14 13:17:11 +01:00
|
|
|
reputationDB: reputationDB,
|
|
|
|
storageUsageDB: storageUsageDB,
|
2020-04-10 15:03:14 +01:00
|
|
|
pricingDB: pricingDB,
|
|
|
|
satelliteDB: satelliteDB,
|
2019-08-08 02:47:30 +01:00
|
|
|
pieceStore: pieceStore,
|
2019-06-20 12:52:32 +01:00
|
|
|
version: version,
|
2019-09-11 21:41:43 +01:00
|
|
|
pingStats: pingStats,
|
2019-06-20 12:52:32 +01:00
|
|
|
allocatedDiskSpace: allocatedDiskSpace,
|
2019-09-19 20:56:34 +01:00
|
|
|
contact: contact,
|
2020-09-08 16:15:08 +01:00
|
|
|
estimation: estimation,
|
2019-06-20 12:52:32 +01:00
|
|
|
walletAddress: walletAddress,
|
|
|
|
startedAt: time.Now(),
|
|
|
|
versionInfo: versionInfo,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2019-09-06 13:01:03 +01:00
|
|
|
// SatelliteInfo encapsulates satellite ID and disqualification.
|
|
|
|
type SatelliteInfo struct {
|
|
|
|
ID storj.NodeID `json:"id"`
|
2019-11-19 12:16:56 +00:00
|
|
|
URL string `json:"url"`
|
2019-09-06 13:01:03 +01:00
|
|
|
Disqualified *time.Time `json:"disqualified"`
|
2020-03-27 18:50:57 +00:00
|
|
|
Suspended *time.Time `json:"suspended"`
|
2019-09-06 13:01:03 +01:00
|
|
|
}
|
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
// Dashboard encapsulates dashboard stale data.
|
|
|
|
type Dashboard struct {
|
|
|
|
NodeID storj.NodeID `json:"nodeID"`
|
|
|
|
Wallet string `json:"wallet"`
|
2019-06-20 12:52:32 +01:00
|
|
|
|
2019-09-06 13:01:03 +01:00
|
|
|
Satellites []SatelliteInfo `json:"satellites"`
|
2019-06-20 12:52:32 +01:00
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
DiskSpace DiskSpaceInfo `json:"diskSpace"`
|
|
|
|
Bandwidth BandwidthInfo `json:"bandwidth"`
|
2019-07-02 10:53:40 +01:00
|
|
|
|
2020-04-27 12:07:51 +01:00
|
|
|
LastPinged time.Time `json:"lastPinged"`
|
2019-09-06 13:01:03 +01:00
|
|
|
|
2019-11-26 16:08:24 +00:00
|
|
|
Version version.SemVer `json:"version"`
|
|
|
|
AllowedVersion version.SemVer `json:"allowedVersion"`
|
|
|
|
UpToDate bool `json:"upToDate"`
|
2019-10-11 17:28:47 +01:00
|
|
|
|
|
|
|
StartedAt time.Time `json:"startedAt"`
|
2019-07-02 10:53:40 +01:00
|
|
|
}
|
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
// GetDashboardData returns stale dashboard data.
|
|
|
|
func (s *Service) GetDashboardData(ctx context.Context) (_ *Dashboard, err error) {
|
2019-07-02 10:53:40 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
2019-08-14 13:17:11 +01:00
|
|
|
data := new(Dashboard)
|
2019-07-02 10:53:40 +01:00
|
|
|
|
2020-05-20 14:40:25 +01:00
|
|
|
data.NodeID = s.contact.Local().ID
|
2019-08-14 13:17:11 +01:00
|
|
|
data.Wallet = s.walletAddress
|
|
|
|
data.Version = s.versionInfo.Version
|
2019-10-11 17:28:47 +01:00
|
|
|
data.StartedAt = s.startedAt
|
2019-09-11 21:41:43 +01:00
|
|
|
|
2019-10-03 19:31:39 +01:00
|
|
|
data.LastPinged = s.pingStats.WhenLastPinged()
|
2019-11-26 16:08:24 +00:00
|
|
|
data.AllowedVersion, data.UpToDate = s.version.IsAllowed(ctx)
|
2019-09-06 13:01:03 +01:00
|
|
|
|
|
|
|
stats, err := s.reputationDB.All(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, rep := range stats {
|
2020-05-19 17:11:30 +01:00
|
|
|
url, err := s.trust.GetNodeURL(ctx, rep.SatelliteID)
|
2019-11-19 12:16:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2019-09-06 13:01:03 +01:00
|
|
|
data.Satellites = append(data.Satellites,
|
|
|
|
SatelliteInfo{
|
|
|
|
ID: rep.SatelliteID,
|
2020-09-01 12:20:12 +01:00
|
|
|
Disqualified: rep.DisqualifiedAt,
|
|
|
|
Suspended: rep.SuspendedAt,
|
2020-05-19 17:11:30 +01:00
|
|
|
URL: url.Address,
|
2019-09-06 13:01:03 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2019-06-24 16:15:31 +01:00
|
|
|
|
2020-06-03 11:57:02 +01:00
|
|
|
pieceTotal, _, err := s.pieceStore.SpaceUsedForPieces(ctx)
|
2020-05-02 18:52:29 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
trash, err := s.pieceStore.SpaceUsedForTrash(ctx)
|
2019-06-20 12:52:32 +01:00
|
|
|
if err != nil {
|
2019-08-14 13:17:11 +01:00
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
2019-06-20 12:52:32 +01:00
|
|
|
}
|
|
|
|
|
2020-01-31 23:25:52 +00:00
|
|
|
bandwidthUsage, err := s.bandwidthDB.MonthSummary(ctx, time.Now())
|
2019-08-14 13:17:11 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
2019-06-20 12:52:32 +01:00
|
|
|
|
2020-08-02 17:21:43 +01:00
|
|
|
// temporary solution - in case we receive negative amount of free space we recalculate dir disk available space and recalculates used space.
|
|
|
|
// TODO: find real reason of negative space, garbage collector calculates trash correctly.
|
|
|
|
if s.allocatedDiskSpace.Int64()-pieceTotal-trash < 0 {
|
|
|
|
status, err := s.pieceStore.StorageStatus(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
data.DiskSpace = DiskSpaceInfo{
|
|
|
|
Used: s.allocatedDiskSpace.Int64() - status.DiskFree - trash,
|
|
|
|
Available: s.allocatedDiskSpace.Int64(),
|
|
|
|
Trash: trash,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data.DiskSpace = DiskSpaceInfo{
|
|
|
|
Used: pieceTotal,
|
|
|
|
Available: s.allocatedDiskSpace.Int64(),
|
|
|
|
Trash: trash,
|
|
|
|
}
|
2019-08-14 13:17:11 +01:00
|
|
|
}
|
2019-06-24 16:15:31 +01:00
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
data.Bandwidth = BandwidthInfo{
|
2020-02-12 21:19:42 +00:00
|
|
|
Used: bandwidthUsage,
|
2019-06-20 12:52:32 +01:00
|
|
|
}
|
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
return data, nil
|
|
|
|
}
|
|
|
|
|
2020-04-10 15:03:14 +01:00
|
|
|
// PriceModel is a satellite prices for storagenode usage TB/H.
|
|
|
|
type PriceModel struct {
|
|
|
|
EgressBandwidth int64
|
|
|
|
RepairBandwidth int64
|
|
|
|
AuditBandwidth int64
|
|
|
|
DiskSpace int64
|
|
|
|
}
|
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
// Satellite encapsulates satellite related data.
|
|
|
|
type Satellite struct {
|
2019-09-06 13:01:03 +01:00
|
|
|
ID storj.NodeID `json:"id"`
|
|
|
|
StorageDaily []storageusage.Stamp `json:"storageDaily"`
|
|
|
|
BandwidthDaily []bandwidth.UsageRollup `json:"bandwidthDaily"`
|
|
|
|
StorageSummary float64 `json:"storageSummary"`
|
|
|
|
BandwidthSummary int64 `json:"bandwidthSummary"`
|
2019-11-20 14:37:57 +00:00
|
|
|
EgressSummary int64 `json:"egressSummary"`
|
|
|
|
IngressSummary int64 `json:"ingressSummary"`
|
2019-09-06 13:01:03 +01:00
|
|
|
Audit reputation.Metric `json:"audit"`
|
|
|
|
Uptime reputation.Metric `json:"uptime"`
|
2020-09-01 12:20:12 +01:00
|
|
|
OnlineScore float64 `json:"onlineScore"`
|
2020-04-10 15:03:14 +01:00
|
|
|
PriceModel PriceModel `json:"priceModel"`
|
|
|
|
NodeJoinedAt time.Time `json:"nodeJoinedAt"`
|
2019-06-20 12:52:32 +01:00
|
|
|
}
|
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
// GetSatelliteData returns satellite related data.
|
|
|
|
func (s *Service) GetSatelliteData(ctx context.Context, satelliteID storj.NodeID) (_ *Satellite, err error) {
|
2019-06-24 16:15:31 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
2019-09-06 13:01:03 +01:00
|
|
|
from, to := date.MonthBoundary(time.Now().UTC())
|
2019-06-24 16:15:31 +01:00
|
|
|
|
2019-09-04 15:01:55 +01:00
|
|
|
bandwidthDaily, err := s.bandwidthDB.GetDailySatelliteRollups(ctx, satelliteID, from, to)
|
2019-06-20 12:52:32 +01:00
|
|
|
if err != nil {
|
2019-08-14 13:17:11 +01:00
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
2019-06-20 12:52:32 +01:00
|
|
|
}
|
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
storageDaily, err := s.storageUsageDB.GetDaily(ctx, satelliteID, from, to)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
2019-06-20 12:52:32 +01:00
|
|
|
|
2019-09-06 13:01:03 +01:00
|
|
|
bandwidthSummary, err := s.bandwidthDB.SatelliteSummary(ctx, satelliteID, from, to)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2019-11-20 14:37:57 +00:00
|
|
|
egressSummary, err := s.bandwidthDB.SatelliteEgressSummary(ctx, satelliteID, from, to)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ingressSummary, err := s.bandwidthDB.SatelliteIngressSummary(ctx, satelliteID, from, to)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2019-09-06 13:01:03 +01:00
|
|
|
storageSummary, err := s.storageUsageDB.SatelliteSummary(ctx, satelliteID, from, to)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
rep, err := s.reputationDB.Get(ctx, satelliteID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
2019-06-20 12:52:32 +01:00
|
|
|
|
2020-04-10 15:03:14 +01:00
|
|
|
pricingModel, err := s.pricingDB.Get(ctx, satelliteID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
satellitePricing := PriceModel{
|
|
|
|
EgressBandwidth: pricingModel.EgressBandwidth,
|
|
|
|
RepairBandwidth: pricingModel.RepairBandwidth,
|
|
|
|
AuditBandwidth: pricingModel.AuditBandwidth,
|
|
|
|
DiskSpace: pricingModel.DiskSpace,
|
|
|
|
}
|
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
return &Satellite{
|
2019-09-06 13:01:03 +01:00
|
|
|
ID: satelliteID,
|
|
|
|
StorageDaily: storageDaily,
|
|
|
|
BandwidthDaily: bandwidthDaily,
|
|
|
|
StorageSummary: storageSummary,
|
|
|
|
BandwidthSummary: bandwidthSummary.Total(),
|
2019-11-20 14:37:57 +00:00
|
|
|
EgressSummary: egressSummary.Total(),
|
|
|
|
IngressSummary: ingressSummary.Total(),
|
2019-09-06 13:01:03 +01:00
|
|
|
Audit: rep.Audit,
|
|
|
|
Uptime: rep.Uptime,
|
2020-09-01 12:20:12 +01:00
|
|
|
OnlineScore: rep.OnlineScore,
|
2020-04-10 15:03:14 +01:00
|
|
|
PriceModel: satellitePricing,
|
2020-04-16 16:40:28 +01:00
|
|
|
NodeJoinedAt: rep.JoinedAt,
|
2019-08-14 13:17:11 +01:00
|
|
|
}, nil
|
2019-06-20 12:52:32 +01:00
|
|
|
}
|
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
// Satellites represents consolidated data across all satellites.
|
|
|
|
type Satellites struct {
|
2019-09-06 13:01:03 +01:00
|
|
|
StorageDaily []storageusage.Stamp `json:"storageDaily"`
|
|
|
|
BandwidthDaily []bandwidth.UsageRollup `json:"bandwidthDaily"`
|
|
|
|
StorageSummary float64 `json:"storageSummary"`
|
|
|
|
BandwidthSummary int64 `json:"bandwidthSummary"`
|
2019-11-20 14:37:57 +00:00
|
|
|
EgressSummary int64 `json:"egressSummary"`
|
|
|
|
IngressSummary int64 `json:"ingressSummary"`
|
2020-04-13 16:00:14 +01:00
|
|
|
EarliestJoinedAt time.Time `json:"earliestJoinedAt"`
|
2020-08-10 11:13:21 +01:00
|
|
|
Audits []Audits `json:"audits"`
|
|
|
|
}
|
|
|
|
|
2020-09-01 12:20:12 +01:00
|
|
|
// Audits represents audit, suspension and online scores of SNO across all satellites.
|
2020-08-10 11:13:21 +01:00
|
|
|
type Audits struct {
|
2020-09-01 12:20:12 +01:00
|
|
|
AuditScore float64 `json:"auditScore"`
|
|
|
|
SuspensionScore float64 `json:"suspensionScore"`
|
|
|
|
OnlineScore float64 `json:"onlineScore"`
|
|
|
|
SatelliteName string `json:"satelliteName"`
|
2019-06-26 19:55:22 +01:00
|
|
|
}
|
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
// GetAllSatellitesData returns bandwidth and storage daily usage consolidate
|
|
|
|
// among all satellites from the node's trust pool.
|
|
|
|
func (s *Service) GetAllSatellitesData(ctx context.Context) (_ *Satellites, err error) {
|
|
|
|
defer mon.Task()(&ctx)(nil)
|
2019-09-06 13:01:03 +01:00
|
|
|
from, to := date.MonthBoundary(time.Now().UTC())
|
2019-07-02 13:05:58 +01:00
|
|
|
|
2020-08-10 11:13:21 +01:00
|
|
|
var audits []Audits
|
|
|
|
|
2019-09-04 15:01:55 +01:00
|
|
|
bandwidthDaily, err := s.bandwidthDB.GetDailyRollups(ctx, from, to)
|
2019-08-14 13:17:11 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
2019-07-02 13:05:58 +01:00
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
storageDaily, err := s.storageUsageDB.GetDailyTotal(ctx, from, to)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
2019-06-20 12:52:32 +01:00
|
|
|
|
2019-09-06 13:01:03 +01:00
|
|
|
bandwidthSummary, err := s.bandwidthDB.Summary(ctx, from, to)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2019-11-20 14:37:57 +00:00
|
|
|
egressSummary, err := s.bandwidthDB.EgressSummary(ctx, from, to)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ingressSummary, err := s.bandwidthDB.IngressSummary(ctx, from, to)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2019-09-06 13:01:03 +01:00
|
|
|
storageSummary, err := s.storageUsageDB.Summary(ctx, from, to)
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2020-04-13 16:00:14 +01:00
|
|
|
satellitesIDs := s.trust.GetSatellites(ctx)
|
|
|
|
joinedAt := time.Now().UTC()
|
2020-08-10 11:13:21 +01:00
|
|
|
|
2020-04-13 16:00:14 +01:00
|
|
|
for i := 0; i < len(satellitesIDs); i++ {
|
2020-04-16 16:40:28 +01:00
|
|
|
stats, err := s.reputationDB.Get(ctx, satellitesIDs[i])
|
2020-04-13 16:00:14 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2020-08-25 12:55:48 +01:00
|
|
|
url, err := s.trust.GetNodeURL(ctx, satellitesIDs[i])
|
|
|
|
if err != nil {
|
|
|
|
return nil, SNOServiceErr.Wrap(err)
|
|
|
|
}
|
|
|
|
|
2020-08-10 11:13:21 +01:00
|
|
|
audits = append(audits, Audits{
|
2020-09-01 12:20:12 +01:00
|
|
|
AuditScore: stats.Audit.Score,
|
|
|
|
SuspensionScore: stats.Audit.UnknownScore,
|
|
|
|
OnlineScore: stats.OnlineScore,
|
|
|
|
SatelliteName: url.Address,
|
2020-08-10 11:13:21 +01:00
|
|
|
})
|
2020-04-21 14:09:28 +01:00
|
|
|
if !stats.JoinedAt.IsZero() && stats.JoinedAt.Before(joinedAt) {
|
2020-04-16 16:40:28 +01:00
|
|
|
joinedAt = stats.JoinedAt
|
2020-04-13 16:00:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-14 13:17:11 +01:00
|
|
|
return &Satellites{
|
2019-09-06 13:01:03 +01:00
|
|
|
StorageDaily: storageDaily,
|
|
|
|
BandwidthDaily: bandwidthDaily,
|
|
|
|
StorageSummary: storageSummary,
|
|
|
|
BandwidthSummary: bandwidthSummary.Total(),
|
2019-11-20 14:37:57 +00:00
|
|
|
EgressSummary: egressSummary.Total(),
|
|
|
|
IngressSummary: ingressSummary.Total(),
|
2020-04-13 16:00:14 +01:00
|
|
|
EarliestJoinedAt: joinedAt,
|
2020-08-10 11:13:21 +01:00
|
|
|
Audits: audits,
|
2019-08-14 13:17:11 +01:00
|
|
|
}, nil
|
2019-06-20 12:52:32 +01:00
|
|
|
}
|
|
|
|
|
2020-09-08 16:15:08 +01:00
|
|
|
// GetSatelliteEstimatedPayout returns estimated payout for current and previous months for selected satellite.
|
|
|
|
func (s *Service) GetSatelliteEstimatedPayout(ctx context.Context, satelliteID storj.NodeID) (estimatedPayout estimatedpayout.EstimatedPayout, err error) {
|
|
|
|
estimatedPayout, err = s.estimation.GetSatelliteEstimatedPayout(ctx, satelliteID)
|
2019-08-14 13:17:11 +01:00
|
|
|
if err != nil {
|
2020-09-08 16:15:08 +01:00
|
|
|
return estimatedpayout.EstimatedPayout{}, SNOServiceErr.Wrap(err)
|
2019-08-14 13:17:11 +01:00
|
|
|
}
|
|
|
|
|
2020-09-08 16:15:08 +01:00
|
|
|
return estimatedPayout, nil
|
2019-06-20 12:52:32 +01:00
|
|
|
}
|
2020-05-10 12:23:13 +01:00
|
|
|
|
2020-09-08 16:15:08 +01:00
|
|
|
// GetAllSatellitesEstimatedPayout returns estimated payout for current and previous months for all satellites.
|
|
|
|
func (s *Service) GetAllSatellitesEstimatedPayout(ctx context.Context) (estimatedPayout estimatedpayout.EstimatedPayout, err error) {
|
|
|
|
estimatedPayout, err = s.estimation.GetAllSatellitesEstimatedPayout(ctx)
|
2020-05-10 12:23:13 +01:00
|
|
|
if err != nil {
|
2020-09-08 16:15:08 +01:00
|
|
|
return estimatedpayout.EstimatedPayout{}, SNOServiceErr.Wrap(err)
|
2020-05-10 12:23:13 +01:00
|
|
|
}
|
|
|
|
|
2020-09-08 16:15:08 +01:00
|
|
|
return estimatedPayout, nil
|
2020-05-10 12:23:13 +01:00
|
|
|
}
|
|
|
|
|
2020-09-08 16:15:08 +01:00
|
|
|
// VerifySatelliteID verifies if the satellite belongs to the trust pool.
|
|
|
|
func (s *Service) VerifySatelliteID(ctx context.Context, satelliteID storj.NodeID) (err error) {
|
2020-05-10 12:23:13 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
2020-09-08 16:15:08 +01:00
|
|
|
err = s.trust.VerifySatelliteID(ctx, satelliteID)
|
2020-05-10 12:23:13 +01:00
|
|
|
if err != nil {
|
2020-09-08 16:15:08 +01:00
|
|
|
return SNOServiceErr.Wrap(err)
|
2020-05-10 12:23:13 +01:00
|
|
|
}
|
|
|
|
|
2020-09-08 16:15:08 +01:00
|
|
|
return nil
|
2020-05-10 12:23:13 +01:00
|
|
|
}
|