Move mc admin top scanner -> mc admin scanner info (#4151)
Also, add `mc admin scanner trace` which gives a simplified trace with only relevant options.
This commit is contained in:
@@ -49,6 +49,7 @@ var adminCmdSubcommands = []cli.Command{
|
||||
adminTierCmd,
|
||||
adminSpeedtestCmd,
|
||||
adminProfileCmd,
|
||||
adminScannerCmd,
|
||||
adminTopCmd,
|
||||
adminTraceCmd,
|
||||
adminConsoleCmd,
|
||||
|
||||
@@ -39,7 +39,7 @@ import (
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
var adminTopScannerFlags = []cli.Flag{
|
||||
var adminScannerInfoFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "nodes",
|
||||
Usage: "show only on matching servers, comma separate multiple",
|
||||
@@ -61,13 +61,13 @@ var adminTopScannerFlags = []cli.Flag{
|
||||
},
|
||||
}
|
||||
|
||||
var adminTopScannerCmd = cli.Command{
|
||||
Name: "scanner",
|
||||
var adminScannerInfo = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "summarize scanner events on MinIO server in real-time",
|
||||
Action: mainAdminTopScanner,
|
||||
Action: mainAdminScannerInfo,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminTopScannerFlags, globalFlags...),
|
||||
Flags: append(adminScannerInfoFlags, globalFlags...),
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
@@ -85,14 +85,14 @@ EXAMPLES:
|
||||
}
|
||||
|
||||
// checkAdminTopAPISyntax - validate all the passed arguments
|
||||
func checkAdminTopScannerSyntax(ctx *cli.Context) {
|
||||
func checkAdminScannerInfoSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "scanner", 1) // last argument is exit code
|
||||
cli.ShowCommandHelpAndExit(ctx, "info", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
func mainAdminTopScanner(ctx *cli.Context) error {
|
||||
checkAdminTopScannerSyntax(ctx)
|
||||
func mainAdminScannerInfo(ctx *cli.Context) error {
|
||||
checkAdminScannerInfoSyntax(ctx)
|
||||
|
||||
aliasedURL := ctx.Args().Get(0)
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminScannerTraceFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "response-threshold",
|
||||
Usage: "trace calls only with response duration greater than this threshold (e.g. `5ms`)",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "funcname",
|
||||
Usage: "trace only matching func name (eg 'scanner.ScanObject')",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "node",
|
||||
Usage: "trace only matching servers",
|
||||
},
|
||||
}
|
||||
|
||||
var adminScannerTraceCmd = cli.Command{
|
||||
Name: "trace",
|
||||
Usage: "show trace for MinIO scanner operations",
|
||||
Action: mainAdminScannerTrace,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminScannerTraceFlags, globalFlags...),
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Show scanner trace for MinIO server
|
||||
{{.Prompt}} {{.HelpName}} myminio
|
||||
|
||||
2. Show scanner trace for a specific path
|
||||
{{.Prompt}} {{.HelpName}} --path my-bucket/my-prefix/* myminio
|
||||
|
||||
3. Show trace for only ScanObject operations
|
||||
{{.Prompt}} {{.HelpName}} --funcname=scanner.ScanObject myminio
|
||||
`,
|
||||
}
|
||||
|
||||
func checkAdminScannerTraceSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "trace", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// mainAdminScannerTrace - the entry function of trace command
|
||||
func mainAdminScannerTrace(ctx *cli.Context) error {
|
||||
// Check for command syntax
|
||||
checkAdminScannerTraceSyntax(ctx)
|
||||
|
||||
verbose := ctx.Bool("verbose")
|
||||
aliasedURL := ctx.Args().Get(0)
|
||||
|
||||
console.SetColor("Stat", color.New(color.FgYellow))
|
||||
|
||||
console.SetColor("Request", color.New(color.FgCyan))
|
||||
console.SetColor("Method", color.New(color.Bold, color.FgWhite))
|
||||
console.SetColor("Host", color.New(color.Bold, color.FgGreen))
|
||||
console.SetColor("FuncName", color.New(color.Bold, color.FgGreen))
|
||||
|
||||
console.SetColor("ReqHeaderKey", color.New(color.Bold, color.FgWhite))
|
||||
console.SetColor("RespHeaderKey", color.New(color.Bold, color.FgCyan))
|
||||
console.SetColor("HeaderValue", color.New(color.FgWhite))
|
||||
console.SetColor("RespStatus", color.New(color.Bold, color.FgYellow))
|
||||
console.SetColor("ErrStatus", color.New(color.Bold, color.FgRed))
|
||||
|
||||
console.SetColor("Response", color.New(color.FgGreen))
|
||||
console.SetColor("Body", color.New(color.FgYellow))
|
||||
for _, c := range colors {
|
||||
console.SetColor(fmt.Sprintf("Node%d", c), color.New(c))
|
||||
}
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
|
||||
return nil
|
||||
}
|
||||
|
||||
ctxt, cancel := context.WithCancel(globalContext)
|
||||
defer cancel()
|
||||
|
||||
opts, e := tracingOpts(ctx, []string{"scanner"})
|
||||
fatalIf(probe.NewError(e), "Unable to start tracing")
|
||||
|
||||
mopts := matchOpts{
|
||||
funcNames: ctx.StringSlice("funcname"),
|
||||
apiPaths: ctx.StringSlice("path"),
|
||||
nodes: ctx.StringSlice("node"),
|
||||
}
|
||||
|
||||
// Start listening on all trace activity.
|
||||
traceCh := client.ServiceTrace(ctxt, opts)
|
||||
for traceInfo := range traceCh {
|
||||
if traceInfo.Err != nil {
|
||||
fatalIf(probe.NewError(traceInfo.Err), "Unable to listen to http trace")
|
||||
}
|
||||
if matchTrace(mopts, traceInfo) {
|
||||
printTrace(verbose, traceInfo)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var adminScannerSubcommands = []cli.Command{
|
||||
adminScannerInfo,
|
||||
adminScannerTraceCmd,
|
||||
}
|
||||
|
||||
var adminScannerCmd = cli.Command{
|
||||
Name: "scanner",
|
||||
Usage: "provide MinIO scanner info",
|
||||
Action: mainAdminScanner,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Subcommands: adminScannerSubcommands,
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
|
||||
// mainAdminScanner is the handle for "mc admin scanner" command.
|
||||
func mainAdminScanner(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, adminScannerSubcommands)
|
||||
return nil
|
||||
}
|
||||
@@ -94,7 +94,7 @@ func mainAdminTopAPI(ctx *cli.Context) error {
|
||||
ctxt, cancel := context.WithCancel(globalContext)
|
||||
defer cancel()
|
||||
|
||||
opts, e := tracingOpts(ctx)
|
||||
opts, e := tracingOpts(ctx, ctx.StringSlice("call"))
|
||||
fatalIf(probe.NewError(e), "Unable to start tracing")
|
||||
|
||||
mopts := matchOpts{
|
||||
|
||||
@@ -22,7 +22,6 @@ import "github.com/minio/cli"
|
||||
var adminTopSubcommands = []cli.Command{
|
||||
adminTopAPICmd,
|
||||
adminTopLocksCmd,
|
||||
adminTopScannerCmd,
|
||||
}
|
||||
|
||||
var adminTopCmd = cli.Command{
|
||||
|
||||
+2
-3
@@ -217,7 +217,7 @@ func matchTrace(opts matchOpts, traceInfo madmin.ServiceTraceInfo) bool {
|
||||
}
|
||||
|
||||
// Calculate tracing options for command line flags
|
||||
func tracingOpts(ctx *cli.Context) (opts madmin.ServiceTraceOpts, e error) {
|
||||
func tracingOpts(ctx *cli.Context, apis []string) (opts madmin.ServiceTraceOpts, e error) {
|
||||
if t := ctx.String("response-threshold"); t != "" {
|
||||
d, e := time.ParseDuration(t)
|
||||
if e != nil {
|
||||
@@ -237,7 +237,6 @@ func tracingOpts(ctx *cli.Context) (opts madmin.ServiceTraceOpts, e error) {
|
||||
return
|
||||
}
|
||||
|
||||
apis := ctx.StringSlice("call")
|
||||
if len(apis) == 0 {
|
||||
// If api flag is not specified, then we will
|
||||
// trace only S3 requests by default.
|
||||
@@ -299,7 +298,7 @@ func mainAdminTrace(ctx *cli.Context) error {
|
||||
ctxt, cancel := context.WithCancel(globalContext)
|
||||
defer cancel()
|
||||
|
||||
opts, e := tracingOpts(ctx)
|
||||
opts, e := tracingOpts(ctx, ctx.StringSlice("call"))
|
||||
fatalIf(probe.NewError(e), "Unable to start tracing")
|
||||
|
||||
mopts := matchOpts{
|
||||
|
||||
+10
-8
@@ -323,14 +323,16 @@ var completeCmds = map[string]complete.Predictor{
|
||||
"/admin/decommission/status": aliasCompleter,
|
||||
"/admin/decommission/cancel": aliasCompleter,
|
||||
|
||||
"/admin/trace": aliasCompleter,
|
||||
"/admin/speedtest": aliasCompleter,
|
||||
"/admin/console": aliasCompleter,
|
||||
"/admin/update": aliasCompleter,
|
||||
"/admin/inspect": s3Completer,
|
||||
"/admin/top/locks": aliasCompleter,
|
||||
"/admin/top/api": aliasCompleter,
|
||||
"/admin/top/scanner": aliasCompleter,
|
||||
"/admin/trace": aliasCompleter,
|
||||
"/admin/speedtest": aliasCompleter,
|
||||
"/admin/console": aliasCompleter,
|
||||
"/admin/update": aliasCompleter,
|
||||
"/admin/inspect": s3Completer,
|
||||
"/admin/top/locks": aliasCompleter,
|
||||
"/admin/top/api": aliasCompleter,
|
||||
|
||||
"/admin/scanner/info": aliasCompleter,
|
||||
"/admin/scanner/trace": aliasCompleter,
|
||||
|
||||
"/admin/service/stop": aliasCompleter,
|
||||
"/admin/service/restart": aliasCompleter,
|
||||
|
||||
Reference in New Issue
Block a user