improve user messaging in 'support perf' and 'mc rm --dry-run' (#4617)
- terminal messaging for 'mc rm --dry-run' was completely wrong, it was using `fmt.Println` which shouldn't be done. - mc support perf - printing was using a mix of color.New() and console.Infoln() (use one) - mc support profile - printing was using a mix of color.New() and console.Info() (use one) - mc support inspect - printing was using a mix of color.New() and consoleInfo() (use one)
This commit is contained in:
+28
-14
@@ -172,22 +172,31 @@ EXAMPLES:
|
||||
|
||||
// Structured message depending on the type of console.
|
||||
type rmMessage struct {
|
||||
Status string `json:"status"`
|
||||
Key string `json:"key"`
|
||||
DeleteMarker bool `json:"deleteMarker"`
|
||||
VersionID string `json:"versionID"`
|
||||
Status string `json:"status"`
|
||||
Key string `json:"key"`
|
||||
DeleteMarker bool `json:"deleteMarker"`
|
||||
VersionID string `json:"versionID"`
|
||||
ModTime *time.Time `json:"modTime"`
|
||||
DryRun bool `json:"dryRun"`
|
||||
}
|
||||
|
||||
// Colorized message for console printing.
|
||||
func (r rmMessage) String() string {
|
||||
msg := "Removed "
|
||||
if r.DryRun {
|
||||
msg = "DRYRUN: Removing "
|
||||
}
|
||||
|
||||
if r.DeleteMarker {
|
||||
msg = "Created delete marker "
|
||||
}
|
||||
|
||||
msg += console.Colorize("Removed", fmt.Sprintf("`%s`", r.Key))
|
||||
if r.VersionID != "" {
|
||||
msg += fmt.Sprintf(" (versionId=%s)", r.VersionID)
|
||||
if r.ModTime != nil {
|
||||
msg += fmt.Sprintf(" (modTime=%s)", r.ModTime.Format(printDate))
|
||||
}
|
||||
}
|
||||
msg += "."
|
||||
return msg
|
||||
@@ -322,8 +331,8 @@ func removeSingle(url, versionID string, opts removeOpts) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
targetAlias, targetURL, _ := mustExpandAlias(url)
|
||||
if !opts.isFake {
|
||||
targetAlias, targetURL, _ := mustExpandAlias(url)
|
||||
clnt, pErr := newClientFromAlias(targetAlias, targetURL)
|
||||
if pErr != nil {
|
||||
errorIf(pErr.Trace(url), "Invalid argument `"+url+"`.")
|
||||
@@ -361,7 +370,7 @@ func removeSingle(url, versionID string, opts removeOpts) error {
|
||||
printMsg(msg)
|
||||
}
|
||||
} else {
|
||||
printDryRunMsg(content, opts.withVersions)
|
||||
printDryRunMsg(targetAlias, content, opts.withVersions)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -381,15 +390,20 @@ type removeOpts struct {
|
||||
encKeyDB map[string][]prefixSSEPair
|
||||
}
|
||||
|
||||
func printDryRunMsg(content *ClientContent, printModTime bool) {
|
||||
if globalJSON || content == nil {
|
||||
func printDryRunMsg(targetAlias string, content *ClientContent, printModTime bool) {
|
||||
if content == nil {
|
||||
return
|
||||
}
|
||||
msg := rmMessage{
|
||||
Status: "success",
|
||||
DryRun: true,
|
||||
Key: targetAlias + getKey(content),
|
||||
VersionID: content.VersionID,
|
||||
}
|
||||
if printModTime {
|
||||
fmt.Println("DRYRUN: Removing ", content.VersionID, content.Time.Format(printDate), content.URL.Path)
|
||||
return
|
||||
msg.ModTime = &content.Time
|
||||
}
|
||||
fmt.Println("DRYRUN: Removing ", content.URL.Path)
|
||||
printMsg(msg)
|
||||
}
|
||||
|
||||
// listAndRemove uses listing before removal, it can list recursively or not, with versions or not.
|
||||
@@ -472,7 +486,7 @@ func listAndRemove(url string, opts removeOpts) error {
|
||||
}
|
||||
|
||||
if opts.isFake {
|
||||
printDryRunMsg(content, true)
|
||||
printDryRunMsg(targetAlias, content, true)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -568,7 +582,7 @@ func listAndRemove(url string, opts removeOpts) error {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printDryRunMsg(content, opts.withVersions)
|
||||
printDryRunMsg(targetAlias, content, opts.withVersions)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -593,7 +607,7 @@ func listAndRemove(url string, opts removeOpts) error {
|
||||
}
|
||||
|
||||
if opts.isFake {
|
||||
printDryRunMsg(content, true)
|
||||
printDryRunMsg(targetAlias, content, true)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -197,8 +197,7 @@ func mainSupportInspect(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
clr := color.New(color.FgGreen, color.Bold)
|
||||
clr.Println("uploaded successfully to SUBNET.")
|
||||
console.Infof("Object inspection data for '%s' uploaded to SUBNET successfully\n", aliasedURL)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+8
-10
@@ -25,7 +25,6 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
@@ -233,7 +232,7 @@ func (p PerfTestOutput) String() string {
|
||||
// JSON - jsonified output of the perf tests
|
||||
func (p PerfTestOutput) JSON() string {
|
||||
JSONBytes, e := json.MarshalIndent(p, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON")
|
||||
return string(JSONBytes)
|
||||
}
|
||||
|
||||
@@ -404,17 +403,17 @@ func execSupportPerf(ctx *cli.Context, aliasedURL string, perfType string) {
|
||||
|
||||
// If results still not available, don't write anything
|
||||
if len(results) == 0 {
|
||||
clr := color.New(color.FgRed, color.Bold)
|
||||
clr.Println("Nothing available to upload to SUBNET yet.")
|
||||
console.Fatalln("No performance reports were captured, please report this issue")
|
||||
} else {
|
||||
resultFileNamePfx := fmt.Sprintf("%s-perf_%s", filepath.Clean(alias), UTCNow().Format("20060102150405"))
|
||||
resultFileName := resultFileNamePfx + ".json"
|
||||
|
||||
regInfo := getClusterRegInfo(getAdminInfo(aliasedURL), alias)
|
||||
tmpFileName, e := zipPerfResult(convertPerfResults(results), resultFileName, regInfo)
|
||||
fatalIf(probe.NewError(e), "Error creating zip from perf test results:")
|
||||
fatalIf(probe.NewError(e), "Unable to generate zip file from performance results")
|
||||
|
||||
if globalAirgapped {
|
||||
console.Infoln()
|
||||
savePerfResultFile(tmpFileName, resultFileNamePfx)
|
||||
return
|
||||
}
|
||||
@@ -424,21 +423,20 @@ func execSupportPerf(ctx *cli.Context, aliasedURL string, perfType string) {
|
||||
|
||||
_, e = uploadFileToSubnet(alias, tmpFileName, reqURL, headers)
|
||||
if e != nil {
|
||||
console.Errorln("Unable to upload perf test results to SUBNET portal: " + e.Error())
|
||||
errorIf(probe.NewError(e), "Unable to upload performance results to SUBNET portal")
|
||||
savePerfResultFile(tmpFileName, resultFileNamePfx)
|
||||
return
|
||||
}
|
||||
|
||||
clr := color.New(color.FgGreen, color.Bold)
|
||||
clr.Println("uploaded successfully to SUBNET.")
|
||||
console.Infoln("Uploaded performance report to SUBNET successfully")
|
||||
}
|
||||
}
|
||||
|
||||
func savePerfResultFile(tmpFileName string, resultFileNamePfx string) {
|
||||
zipFileName := resultFileNamePfx + ".zip"
|
||||
e := moveFile(tmpFileName, zipFileName)
|
||||
fatalIf(probe.NewError(e), fmt.Sprintf("Error moving temp file %s to %s:", tmpFileName, zipFileName))
|
||||
console.Infoln("MinIO performance report saved at", zipFileName)
|
||||
fatalIf(probe.NewError(e), fmt.Sprintf("Unable to move %s -> %s", tmpFileName, zipFileName))
|
||||
console.Infof("MinIO performance report saved at %s, please upload to SUBNET portal manually\n", zipFileName)
|
||||
}
|
||||
|
||||
func runPerfTests(ctx *cli.Context, aliasedURL string, perfType string) []PerfTestResult {
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
@@ -197,23 +196,21 @@ func execSupportProfile(ctx *cli.Context, client *madmin.AdminClient, alias stri
|
||||
reqURL, headers = prepareSubnetUploadURL(uploadURL, alias, apiKey)
|
||||
}
|
||||
|
||||
console.Infof("Profiling '%s' for %d seconds... ", alias, duration)
|
||||
console.Infof("Profiling '%s' for %d seconds... \n", alias, duration)
|
||||
data, e := client.Profile(globalContext, madmin.ProfilerType(profilers), time.Second*time.Duration(duration))
|
||||
fatalIf(probe.NewError(e), "Unable to save profile data")
|
||||
|
||||
saveProfileFile(data)
|
||||
|
||||
successClr := color.New(color.FgGreen, color.Bold)
|
||||
failureClr := color.New(color.FgRed, color.Bold)
|
||||
if !globalAirgapped {
|
||||
_, e := uploadFileToSubnet(alias, profileFile, reqURL, headers)
|
||||
_, e = uploadFileToSubnet(alias, profileFile, reqURL, headers)
|
||||
if e != nil {
|
||||
failureClr.Println("\nUnable to upload profile file to SUBNET:", e.Error())
|
||||
successClr.Printf("Profiling data are saved locally at '%s'\n", profileFile)
|
||||
errorIf(probe.NewError(e), "Unable to upload profile file to SUBNET")
|
||||
console.Infof("Profiling data saved locally at '%s'\n", profileFile)
|
||||
return
|
||||
}
|
||||
successClr.Println("uploaded successfully to SUBNET.")
|
||||
console.Infoln("Profiling data uploaded to SUBNET successfully")
|
||||
} else {
|
||||
successClr.Printf("saved successfully at '%s'\n", profileFile)
|
||||
console.Infoln("Profiling data saved successfully at", profileFile)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user