mirror of
https://github.com/minio/minio.git
synced 2025-11-28 05:04:14 -05:00
Add madmin package context support (#9172)
This is to improve responsiveness for all admin API operations and allowing callers to cancel any on-going admin operations, if they happen to be waiting too long.
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
package madmin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
@@ -114,8 +115,8 @@ func (d1 BackendDisks) Merge(d2 BackendDisks) BackendDisks {
|
||||
|
||||
// StorageInfo - Connect to a minio server and call Storage Info Management API
|
||||
// to fetch server's information represented by StorageInfo structure
|
||||
func (adm *AdminClient) StorageInfo() (StorageInfo, error) {
|
||||
resp, err := adm.executeMethod("GET", requestData{relPath: adminAPIPrefix + "/storageinfo"})
|
||||
func (adm *AdminClient) StorageInfo(ctx context.Context) (StorageInfo, error) {
|
||||
resp, err := adm.executeMethod(ctx, http.MethodGet, requestData{relPath: adminAPIPrefix + "/storageinfo"})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
return StorageInfo{}, err
|
||||
@@ -178,8 +179,8 @@ type DataUsageInfo struct {
|
||||
}
|
||||
|
||||
// DataUsageInfo - returns data usage of the current object API
|
||||
func (adm *AdminClient) DataUsageInfo() (DataUsageInfo, error) {
|
||||
resp, err := adm.executeMethod("GET", requestData{relPath: adminAPIPrefix + "/datausageinfo"})
|
||||
func (adm *AdminClient) DataUsageInfo(ctx context.Context) (DataUsageInfo, error) {
|
||||
resp, err := adm.executeMethod(ctx, http.MethodGet, requestData{relPath: adminAPIPrefix + "/datausageinfo"})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
return DataUsageInfo{}, err
|
||||
@@ -222,8 +223,8 @@ type BucketAccountingUsage struct {
|
||||
|
||||
// AccountingUsageInfo returns the accounting usage info, currently it returns
|
||||
// the type of access of different accounts to the different buckets.
|
||||
func (adm *AdminClient) AccountingUsageInfo() (map[string]BucketAccountingUsage, error) {
|
||||
resp, err := adm.executeMethod(http.MethodGet, requestData{relPath: adminAPIPrefix + "/accountingusageinfo"})
|
||||
func (adm *AdminClient) AccountingUsageInfo(ctx context.Context) (map[string]BucketAccountingUsage, error) {
|
||||
resp, err := adm.executeMethod(ctx, http.MethodGet, requestData{relPath: adminAPIPrefix + "/accountingusageinfo"})
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -260,16 +261,18 @@ type ServerDrivesPerfInfo struct {
|
||||
}
|
||||
|
||||
// ServerDrivesPerfInfo - Returns drive's read and write performance information
|
||||
func (adm *AdminClient) ServerDrivesPerfInfo(size int64) ([]ServerDrivesPerfInfo, error) {
|
||||
func (adm *AdminClient) ServerDrivesPerfInfo(ctx context.Context, size int64) ([]ServerDrivesPerfInfo, error) {
|
||||
v := url.Values{}
|
||||
v.Set("perfType", string("drive"))
|
||||
|
||||
v.Set("size", strconv.FormatInt(size, 10))
|
||||
|
||||
resp, err := adm.executeMethod("GET", requestData{
|
||||
relPath: adminAPIPrefix + "/performance",
|
||||
queryValues: v,
|
||||
})
|
||||
resp, err := adm.executeMethod(ctx, http.MethodGet,
|
||||
requestData{
|
||||
relPath: adminAPIPrefix + "/performance",
|
||||
queryValues: v,
|
||||
},
|
||||
)
|
||||
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
@@ -307,13 +310,15 @@ type ServerCPULoadInfo struct {
|
||||
}
|
||||
|
||||
// ServerCPULoadInfo - Returns cpu utilization information
|
||||
func (adm *AdminClient) ServerCPULoadInfo() ([]ServerCPULoadInfo, error) {
|
||||
func (adm *AdminClient) ServerCPULoadInfo(ctx context.Context) ([]ServerCPULoadInfo, error) {
|
||||
v := url.Values{}
|
||||
v.Set("perfType", string("cpu"))
|
||||
resp, err := adm.executeMethod("GET", requestData{
|
||||
relPath: adminAPIPrefix + "/performance",
|
||||
queryValues: v,
|
||||
})
|
||||
resp, err := adm.executeMethod(ctx,
|
||||
http.MethodGet, requestData{
|
||||
relPath: adminAPIPrefix + "/performance",
|
||||
queryValues: v,
|
||||
},
|
||||
)
|
||||
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
@@ -351,13 +356,16 @@ type ServerMemUsageInfo struct {
|
||||
}
|
||||
|
||||
// ServerMemUsageInfo - Returns mem utilization information
|
||||
func (adm *AdminClient) ServerMemUsageInfo() ([]ServerMemUsageInfo, error) {
|
||||
func (adm *AdminClient) ServerMemUsageInfo(ctx context.Context) ([]ServerMemUsageInfo, error) {
|
||||
v := url.Values{}
|
||||
v.Set("perfType", string("mem"))
|
||||
resp, err := adm.executeMethod("GET", requestData{
|
||||
relPath: adminAPIPrefix + "/performance",
|
||||
queryValues: v,
|
||||
})
|
||||
resp, err := adm.executeMethod(ctx,
|
||||
http.MethodGet,
|
||||
requestData{
|
||||
relPath: adminAPIPrefix + "/performance",
|
||||
queryValues: v,
|
||||
},
|
||||
)
|
||||
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
@@ -393,16 +401,19 @@ type NetPerfInfo struct {
|
||||
}
|
||||
|
||||
// NetPerfInfo - Returns network performance information of all cluster nodes.
|
||||
func (adm *AdminClient) NetPerfInfo(size int) (map[string][]NetPerfInfo, error) {
|
||||
func (adm *AdminClient) NetPerfInfo(ctx context.Context, size int) (map[string][]NetPerfInfo, error) {
|
||||
v := url.Values{}
|
||||
v.Set("perfType", "net")
|
||||
if size > 0 {
|
||||
v.Set("size", strconv.Itoa(size))
|
||||
}
|
||||
resp, err := adm.executeMethod("GET", requestData{
|
||||
relPath: adminAPIPrefix + "/performance",
|
||||
queryValues: v,
|
||||
})
|
||||
resp, err := adm.executeMethod(ctx,
|
||||
http.MethodGet,
|
||||
requestData{
|
||||
relPath: adminAPIPrefix + "/performance",
|
||||
queryValues: v,
|
||||
},
|
||||
)
|
||||
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
@@ -509,13 +520,13 @@ const (
|
||||
ErasureType = backendType("Erasure")
|
||||
)
|
||||
|
||||
// FsBackend contains specific FS storage information
|
||||
type FsBackend struct {
|
||||
// FSBackend contains specific FS storage information
|
||||
type FSBackend struct {
|
||||
Type backendType `json:"backendType,omitempty"`
|
||||
}
|
||||
|
||||
// XlBackend contains specific erasure storage information
|
||||
type XlBackend struct {
|
||||
// XLBackend contains specific erasure storage information
|
||||
type XLBackend struct {
|
||||
Type backendType `json:"backendType,omitempty"`
|
||||
OnlineDisks int `json:"onlineDisks,omitempty"`
|
||||
OfflineDisks int `json:"offlineDisks,omitempty"`
|
||||
@@ -557,9 +568,11 @@ type Disk struct {
|
||||
|
||||
// ServerInfo - Connect to a minio server and call Server Admin Info Management API
|
||||
// to fetch server's information represented by infoMessage structure
|
||||
func (adm *AdminClient) ServerInfo() (InfoMessage, error) {
|
||||
|
||||
resp, err := adm.executeMethod("GET", requestData{relPath: adminAPIPrefix + "/info"})
|
||||
func (adm *AdminClient) ServerInfo(ctx context.Context) (InfoMessage, error) {
|
||||
resp, err := adm.executeMethod(ctx,
|
||||
http.MethodGet,
|
||||
requestData{relPath: adminAPIPrefix + "/info"},
|
||||
)
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
return InfoMessage{}, err
|
||||
|
||||
Reference in New Issue
Block a user