satellite/console: update project usage-limits endpoint to also return buckets count/limit
Extended {projectID}/usage-limits endpoint to also return buckets count/limit. Issue: https://github.com/storj/storj/issues/6492 Change-Id: Ibc8956a2c10c9f383324e049f4b093410cbea899
This commit is contained in:
parent
6834c04539
commit
cfb7f55220
@ -590,6 +590,7 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB,
|
|||||||
peer.Mail.Service,
|
peer.Mail.Service,
|
||||||
externalAddress,
|
externalAddress,
|
||||||
consoleConfig.SatelliteName,
|
consoleConfig.SatelliteName,
|
||||||
|
config.Metainfo.ProjectLimits.MaxBuckets,
|
||||||
consoleConfig.Config,
|
consoleConfig.Config,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -118,6 +118,7 @@ func TestGraphqlMutation(t *testing.T) {
|
|||||||
nil,
|
nil,
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
|
sat.Config.Metainfo.ProjectLimits.MaxBuckets,
|
||||||
console.Config{
|
console.Config{
|
||||||
PasswordCost: console.TestPasswordCost,
|
PasswordCost: console.TestPasswordCost,
|
||||||
DefaultProjectLimit: 5,
|
DefaultProjectLimit: 5,
|
||||||
|
@ -102,6 +102,7 @@ func TestGraphqlQuery(t *testing.T) {
|
|||||||
nil,
|
nil,
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
|
sat.Config.Metainfo.ProjectLimits.MaxBuckets,
|
||||||
console.Config{
|
console.Config{
|
||||||
PasswordCost: console.TestPasswordCost,
|
PasswordCost: console.TestPasswordCost,
|
||||||
DefaultProjectLimit: 5,
|
DefaultProjectLimit: 5,
|
||||||
|
@ -15,6 +15,8 @@ type ProjectUsageLimits struct {
|
|||||||
SegmentLimit int64 `json:"segmentLimit"`
|
SegmentLimit int64 `json:"segmentLimit"`
|
||||||
RateUsed int64 `json:"rateUsed"`
|
RateUsed int64 `json:"rateUsed"`
|
||||||
SegmentUsed int64 `json:"segmentUsed"`
|
SegmentUsed int64 `json:"segmentUsed"`
|
||||||
|
BucketsUsed int64 `json:"bucketsUsed"`
|
||||||
|
BucketsLimit int64 `json:"bucketsLimit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsageLimits represents storage, bandwidth, and segment limits imposed on an entity.
|
// UsageLimits represents storage, bandwidth, and segment limits imposed on an entity.
|
||||||
|
@ -182,6 +182,7 @@ type Service struct {
|
|||||||
satelliteName string
|
satelliteName string
|
||||||
|
|
||||||
config Config
|
config Config
|
||||||
|
maxProjectBuckets int
|
||||||
|
|
||||||
nowFn func() time.Time
|
nowFn func() time.Time
|
||||||
}
|
}
|
||||||
@ -204,7 +205,7 @@ type Payments struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewService returns new instance of Service.
|
// NewService returns new instance of Service.
|
||||||
func NewService(log *zap.Logger, store DB, restKeys RESTKeys, projectAccounting accounting.ProjectAccounting, projectUsage *accounting.Service, buckets buckets.DB, accounts payments.Accounts, depositWallets payments.DepositWallets, billing billing.TransactionsDB, analytics *analytics.Service, tokens *consoleauth.Service, mailService *mailservice.Service, satelliteAddress string, satelliteName string, config Config) (*Service, error) {
|
func NewService(log *zap.Logger, store DB, restKeys RESTKeys, projectAccounting accounting.ProjectAccounting, projectUsage *accounting.Service, buckets buckets.DB, accounts payments.Accounts, depositWallets payments.DepositWallets, billing billing.TransactionsDB, analytics *analytics.Service, tokens *consoleauth.Service, mailService *mailservice.Service, satelliteAddress string, satelliteName string, maxProjectBuckets int, config Config) (*Service, error) {
|
||||||
if store == nil {
|
if store == nil {
|
||||||
return nil, errs.New("store can't be nil")
|
return nil, errs.New("store can't be nil")
|
||||||
}
|
}
|
||||||
@ -250,6 +251,7 @@ func NewService(log *zap.Logger, store DB, restKeys RESTKeys, projectAccounting
|
|||||||
mailService: mailService,
|
mailService: mailService,
|
||||||
satelliteAddress: satelliteAddress,
|
satelliteAddress: satelliteAddress,
|
||||||
satelliteName: satelliteName,
|
satelliteName: satelliteName,
|
||||||
|
maxProjectBuckets: maxProjectBuckets,
|
||||||
config: config,
|
config: config,
|
||||||
nowFn: time.Now,
|
nowFn: time.Now,
|
||||||
}, nil
|
}, nil
|
||||||
@ -2914,6 +2916,8 @@ func (s *Service) GetProjectUsageLimits(ctx context.Context, projectID uuid.UUID
|
|||||||
SegmentCount: prObjectsSegments.SegmentCount,
|
SegmentCount: prObjectsSegments.SegmentCount,
|
||||||
SegmentLimit: prUsageLimits.SegmentLimit,
|
SegmentLimit: prUsageLimits.SegmentLimit,
|
||||||
SegmentUsed: prUsageLimits.SegmentUsed,
|
SegmentUsed: prUsageLimits.SegmentUsed,
|
||||||
|
BucketsUsed: prUsageLimits.BucketsUsed,
|
||||||
|
BucketsLimit: prUsageLimits.BucketsLimit,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2993,6 +2997,20 @@ func (s *Service) getProjectUsageLimits(ctx context.Context, projectID uuid.UUID
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bucketsUsed, err := s.buckets.CountBuckets(ctx, projectID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
bucketsLimit, err := s.store.Projects().GetMaxBuckets(ctx, projectID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if bucketsLimit == nil {
|
||||||
|
bucketsLimit = &s.maxProjectBuckets
|
||||||
|
}
|
||||||
|
|
||||||
return &ProjectUsageLimits{
|
return &ProjectUsageLimits{
|
||||||
StorageLimit: storageLimit.Int64(),
|
StorageLimit: storageLimit.Int64(),
|
||||||
BandwidthLimit: bandwidthLimit.Int64(),
|
BandwidthLimit: bandwidthLimit.Int64(),
|
||||||
@ -3000,6 +3018,8 @@ func (s *Service) getProjectUsageLimits(ctx context.Context, projectID uuid.UUID
|
|||||||
BandwidthUsed: bandwidthUsed,
|
BandwidthUsed: bandwidthUsed,
|
||||||
SegmentLimit: segmentLimit.Int64(),
|
SegmentLimit: segmentLimit.Int64(),
|
||||||
SegmentUsed: segmentUsed,
|
SegmentUsed: segmentUsed,
|
||||||
|
BucketsUsed: int64(bucketsUsed),
|
||||||
|
BucketsLimit: int64(*bucketsLimit),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,6 +397,7 @@ func TestService(t *testing.T) {
|
|||||||
t.Run("GetProjectUsageLimits", func(t *testing.T) {
|
t.Run("GetProjectUsageLimits", func(t *testing.T) {
|
||||||
bandwidthLimit := sat.Config.Console.UsageLimits.Bandwidth.Free
|
bandwidthLimit := sat.Config.Console.UsageLimits.Bandwidth.Free
|
||||||
storageLimit := sat.Config.Console.UsageLimits.Storage.Free
|
storageLimit := sat.Config.Console.UsageLimits.Storage.Free
|
||||||
|
bucketsLimit := int64(sat.Config.Metainfo.ProjectLimits.MaxBuckets)
|
||||||
|
|
||||||
limits1, err := service.GetProjectUsageLimits(userCtx2, up2Proj.ID)
|
limits1, err := service.GetProjectUsageLimits(userCtx2, up2Proj.ID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -410,8 +411,12 @@ func TestService(t *testing.T) {
|
|||||||
// limits gotten by ID and publicID should be the same
|
// limits gotten by ID and publicID should be the same
|
||||||
require.Equal(t, storageLimit.Int64(), limits1.StorageLimit)
|
require.Equal(t, storageLimit.Int64(), limits1.StorageLimit)
|
||||||
require.Equal(t, bandwidthLimit.Int64(), limits1.BandwidthLimit)
|
require.Equal(t, bandwidthLimit.Int64(), limits1.BandwidthLimit)
|
||||||
|
require.Equal(t, int64(1), limits1.BucketsUsed)
|
||||||
|
require.Equal(t, bucketsLimit, limits1.BucketsLimit)
|
||||||
require.Equal(t, storageLimit.Int64(), limits2.StorageLimit)
|
require.Equal(t, storageLimit.Int64(), limits2.StorageLimit)
|
||||||
require.Equal(t, bandwidthLimit.Int64(), limits2.BandwidthLimit)
|
require.Equal(t, bandwidthLimit.Int64(), limits2.BandwidthLimit)
|
||||||
|
require.Equal(t, int64(1), limits2.BucketsUsed)
|
||||||
|
require.Equal(t, bucketsLimit, limits2.BucketsLimit)
|
||||||
|
|
||||||
// update project's limits
|
// update project's limits
|
||||||
updatedStorageLimit := memory.Size(100) + memory.TB
|
updatedStorageLimit := memory.Size(100) + memory.TB
|
||||||
@ -423,6 +428,10 @@ func TestService(t *testing.T) {
|
|||||||
err = sat.DB.Console().Projects().Update(ctx, up2Proj)
|
err = sat.DB.Console().Projects().Update(ctx, up2Proj)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
updatedBucketsLimit := 20
|
||||||
|
err = sat.DB.Console().Projects().UpdateBucketLimit(ctx, up2Proj.ID, updatedBucketsLimit)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
limits1, err = service.GetProjectUsageLimits(userCtx2, up2Proj.ID)
|
limits1, err = service.GetProjectUsageLimits(userCtx2, up2Proj.ID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, limits1)
|
require.NotNil(t, limits1)
|
||||||
@ -435,8 +444,10 @@ func TestService(t *testing.T) {
|
|||||||
// limits gotten by ID and publicID should be the same
|
// limits gotten by ID and publicID should be the same
|
||||||
require.Equal(t, updatedStorageLimit.Int64(), limits1.StorageLimit)
|
require.Equal(t, updatedStorageLimit.Int64(), limits1.StorageLimit)
|
||||||
require.Equal(t, updatedBandwidthLimit.Int64(), limits1.BandwidthLimit)
|
require.Equal(t, updatedBandwidthLimit.Int64(), limits1.BandwidthLimit)
|
||||||
|
require.Equal(t, int64(updatedBucketsLimit), limits1.BucketsLimit)
|
||||||
require.Equal(t, updatedStorageLimit.Int64(), limits2.StorageLimit)
|
require.Equal(t, updatedStorageLimit.Int64(), limits2.StorageLimit)
|
||||||
require.Equal(t, updatedBandwidthLimit.Int64(), limits2.BandwidthLimit)
|
require.Equal(t, updatedBandwidthLimit.Int64(), limits2.BandwidthLimit)
|
||||||
|
require.Equal(t, int64(updatedBucketsLimit), limits2.BucketsLimit)
|
||||||
|
|
||||||
bucket := "testbucket1"
|
bucket := "testbucket1"
|
||||||
err = planet.Uplinks[1].CreateBucket(ctx, sat, bucket)
|
err = planet.Uplinks[1].CreateBucket(ctx, sat, bucket)
|
||||||
@ -465,6 +476,7 @@ func TestService(t *testing.T) {
|
|||||||
limits2, err = service.GetProjectUsageLimits(userCtx2, up2Proj.PublicID)
|
limits2, err = service.GetProjectUsageLimits(userCtx2, up2Proj.PublicID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, limits2)
|
require.NotNil(t, limits2)
|
||||||
|
require.Equal(t, int64(2), limits2.BucketsUsed)
|
||||||
require.Equal(t, allocatedAmount, limits2.BandwidthUsed)
|
require.Equal(t, allocatedAmount, limits2.BandwidthUsed)
|
||||||
|
|
||||||
// set now as fourth day of the month.
|
// set now as fourth day of the month.
|
||||||
|
@ -96,6 +96,7 @@ func TestSignupCouponCodes(t *testing.T) {
|
|||||||
nil,
|
nil,
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
|
sat.Config.Metainfo.ProjectLimits.MaxBuckets,
|
||||||
console.Config{PasswordCost: console.TestPasswordCost, DefaultProjectLimit: 5},
|
console.Config{PasswordCost: console.TestPasswordCost, DefaultProjectLimit: 5},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user