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:
Harshavardhana
2020-03-20 15:00:44 -07:00
committed by GitHub
parent 1ffa983a9d
commit ae654831aa
47 changed files with 398 additions and 213 deletions

View File

@@ -17,18 +17,17 @@
package madmin
import (
"context"
"encoding/json"
"net/http"
"net/url"
"strconv"
"strings"
"github.com/minio/minio/cmd/logger/message/log"
)
// LogInfo holds console log messages
type LogInfo struct {
log.Entry
logEntry
ConsoleMsg string
NodeName string `json:"node"`
Err error `json:"-"`
@@ -42,7 +41,7 @@ func (l LogInfo) SendLog(node, logKind string) bool {
}
// GetLogs - listen on console log messages.
func (adm AdminClient) GetLogs(node string, lineCnt int, logKind string, doneCh <-chan struct{}) <-chan LogInfo {
func (adm AdminClient) GetLogs(ctx context.Context, node string, lineCnt int, logKind string) <-chan LogInfo {
logCh := make(chan LogInfo, 1)
// Only success, start a routine to start reading line by line.
@@ -58,7 +57,7 @@ func (adm AdminClient) GetLogs(node string, lineCnt int, logKind string, doneCh
queryValues: urlValues,
}
// Execute GET to call log handler
resp, err := adm.executeMethod("GET", reqData)
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
if err != nil {
closeResponse(resp)
return
@@ -75,7 +74,7 @@ func (adm AdminClient) GetLogs(node string, lineCnt int, logKind string, doneCh
break
}
select {
case <-doneCh:
case <-ctx.Done():
return
case logCh <- info:
}