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 25a944e
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 5 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
74 changes: 70 additions & 4 deletions service-commands.go
Original file line number Diff line number Diff line change
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, ServiceCallOpts{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, ServiceCallOpts{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, ServiceCallOpts{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, ServiceCallOpts{Action: ServiceActionUnfreeze})
return err
}

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

// ServiceActionOpts specifies the action that the service is requested

Check failure on line 70 in service-commands.go

View workflow job for this annotation

GitHub Actions / Lint checks Go 1.21.x

exported: comment on exported type ServiceCallOpts should be of the form "ServiceCallOpts ..." (with optional leading article) (revive)
// to take, dryRun indicates if the action is a no-op, force indicates
// that server must make best effort to restart the process.
type ServiceCallOpts struct {
Action ServiceAction
DryRun bool
Force bool
}

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

// ServiceResult service action result
type ServiceResult struct {
Action ServiceAction `json:"action"`
Forced bool `json:"forced"`
DryRun bool `json:"dryRun"`
Results []ServicePeerResult `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 ServiceCallOpts) (ServiceResult, error) {
return adm.serviceCallActionV2(ctx, opts)
}

// serviceCallActionV2 - call service restart/stop/freeze/unfreeze
func (adm *AdminClient) serviceCallActionV2(ctx context.Context, opts ServiceCallOpts) (ServiceResult, error) {
queryValues := url.Values{}
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,
http.MethodPost, requestData{
relPath: adminAPIPrefix + "/service",
queryValues: queryValues,
},
)
defer closeResponse(resp)
if err != nil {
return ServiceResult{}, err
}

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

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

return srvRes, nil
}

// serviceCallAction - call service restart/update/stop API.
func (adm *AdminClient) serviceCallAction(ctx context.Context, action ServiceAction) error {

Check failure on line 133 in service-commands.go

View workflow job for this annotation

GitHub Actions / Lint checks Go 1.21.x

func `(*AdminClient).serviceCallAction` is unused (unused)
queryValues := url.Values{}
Expand Down

0 comments on commit 25a944e

Please sign in to comment.