From 25a944ebebbcc6e800ff722ee80cf26d74fab161 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 18 Jan 2024 19:25:21 -0800 Subject: [PATCH] introduce a new ServiceAction() API that uses the newer v2 API --- info-commands.go | 16 +++++++++- service-commands.go | 74 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/info-commands.go b/info-commands.go index 81e241aa..0b5c16f4 100644 --- a/info-commands.go +++ b/info-commands.go @@ -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"` } diff --git a/service-commands.go b/service-commands.go index 1069fba1..dceb7c6e 100644 --- a/service-commands.go +++ b/service-commands.go @@ -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 @@ -63,6 +67,68 @@ const ( ServiceActionUnfreeze = "unfreeze" ) +// 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 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 { queryValues := url.Values{}