From a39fd4f9e1550576196ecbae7a80df9e8867dd6b Mon Sep 17 00:00:00 2001 From: Shubhendu Ram Tripathi Date: Tue, 5 Dec 2023 18:01:16 +0530 Subject: [PATCH] Incorporated review comments Signed-off-by: Shubhendu Ram Tripathi --- quota-commands.go | 25 ++++++++-- throttle-commands.go | 109 ------------------------------------------- 2 files changed, 20 insertions(+), 114 deletions(-) delete mode 100644 throttle-commands.go diff --git a/quota-commands.go b/quota-commands.go index 553ba41..c412b49 100644 --- a/quota-commands.go +++ b/quota-commands.go @@ -40,13 +40,20 @@ func (t QuotaType) IsValid() bool { return t == HardQuota } +// BucketThrottleRule holds a bucket throttle rule +type BucketThrottleRule struct { + ConcurrentRequestsCount uint64 `json:"concurrentRequestsCount"` // indicates no of concurrent requests + APIs []string `json:"apis"` // indicates list of APIs +} + // BucketQuota holds bucket quota restrictions type BucketQuota struct { - Quota uint64 `json:"quota"` // Deprecated Aug 2023 - Size uint64 `json:"size"` // Indicates maximum size allowed per bucket - Rate uint64 `json:"rate"` // Indicates bandwidth rate allocated per bucket - Requests uint64 `json:"requests"` // Indicates number of requests allocated per bucket - Type QuotaType `json:"quotatype,omitempty"` + Quota uint64 `json:"quota"` // Deprecated Aug 2023 + Size uint64 `json:"size"` // Indicates maximum size allowed per bucket + Rate uint64 `json:"rate"` // Indicates bandwidth rate allocated per bucket + Requests uint64 `json:"requests"` // Indicates number of requests allocated per bucket + Type QuotaType `json:"quotatype,omitempty"` + ThrottleRules []BucketThrottleRule `json:"throttleRules"` // indocates list of throttle rules per bucket } // IsValid returns false if quota is invalid @@ -55,6 +62,14 @@ func (q BucketQuota) IsValid() bool { if q.Quota > 0 { return q.Type.IsValid() } + if len(q.ThrottleRules) > 0 { + // if any throttle rule invalid, return false + for _, rule := range q.ThrottleRules { + if rule.ConcurrentRequestsCount <= 0 || len(rule.APIs) <= 0 { + return false + } + } + } // Empty configs are valid. return true } diff --git a/throttle-commands.go b/throttle-commands.go deleted file mode 100644 index 2b40771..0000000 --- a/throttle-commands.go +++ /dev/null @@ -1,109 +0,0 @@ -// -// Copyright (c) 2015-2022 MinIO, Inc. -// -// This file is part of MinIO Object Storage stack -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . -// - -package madmin - -import ( - "context" - "encoding/json" - "io/ioutil" - "net/http" - "net/url" - - "github.com/minio/minio-go/v7/pkg/throttle" -) - -// BucketThrottle holds bucket throttle -type BucketThrottle struct { - ConcurrentRequestsCount uint64 `json:"concurrentRequestsCount"` // Indicates concurrent no of requets - APIs []string `json:"apis"` // Indicates S3 APIs for which the above throttle to be applied -} - -// IsValid returns false if throttle configuration is invalid -func (t BucketThrottle) IsValid() bool { - if t.ConcurrentRequestsCount > 0 && len(t.APIs) > 0 { - return true - } - // empty throttle configuration is invalid - return false -} - -// GetBucketThrottle - get throttle info for a bucket -func (adm *AdminClient) GetBucketThrottle(ctx context.Context, bucket string) (t throttle.Configuration, err error) { - queryValues := url.Values{} - queryValues.Set("bucket", bucket) - - reqData := requestData{ - relPath: adminAPIPrefix + "/get-bucket-throttle", - queryValues: queryValues, - } - - // Execute GET on /minio/admin/v3/get-throttle - resp, err := adm.executeMethod(ctx, http.MethodGet, reqData) - - defer closeResponse(resp) - if err != nil { - return t, err - } - - if resp.StatusCode != http.StatusOK { - return t, httpRespToErrorResponse(resp) - } - - b, err := ioutil.ReadAll(resp.Body) - if err != nil { - return t, err - } - if err = json.Unmarshal(b, &t); err != nil { - return t, err - } - - return t, nil -} - -// SetBucketThrottle - sets a bucket's throttle values -func (adm *AdminClient) SetBucketThrottle(ctx context.Context, bucket string, t throttle.Configuration) error { - data, err := json.Marshal(t) - if err != nil { - return err - } - - queryValues := url.Values{} - queryValues.Set("bucket", bucket) - - reqData := requestData{ - relPath: adminAPIPrefix + "/set-bucket-throttle", - queryValues: queryValues, - content: data, - } - - // Execute PUT on /minio/admin/v3/set-bucket-throttle - resp, err := adm.executeMethod(ctx, http.MethodPut, reqData) - - defer closeResponse(resp) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - return httpRespToErrorResponse(resp) - } - - return nil -}