Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce a new ServiceAction() API that uses the newer v2 API #263

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion info-commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,25 @@ type ServerProperties struct {
type DiskMetrics struct {
LastMinute map[string]TimedAction `json:"lastMinute,omitempty"`
APICalls map[string]uint64 `json:"apiCalls,omitempty"`
// Captures all data availability errors such as permission denied, faulty disk and timeout errors.

// TotalTokens set per drive max concurrent I/O.
TotalTokens uint32 `json:"totalTokens,omitempty"`
// TotalWaiting the amount of concurrent I/O waiting on disk
TotalWaiting uint32 `json:"totalWaiting,omitempty"`

// Captures all data availability errors such as
// permission denied, faulty disk and timeout errors.
TotalErrorsAvailability uint64 `json:"totalErrorsAvailability,omitempty"`
// Captures all timeout only errors
TotalErrorsTimeout uint64 `json:"totalErrorsTimeout,omitempty"`

// Total writes on disk (could be empty if the feature
// is not enabled on the server)
TotalWrites uint64 `json:"totalWrites,omitempty"`
// Total deletes on disk (could be empty if the feature
// is not enabled on the server)
TotalDeletes uint64 `json:"totalDeletes,omitempty"`

// Deprecated: Use LastMinute instead. Not populated from servers after July 2022.
APILatencies map[string]interface{} `json:"apiLatencies,omitempty"`
}
Expand Down
64 changes: 53 additions & 11 deletions service-commands.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2015-2022 MinIO, Inc.
// Copyright (c) 2015-2024 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
Expand Down Expand Up @@ -31,22 +31,26 @@ import (

// ServiceRestart - restarts the MinIO cluster
func (adm *AdminClient) ServiceRestart(ctx context.Context) error {
return adm.serviceCallAction(ctx, ServiceActionRestart)
_, err := adm.serviceCallActionV2(ctx, ServiceActionOpts{Action: ServiceActionRestart})
return err
}

// ServiceStop - stops the MinIO cluster
func (adm *AdminClient) ServiceStop(ctx context.Context) error {
return adm.serviceCallAction(ctx, ServiceActionStop)
_, err := adm.serviceCallActionV2(ctx, ServiceActionOpts{Action: ServiceActionStop})
return err
}

// ServiceFreeze - freezes all incoming S3 API calls on MinIO cluster
func (adm *AdminClient) ServiceFreeze(ctx context.Context) error {
return adm.serviceCallAction(ctx, ServiceActionFreeze)
_, err := adm.serviceCallActionV2(ctx, ServiceActionOpts{Action: ServiceActionFreeze})
return err
}

// ServiceUnfreeze - un-freezes all incoming S3 API calls on MinIO cluster
func (adm *AdminClient) ServiceUnfreeze(ctx context.Context) error {
return adm.serviceCallAction(ctx, ServiceActionUnfreeze)
_, err := adm.serviceCallActionV2(ctx, ServiceActionOpts{Action: ServiceActionUnfreeze})
return err
}

// ServiceAction - type to restrict service-action values
Expand All @@ -63,10 +67,42 @@ const (
ServiceActionUnfreeze = "unfreeze"
)

// serviceCallAction - call service restart/update/stop API.
func (adm *AdminClient) serviceCallAction(ctx context.Context, action ServiceAction) error {
// ServiceActionOpts specifies the action that the service is requested
// to take, dryRun indicates if the action is a no-op, force indicates
// that server must make best effort to restart the process.
type ServiceActionOpts struct {
Action ServiceAction
DryRun bool
Force bool
}

// ServiceActionPeerResult service peer result
type ServiceActionPeerResult struct {
Host string `json:"host"`
Err string `json:"err,omitempty"`
WaitingDrives map[string]DiskMetrics `json:"waitingDrives,omitempty"`
}

// ServiceActionResult service action result
type ServiceActionResult struct {
Action ServiceAction `json:"action"`
Forced bool `json:"forced"`
DryRun bool `json:"dryRun"`
Results []ServiceActionPeerResult `json:"results,omitempty"`
}

// ServiceAction - specify the type of service action that we are requesting the server to perform
func (adm *AdminClient) ServiceAction(ctx context.Context, opts ServiceActionOpts) (ServiceActionResult, error) {
return adm.serviceCallActionV2(ctx, opts)
}

// serviceCallActionV2 - call service restart/stop/freeze/unfreeze
func (adm *AdminClient) serviceCallActionV2(ctx context.Context, opts ServiceActionOpts) (ServiceActionResult, error) {
queryValues := url.Values{}
queryValues.Set("action", string(action))
queryValues.Set("action", string(opts.Action))
queryValues.Set("dry-run", strconv.FormatBool(opts.DryRun))
queryValues.Set("force", strconv.FormatBool(opts.Force))
queryValues.Set("type", "2")

// Request API to Restart server
resp, err := adm.executeMethod(ctx,
Expand All @@ -77,14 +113,20 @@ func (adm *AdminClient) serviceCallAction(ctx context.Context, action ServiceAct
)
defer closeResponse(resp)
if err != nil {
return err
return ServiceActionResult{}, err
}

if resp.StatusCode != http.StatusOK {
return httpRespToErrorResponse(resp)
return ServiceActionResult{}, httpRespToErrorResponse(resp)
}

return nil
srvRes := ServiceActionResult{}
dec := json.NewDecoder(resp.Body)
if err = dec.Decode(&srvRes); err != nil {
return ServiceActionResult{}, err
}

return srvRes, nil
}

// ServiceTraceInfo holds http trace
Expand Down
Loading