Skip to content

Commit

Permalink
shivam-51: Add log file paths to dapr list 1228 (#1296)
Browse files Browse the repository at this point in the history
* shivam-51: Add log file paths to dapr list 1228

Signed-off-by: Shivam Kumar Singh <shivamhere247@gmail.com>

* Minor type fix.

Signed-off-by: Shivam Kumar Singh <shivamhere247@gmail.com>

* Add condition for log file in dapr list

Signed-off-by: Shivam Kumar Singh <shivamhere247@gmail.com>

* Add tests

Signed-off-by: Shivam Kumar Singh <shivamhere247@gmail.com>

* Complete tests

Signed-off-by: Shivam Kumar Singh <shivamhere247@gmail.com>

* Fix failing e2e tests

Signed-off-by: Shivam Kumar Singh <shivamhere247@gmail.com>

* Use constants

Signed-off-by: Shivam Kumar Singh <shivamhere247@gmail.com>

* Add success tests

Signed-off-by: Shivam Kumar Singh <shivamhere247@gmail.com>

* Add proper assert in test

Signed-off-by: Shivam Kumar Singh <shivamhere247@gmail.com>

* Fix typo

Signed-off-by: Shivam Kumar Singh <shivamhere247@gmail.com>

---------

Signed-off-by: Shivam Kumar Singh <shivamhere247@gmail.com>
Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
  • Loading branch information
shivam-51 and mukundansundar authored Jun 13, 2023
1 parent fa2c99d commit 7da8bd7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,16 @@ func executeRun(runTemplateName, runFilePath string, apps []runfileconfig.App) (
// Update extended metadata with run file path.
putRunTemplateNameInMeta(runState, runTemplateName)

// Update extended metadata with app log file path.
if app.AppLogDestination != standalone.Console {
putAppLogFilePathInMeta(runState, app.AppLogFileName)
}

// Update extended metadata with daprd log file path.
if app.DaprdLogDestination != standalone.Console {
putDaprLogFilePathInMeta(runState, app.DaprdLogFileName)
}

if runState.AppCMD.Command != nil {
putAppCommandInMeta(runConfig, runState)

Expand Down Expand Up @@ -999,6 +1009,22 @@ func putRunTemplateNameInMeta(runE *runExec.RunExec, runTemplateName string) {
}
}

// putAppLogFilePathInMeta puts the absolute path of app log file in metadata so that it can be used by the CLI to stop the app.
func putAppLogFilePathInMeta(runE *runExec.RunExec, appLogFilePath string) {
err := metadata.Put(runE.DaprHTTPPort, "appLogPath", appLogFilePath, runE.AppID, unixDomainSocket)
if err != nil {
print.StatusEvent(runE.DaprCMD.OutputWriter, print.LogWarning, "Could not update sidecar metadata for app log file path: %s", err.Error())
}
}

// putDaprLogFilePathInMeta puts the absolute path of Dapr log file in metadata so that it can be used by the CLI to stop the app.
func putDaprLogFilePathInMeta(runE *runExec.RunExec, daprLogFilePath string) {
err := metadata.Put(runE.DaprHTTPPort, "daprdLogPath", daprLogFilePath, runE.AppID, unixDomainSocket)
if err != nil {
print.StatusEvent(runE.DaprCMD.OutputWriter, print.LogWarning, "Could not update sidecar metadata for dapr log file path: %s", err.Error())
}
}

// getRunFilePath returns the path to the run file.
// If the provided path is a path to a YAML file then return the same.
// Else it returns the path of "dapr.yaml" in the provided directory.
Expand Down
8 changes: 8 additions & 0 deletions pkg/standalone/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type ListOutput struct {
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.
RunTemplatePath string `csv:"RUN_TEMPLATE_PATH" json:"runTemplatePath" yaml:"runTemplatePath"`
AppLogPath string `csv:"APP_LOG_PATH" json:"appLogPath" yaml:"appLogPath"`
DaprDLogPath string `csv:"DAPRD_LOG_PATH" json:"daprdLogPath" yaml:"daprdLogPath"`
RunTemplateName string `json:"runTemplateName" yaml:"runTemplateName"` // specifically omitted in csv output.
}

Expand Down Expand Up @@ -112,6 +114,8 @@ func List() ([]ListOutput, error) {
appPIDString := ""
cliPIDString := ""
runTemplatePath := ""
appLogPath := ""
daprdLogPath := ""
runTemplateName := ""
socket := argumentsMap["--unix-domain-socket"]
appMetadata, err := metadata.Get(httpPort, appID, socket)
Expand All @@ -121,6 +125,8 @@ func List() ([]ListOutput, error) {
cliPIDString = appMetadata.Extended["cliPID"]
runTemplatePath = appMetadata.Extended["runTemplatePath"]
runTemplateName = appMetadata.Extended["runTemplateName"]
appLogPath = appMetadata.Extended["appLogPath"]
daprdLogPath = appMetadata.Extended["daprdLogPath"]
}

appPID, err := strconv.Atoi(appPIDString)
Expand Down Expand Up @@ -159,6 +165,8 @@ func List() ([]ListOutput, error) {
HTTPReadBufferSize: httpReadBufferSize,
RunTemplatePath: runTemplatePath,
RunTemplateName: runTemplateName,
AppLogPath: appLogPath,
DaprDLogPath: daprdLogPath,
}

// filter only dashboard instance.
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/standalone/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ func listJsonOutputCheck(t *testing.T, output string) {
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.GreaterOrEqual(t, int(result[0]["appPid"].(float64)), 0, "expected an app PID (a real value or zero)")
assert.Equal(t, "", result[0]["appLogPath"], "expected app log path to be empty")
assert.Equal(t, "", result[0]["daprdLogPath"], "expected daprd log path to be empty")
}

func listYamlOutputCheck(t *testing.T, output string) {
Expand All @@ -185,4 +187,6 @@ func listYamlOutputCheck(t *testing.T, output string) {
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.GreaterOrEqual(t, result[0]["appPid"], 0, "expected an app PID (a real value or zero)")
assert.Equal(t, "", result[0]["appLogPath"], "expected app log path to be empty")
assert.Equal(t, "", result[0]["daprdLogPath"], "expected daprd log path to be empty")
}
2 changes: 2 additions & 0 deletions tests/e2e/standalone/stop_with_run_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,6 @@ func assertTemplateListOutput(t *testing.T, name string) {

assert.Len(t, result, 2, "expected two apps to be running")
assert.Equal(t, name, result[0]["runTemplateName"], "expected run template name to be %s", name)
assert.NotEmpty(t, result[0]["appLogPath"], "expected appLogPath to be non-empty")
assert.NotEmpty(t, result[0]["daprdLogPath"], "expected daprdLogPath to be non-empty")
}

0 comments on commit 7da8bd7

Please sign in to comment.