mirror of https://github.com/dapr/cli.git
Store app PID in sidecar metadata. (#1200)
* Store app PID in sidecar metadata. Signed-off-by: Phillip Hoff <phillip@orst.edu> * Move process check under command check. Signed-off-by: Phillip Hoff <phillip@orst.edu> * Add minimal list test appId changes. Signed-off-by: Phillip Hoff <phillip@orst.edu> * Reverse params. Signed-off-by: Phillip Hoff <phillip@orst.edu> * Proper type conversion. Signed-off-by: Phillip Hoff <phillip@orst.edu> --------- Signed-off-by: Phillip Hoff <phillip@orst.edu> Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
This commit is contained in:
parent
42f9519eb2
commit
50d5af4cd9
22
cmd/run.go
22
cmd/run.go
|
@ -360,6 +360,14 @@ dapr run --run-file /path/to/directory
|
||||||
}
|
}
|
||||||
|
|
||||||
if output.AppCMD != nil {
|
if output.AppCMD != nil {
|
||||||
|
if output.AppCMD.Process != nil {
|
||||||
|
print.InfoStatusEvent(os.Stdout, fmt.Sprintf("Updating metadata for appPID: %d", output.AppCMD.Process.Pid))
|
||||||
|
err = metadata.Put(output.DaprHTTPPort, "appPID", strconv.Itoa(output.AppCMD.Process.Pid), appID, unixDomainSocket)
|
||||||
|
if err != nil {
|
||||||
|
print.WarningStatusEvent(os.Stdout, "Could not update sidecar metadata for appPID: %s", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
appCommand := strings.Join(args, " ")
|
appCommand := strings.Join(args, " ")
|
||||||
print.InfoStatusEvent(os.Stdout, fmt.Sprintf("Updating metadata for app command: %s", appCommand))
|
print.InfoStatusEvent(os.Stdout, fmt.Sprintf("Updating metadata for app command: %s", appCommand))
|
||||||
err = metadata.Put(output.DaprHTTPPort, "appCommand", appCommand, appID, unixDomainSocket)
|
err = metadata.Put(output.DaprHTTPPort, "appCommand", appCommand, appID, unixDomainSocket)
|
||||||
|
@ -526,7 +534,12 @@ func executeRun(runFilePath string, apps []runfileconfig.App) (bool, error) {
|
||||||
|
|
||||||
if runState.AppCMD.Command != nil {
|
if runState.AppCMD.Command != nil {
|
||||||
putAppCommandInMeta(runConfig, runState)
|
putAppCommandInMeta(runConfig, runState)
|
||||||
|
|
||||||
|
if runState.AppCMD.Command.Process != nil {
|
||||||
|
putAppProcessIDInMeta(runState)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print.StatusEvent(runState.DaprCMD.OutputWriter, print.LogSuccess, "You're up and running! Dapr logs will appear here.\n")
|
print.StatusEvent(runState.DaprCMD.OutputWriter, print.LogSuccess, "You're up and running! Dapr logs will appear here.\n")
|
||||||
logInformationalStatusToStdout(app)
|
logInformationalStatusToStdout(app)
|
||||||
}
|
}
|
||||||
|
@ -907,6 +920,14 @@ func putCLIProcessIDInMeta(runE *runExec.RunExec, pid int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func putAppProcessIDInMeta(runE *runExec.RunExec) {
|
||||||
|
print.StatusEvent(runE.DaprCMD.OutputWriter, print.LogInfo, "Updating metadata for appPID: %d", runE.AppCMD.Command.Process.Pid)
|
||||||
|
err := metadata.Put(runE.DaprHTTPPort, "appPID", strconv.Itoa(runE.AppCMD.Command.Process.Pid), runE.AppID, unixDomainSocket)
|
||||||
|
if err != nil {
|
||||||
|
print.StatusEvent(runE.DaprCMD.OutputWriter, print.LogWarning, "Could not update sidecar metadata for appPID: %s", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// putAppCommandInMeta puts the app command in metadata so that it can be used by the CLI to stop the app.
|
// putAppCommandInMeta puts the app command in metadata so that it can be used by the CLI to stop the app.
|
||||||
func putAppCommandInMeta(runConfig standalone.RunConfig, runE *runExec.RunExec) {
|
func putAppCommandInMeta(runConfig standalone.RunConfig, runE *runExec.RunExec) {
|
||||||
appCommand := strings.Join(runConfig.Command, " ")
|
appCommand := strings.Join(runConfig.Command, " ")
|
||||||
|
@ -916,7 +937,6 @@ func putAppCommandInMeta(runConfig standalone.RunConfig, runE *runExec.RunExec)
|
||||||
print.StatusEvent(runE.DaprCMD.OutputWriter, print.LogWarning, "Could not update sidecar metadata for appCommand: %s", err.Error())
|
print.StatusEvent(runE.DaprCMD.OutputWriter, print.LogWarning, "Could not update sidecar metadata for appCommand: %s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
print.StatusEvent(runE.DaprCMD.OutputWriter, print.LogSuccess, "You're up and running! Dapr logs will appear here.\n")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// putRunFilePathInMeta puts the absolute path of run file in metadata so that it can be used by the CLI to stop all apps started by this run file.
|
// putRunFilePathInMeta puts the absolute path of run file in metadata so that it can be used by the CLI to stop all apps started by this run file.
|
||||||
|
|
|
@ -39,6 +39,7 @@ type ListOutput struct {
|
||||||
Created string `csv:"CREATED" json:"created" yaml:"created"`
|
Created string `csv:"CREATED" json:"created" yaml:"created"`
|
||||||
DaprdPID int `csv:"DAPRD PID" json:"daprdPid" yaml:"daprdPid"`
|
DaprdPID int `csv:"DAPRD PID" json:"daprdPid" yaml:"daprdPid"`
|
||||||
CliPID int `csv:"CLI PID" json:"cliPid" yaml:"cliPid"`
|
CliPID int `csv:"CLI PID" json:"cliPid" yaml:"cliPid"`
|
||||||
|
AppPID int `csv:"APP PID" json:"appPid" yaml:"appPid"`
|
||||||
MaxRequestBodySize int `csv:"-" json:"maxRequestBodySize" yaml:"maxRequestBodySize"` // Additional field, not displayed in table.
|
MaxRequestBodySize int `csv:"-" json:"maxRequestBodySize" yaml:"maxRequestBodySize"` // Additional field, not displayed in table.
|
||||||
HTTPReadBufferSize int `csv:"-" json:"httpReadBufferSize" yaml:"httpReadBufferSize"` // Additional field, not displayed in table.
|
HTTPReadBufferSize int `csv:"-" json:"httpReadBufferSize" yaml:"httpReadBufferSize"` // Additional field, not displayed in table.
|
||||||
RunTemplatePath string `csv:"RUN_TEMPLATE_PATH" json:"runTemplatePath" yaml:"runTemplatePath"`
|
RunTemplatePath string `csv:"RUN_TEMPLATE_PATH" json:"runTemplatePath" yaml:"runTemplatePath"`
|
||||||
|
@ -99,16 +100,23 @@ func List() ([]ListOutput, error) {
|
||||||
|
|
||||||
appID := argumentsMap["--app-id"]
|
appID := argumentsMap["--app-id"]
|
||||||
appCmd := ""
|
appCmd := ""
|
||||||
|
appPIDString := ""
|
||||||
cliPIDString := ""
|
cliPIDString := ""
|
||||||
runTemplatePath := ""
|
runTemplatePath := ""
|
||||||
socket := argumentsMap["--unix-domain-socket"]
|
socket := argumentsMap["--unix-domain-socket"]
|
||||||
appMetadata, err := metadata.Get(httpPort, appID, socket)
|
appMetadata, err := metadata.Get(httpPort, appID, socket)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
appCmd = appMetadata.Extended["appCommand"]
|
appCmd = appMetadata.Extended["appCommand"]
|
||||||
|
appPIDString = appMetadata.Extended["appPID"]
|
||||||
cliPIDString = appMetadata.Extended["cliPID"]
|
cliPIDString = appMetadata.Extended["cliPID"]
|
||||||
runTemplatePath = appMetadata.Extended["runTemplatePath"]
|
runTemplatePath = appMetadata.Extended["runTemplatePath"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
appPID, err := strconv.Atoi(appPIDString)
|
||||||
|
if err != nil {
|
||||||
|
appPID = 0
|
||||||
|
}
|
||||||
|
|
||||||
// Parse functions return an error on bad input.
|
// Parse functions return an error on bad input.
|
||||||
cliPID, err := strconv.Atoi(cliPIDString)
|
cliPID, err := strconv.Atoi(cliPIDString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -130,6 +138,7 @@ func List() ([]ListOutput, error) {
|
||||||
DaprdPID: daprPID,
|
DaprdPID: daprPID,
|
||||||
CliPID: cliPID,
|
CliPID: cliPID,
|
||||||
AppID: appID,
|
AppID: appID,
|
||||||
|
AppPID: appPID,
|
||||||
HTTPPort: httpPort,
|
HTTPPort: httpPort,
|
||||||
GRPCPort: grpcPort,
|
GRPCPort: grpcPort,
|
||||||
AppPort: appPort,
|
AppPort: appPort,
|
||||||
|
|
|
@ -123,7 +123,7 @@ func listOutputCheck(t *testing.T, output string, isCli bool) {
|
||||||
// only one app is runnning at this time
|
// only one app is runnning at this time
|
||||||
fields := strings.Fields(lines[0])
|
fields := strings.Fields(lines[0])
|
||||||
// Fields splits on space, so Created time field might be split again
|
// Fields splits on space, so Created time field might be split again
|
||||||
assert.GreaterOrEqual(t, len(fields), 4, "expected at least 4 fields in components output")
|
assert.GreaterOrEqual(t, len(fields), 10, "expected at least 10 fields in components output")
|
||||||
if isCli {
|
if isCli {
|
||||||
assert.Equal(t, "dapr_e2e_list", fields[0], "expected name to match")
|
assert.Equal(t, "dapr_e2e_list", fields[0], "expected name to match")
|
||||||
} else {
|
} else {
|
||||||
|
@ -132,6 +132,7 @@ func listOutputCheck(t *testing.T, output string, isCli bool) {
|
||||||
assert.Equal(t, "3555", fields[1], "expected http port to match")
|
assert.Equal(t, "3555", fields[1], "expected http port to match")
|
||||||
assert.Equal(t, "4555", fields[2], "expected grpc port to match")
|
assert.Equal(t, "4555", fields[2], "expected grpc port to match")
|
||||||
assert.Equal(t, "0", fields[3], "expected app port to match")
|
assert.Equal(t, "0", fields[3], "expected app port to match")
|
||||||
|
assert.NotEmpty(t, fields[9], "expected an app PID (a real value or zero)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func listJsonOutputCheck(t *testing.T, output string) {
|
func listJsonOutputCheck(t *testing.T, output string) {
|
||||||
|
@ -146,6 +147,7 @@ func listJsonOutputCheck(t *testing.T, output string) {
|
||||||
assert.Equal(t, 3555, int(result[0]["httpPort"].(float64)), "expected http port to match")
|
assert.Equal(t, 3555, int(result[0]["httpPort"].(float64)), "expected http port to match")
|
||||||
assert.Equal(t, 4555, int(result[0]["grpcPort"].(float64)), "expected grpc port to match")
|
assert.Equal(t, 4555, int(result[0]["grpcPort"].(float64)), "expected grpc port to match")
|
||||||
assert.Equal(t, 0, int(result[0]["appPort"].(float64)), "expected app port to match")
|
assert.Equal(t, 0, int(result[0]["appPort"].(float64)), "expected app port to match")
|
||||||
|
assert.GreaterOrEqual(t, int(result[0]["appPid"].(float64)), 0, "expected an app PID (a real value or zero)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func listYamlOutputCheck(t *testing.T, output string) {
|
func listYamlOutputCheck(t *testing.T, output string) {
|
||||||
|
@ -160,4 +162,5 @@ func listYamlOutputCheck(t *testing.T, output string) {
|
||||||
assert.Equal(t, 3555, result[0]["httpPort"], "expected http port to match")
|
assert.Equal(t, 3555, result[0]["httpPort"], "expected http port to match")
|
||||||
assert.Equal(t, 4555, result[0]["grpcPort"], "expected grpc port to match")
|
assert.Equal(t, 4555, result[0]["grpcPort"], "expected grpc port to match")
|
||||||
assert.Equal(t, 0, result[0]["appPort"], "expected app port to match")
|
assert.Equal(t, 0, result[0]["appPort"], "expected app port to match")
|
||||||
|
assert.GreaterOrEqual(t, result[0]["appPid"], 0, "expected an app PID (a real value or zero)")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue