Move support logs to admin logs (#4381)

This commit is contained in:
Shireesh Anjal
2022-11-30 19:34:01 -08:00
committed by GitHub
parent c64833c018
commit 024656ba05
7 changed files with 55 additions and 79 deletions
+2 -2
View File
@@ -47,12 +47,12 @@ var adminConsoleCmd = cli.Command{
Flags: append(adminConsoleFlags, globalFlags...),
Hidden: true,
HideHelpCommand: true,
CustomHelpTemplate: "This command is not supported now and replaced by 'support logs show' command. Please use 'mc support logs show'.\n",
CustomHelpTemplate: "This command is not supported now and replaced by 'admin logs' command. Please use 'mc admin logs'.\n",
}
// mainAdminConsole - the entry function of console command
func mainAdminConsole(ctx *cli.Context) error {
newCmd := []string{"mc support logs show"}
newCmd := []string{"mc admin logs"}
var flgStr string
+27 -2
View File
@@ -46,6 +46,31 @@ var logsShowFlags = []cli.Flag{
},
}
var adminLogsCmd = cli.Command{
Name: "logs",
Usage: "show MinIO logs",
OnUsageError: onUsageError,
Action: mainAdminLogs,
Before: setGlobalsFromContext,
Flags: append(logsShowFlags, globalFlags...),
HideHelpCommand: true,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} [FLAGS] TARGET [NODENAME]
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Show logs for a MinIO server with alias 'myminio'
{{.Prompt}} {{.HelpName}} myminio
2. Show last 5 log entries for node 'node1' for a MinIO server with alias 'myminio'
{{.Prompt}} {{.HelpName}} --last 5 myminio node1
3. Show application errors in logs for a MinIO server with alias 'myminio'
{{.Prompt}} {{.HelpName}} --type application myminio
`,
}
func checkLogsShowSyntax(ctx *cli.Context) {
if len(ctx.Args()) == 0 || len(ctx.Args()) > 3 {
showCommandHelpAndExit(ctx, 1) // last argument is exit code
@@ -139,8 +164,8 @@ func (l logMessage) String() string {
return fmt.Sprintf("%s\n", logMsg)
}
// mainLogsShowConsole - the entry function of support logs show
func mainLogsShowConsole(ctx *cli.Context) error {
// mainAdminLogs - the entry function of admin logs
func mainAdminLogs(ctx *cli.Context) error {
// Check for command syntax
checkLogsShowSyntax(ctx)
console.SetColor("LogMessage", color.New(color.Bold, color.FgRed))
+1
View File
@@ -55,6 +55,7 @@ var adminCmdSubcommands = []cli.Command{
adminConsoleCmd,
adminClusterCmd,
adminRebalanceCmd,
adminLogsCmd,
}
var adminCmd = cli.Command{
+1 -1
View File
@@ -310,6 +310,7 @@ var completeCmds = map[string]complete.Predictor{
"/admin/heal": s3Completer,
"/admin/info": aliasCompleter,
"/admin/logs": aliasCompleter,
"/admin/config/get": adminConfigCompleter,
"/admin/config/set": adminConfigCompleter,
@@ -449,7 +450,6 @@ var completeCmds = map[string]complete.Predictor{
"/alias/import": nil,
"/support/callhome": aliasCompleter,
"/support/logs": aliasCompleter,
"/support/register": aliasCompleter,
"/support/diag": aliasCompleter,
"/support/profile": aliasCompleter,
+24
View File
@@ -18,6 +18,7 @@
package cmd
import (
"fmt"
"strings"
"github.com/minio/cli"
@@ -213,3 +214,26 @@ func setCallhomeConfig(alias string, enableCallhome bool) {
_, e := client.SetConfigKV(globalContext, configStr)
fatalIf(probe.NewError(e), "Unable to set callhome config on minio")
}
func configureSubnetWebhook(alias string, enable bool) {
// Create a new MinIO Admin Client
client, err := newAdminClient(alias)
fatalIf(err, "Unable to initialize admin connection.")
var input string
if enable {
apiKey := validateClusterRegistered(alias, true)
input = fmt.Sprintf("logger_webhook:subnet endpoint=%s auth_token=%s enable=on",
subnetLogWebhookURL(), apiKey)
} else {
input = "logger_webhook:subnet enable=off"
}
// Call set config API
_, e := client.SetConfigKV(globalContext, input)
fatalIf(probe.NewError(e), "Unable to set '%s' to server", input)
}
func isLogsCallhomeEnabled(alias string) bool {
return isFeatureEnabled(alias, "logger_webhook", "subnet")
}
-73
View File
@@ -1,73 +0,0 @@
// 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 (
"fmt"
"github.com/minio/cli"
"github.com/minio/mc/pkg/probe"
)
var supportLogsCmd = cli.Command{
Name: "logs",
Usage: "show MinIO logs",
OnUsageError: onUsageError,
Action: mainLogsShowConsole,
Before: setGlobalsFromContext,
Flags: append(logsShowFlags, globalFlags...),
HideHelpCommand: true,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} [FLAGS] TARGET [NODENAME]
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Show logs for a MinIO server with alias 'myminio'
{{.Prompt}} {{.HelpName}} myminio
2. Show last 5 log entries for node 'node1' for a MinIO server with alias 'myminio'
{{.Prompt}} {{.HelpName}} --last 5 myminio node1
3. Show application errors in logs for a MinIO server with alias 'myminio'
{{.Prompt}} {{.HelpName}} --type application myminio
`,
}
func configureSubnetWebhook(alias string, enable bool) {
// Create a new MinIO Admin Client
client, err := newAdminClient(alias)
fatalIf(err, "Unable to initialize admin connection.")
var input string
if enable {
apiKey := validateClusterRegistered(alias, true)
input = fmt.Sprintf("logger_webhook:subnet endpoint=%s auth_token=%s enable=on",
subnetLogWebhookURL(), apiKey)
} else {
input = "logger_webhook:subnet enable=off"
}
// Call set config API
_, e := client.SetConfigKV(globalContext, input)
fatalIf(probe.NewError(e), "Unable to set '%s' to server", input)
}
func isLogsCallhomeEnabled(alias string) bool {
return isFeatureEnabled(alias, "logger_webhook", "subnet")
}
-1
View File
@@ -40,7 +40,6 @@ var supportGlobalFlags = append(globalFlags, cli.BoolFlag{
var supportSubcommands = []cli.Command{
supportRegisterCmd,
supportCallhomeCmd,
supportLogsCmd,
supportDiagCmd,
supportPerfCmd,
supportInspectCmd,