Skip to content

Commit

Permalink
introduce a new ServiceAction() API that uses the newer v2 API
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana committed Jan 19, 2024
1 parent c0303b5 commit 815d3da
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 12 deletions.
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

0 comments on commit 815d3da

Please sign in to comment.