Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Modify log modular output #203

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions internal/ccontrol/CmdArgParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ var (
FlagHoldTime string
FlagConfigFilePath string
FlagJson bool
FlagLoggerName string
FlagLogLevel string

RootCmd = &cobra.Command{
Use: "ccontrol",
Expand Down Expand Up @@ -161,6 +163,17 @@ var (
}
},
}
updateLoggingLevelCmd = &cobra.Command{
Use: "logger [flags]",
Short: "Modify node logging level",
Long: "",
Run: func(cmd *cobra.Command, args []string) {
log.Info("-n unset for cranectld")
if err := ChangeLoggingLevel(FlagNodeName, FlagLoggerName, FlagLogLevel); err != util.ErrorSuccess {
1daidai1 marked this conversation as resolved.
Show resolved Hide resolved
os.Exit(err)
}
},
}
holdCmd = &cobra.Command{
Use: "hold [flags] job_id[,job_id...]",
Short: "prevent specified job from starting. ",
Expand Down Expand Up @@ -250,6 +263,12 @@ func init() {
return
}
}
updateCmd.AddCommand(updateLoggingLevelCmd)
{
updateLoggingLevelCmd.Flags().StringVarP(&FlagNodeName, "node", "n", "", "Specify names of the node to be modified (craned names, unset for cranectld)")
updateLoggingLevelCmd.Flags().StringVarP(&FlagLoggerName, "logger", "m", "all", "Specify logger name of the node to be modified")
updateLoggingLevelCmd.Flags().StringVarP(&FlagLogLevel, "level", "l", "trace", "Specify logging level")
}
}
RootCmd.AddCommand(holdCmd)
{
Expand Down
43 changes: 43 additions & 0 deletions internal/ccontrol/ccontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,18 @@ func SummarizeReply(proto interface{}) util.CraneCmdError {
return util.ErrorBackend
}
return util.ErrorSuccess
case *protos.SetLoggingLevelReply:
if len(reply.ModifiedNodes) > 0 {
fmt.Printf("Nodes %v logging level modified successfully.\n", reply.ModifiedNodes)
}
if len(reply.NotModifiedNodes) > 0 {
for i := 0; i < len(reply.NotModifiedNodes); i++ {
_, _ = fmt.Fprintf(os.Stderr, "Failed to modify node logging level: %s. Reason: %s.\n",
reply.NotModifiedNodes[i], reply.NotModifiedReasons[i])
}
return util.ErrorBackend
}
return util.ErrorSuccess
default:
return util.ErrorGeneric
}
Expand Down Expand Up @@ -656,3 +668,34 @@ func ChangeNodeState(nodeRegex string, state string, reason string) util.CraneCm

return SummarizeReply(reply)
}

func ChangeLoggingLevel(inputNodesName, logger, logLevel string) util.CraneCmdError {
nodeNames, ok := util.ParseHostList(inputNodesName)
if !ok {
log.Errorf("Invalid node pattern: %s.\n", inputNodesName)
return util.ErrorCmdArg
}

logger = strings.ToLower(logger)
req := &protos.SetLoggingLevelRequest{
NodeName: nodeNames,
Logger: FlagLoggerName,
LogLevel: logLevel,
}
reply, err := stub.SetLoggingLevel(context.Background(), req)
if err != nil {
log.Errorf("Failed to modify node logger: %v.\n", err)
return util.ErrorNetwork
}

if FlagJson {
fmt.Println(util.FmtJson.FormatReply(reply))
if len(reply.NotModifiedNodes) == 0 {
return util.ErrorSuccess
} else {
return util.ErrorBackend
}
}

return SummarizeReply(reply)
}
26 changes: 26 additions & 0 deletions protos/Crane.proto
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ message CancelTaskReply {
repeated string not_cancelled_reasons = 4;
}

message SetCranedLoggingLevelRequest {
string logger = 1;
string level = 2;
}

message SetCranedLoggingLevelReply {
bool ok = 1;
}

message QueryTaskIdFromPortRequest{
uint32 port = 1;
Expand Down Expand Up @@ -690,6 +698,18 @@ message StreamCforedTaskIOReply {
}
}

message SetLoggingLevelRequest {
repeated string node_name = 1;
string logger = 2;
string log_level = 3;
}

message SetLoggingLevelReply {
repeated string modified_nodes = 1;
repeated string not_modified_nodes = 2;
repeated string not_modified_reasons = 3;
}

// Todo: Divide service into two parts: one for Craned and one for Crun
// We need to distinguish the message sender
// and have some kind of authentication
Expand Down Expand Up @@ -728,6 +748,9 @@ service CraneCtld {
/* RPCs called from cinfo */
rpc QueryClusterInfo(QueryClusterInfoRequest) returns (QueryClusterInfoReply);

/* RPCs called from ccontrol */
rpc SetLoggingLevel(SetLoggingLevelRequest) returns (SetLoggingLevelReply);

/* common RPCs */
rpc QueryTasksInfo(QueryTasksInfoRequest) returns (QueryTasksInfoReply);
}
Expand Down Expand Up @@ -756,6 +779,9 @@ service Craned {
/* ----------------------------------- Called from Craned ------------------------------------------------------ */
rpc QueryTaskIdFromPort(QueryTaskIdFromPortRequest) returns (QueryTaskIdFromPortReply);

/* RPCs called from ccontrol */
rpc SetCranedLoggingLevel(SetCranedLoggingLevelRequest) returns (SetCranedLoggingLevelReply);

/* ----------------------------------- Called from Pam Module --------------------------------------------------- */
rpc QueryTaskIdFromPortForward(QueryTaskIdFromPortForwardRequest) returns (QueryTaskIdFromPortForwardReply);
rpc MigrateSshProcToCgroup(MigrateSshProcToCgroupRequest) returns (MigrateSshProcToCgroupReply);
Expand Down