Changed API logging feature on CLI (#936)

* Changed API logging feature on CLI

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* Chnaged based on the review comments

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* Changes based on the review comments in test

Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>

* change to 1.7.0-rc.2

Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>

* fix linter errors

Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>

* fix method name

Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>

Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
This commit is contained in:
amulyavarote 2022-03-29 23:57:32 -07:00 committed by GitHub
parent db56a250bc
commit 3684654834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 26 deletions

View File

@ -46,9 +46,9 @@ jobs:
runs-on: ubuntu-latest
env:
GOVER: 1.17
DAPR_RUNTIME_VERSION: 1.7.0-rc.1
DAPR_RUNTIME_VERSION: 1.7.0-rc.2
DAPR_DASHBOARD_VERSION: 0.10.0-rc.1
DAPR_TGZ: dapr-1.7.0-rc.1.tgz
DAPR_TGZ: dapr-1.7.0-rc.2.tgz
strategy:
fail-fast: false # Keep running if one leg fails.
matrix:

View File

@ -36,9 +36,9 @@ jobs:
GOARCH: ${{ matrix.target_arch }}
GOPROXY: https://proxy.golang.org
ARCHIVE_OUTDIR: dist/archives
DAPR_RUNTIME_VERSION: "1.7.0-rc.1"
DAPR_RUNTIME_VERSION: "1.7.0-rc.2"
DAPR_DASHBOARD_VERSION: 0.10.0-rc.1
DAPR_TGZ: dapr-1.7.0-rc.1.tgz
DAPR_TGZ: dapr-1.7.0-rc.2.tgz
strategy:
matrix:
os: [ubuntu-latest, macos-latest]

View File

@ -588,14 +588,13 @@ $ dapr invoke --app-id nodeapp --unix-domain-socket --method mymethod
### Set API log level
In order to set the Dapr runtime API calls log verbosity level, use the `api-log-level` flag:
In order to set the Dapr runtime to log API calls with `INFO` log verbosity, use the `enable-api-logging` flag:
```bash
dapr run --app-id nodeapp --app-port 3000 node app.js --api-log-level info
dapr run --app-id nodeapp --app-port 3000 node app.js enable-api-logging
```
This sets the Dapr API log level to `info`.
The default is `debug`.
The default is `false`.
For more details, please run the command and check the examples to apply to your shell.

View File

@ -47,7 +47,7 @@ var (
metricsPort int
maxRequestBodySize int
unixDomainSocket string
apiLogLevel string
enableAPILogging bool
)
const (
@ -116,7 +116,7 @@ dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
MetricsPort: metricsPort,
MaxRequestBodySize: maxRequestBodySize,
UnixDomainSocket: unixDomainSocket,
APILogLevel: apiLogLevel,
EnableAPILogging: enableAPILogging,
})
if err != nil {
print.FailureStatusEvent(os.Stderr, err.Error())
@ -365,7 +365,7 @@ func init() {
RunCmd.Flags().BoolP("help", "h", false, "Print this help message")
RunCmd.Flags().IntVarP(&maxRequestBodySize, "dapr-http-max-request-size", "", -1, "Max size of request body in MB")
RunCmd.Flags().StringVarP(&unixDomainSocket, "unix-domain-socket", "u", "", "Path to a unix domain socket dir. If specified, Dapr API servers will use Unix Domain Sockets")
RunCmd.Flags().StringVarP(&apiLogLevel, "api-log-level", "", "debug", "The api calls log verbosity. Valid values are: debug, info, off")
RunCmd.Flags().BoolVar(&enableAPILogging, "enable-api-logging", false, "Log API calls at INFO verbosity. Valid values are: true or false")
RootCmd.AddCommand(RunCmd)
}

View File

@ -53,7 +53,7 @@ type RunConfig struct {
MetricsPort int `env:"DAPR_METRICS_PORT" arg:"metrics-port"`
MaxRequestBodySize int `arg:"dapr-http-max-request-size"`
UnixDomainSocket string `arg:"unix-domain-socket"`
APILogLevel string `arg:"api-log-level"`
EnableAPILogging bool `arg:"enable-api-logging"`
}
func (meta *DaprMeta) newAppID() string {

View File

@ -90,7 +90,6 @@ func assertCommonArgs(t *testing.T, basicConfig *RunConfig, output *RunOutput) {
assertArgumentEqual(t, "app-ssl", "", output.DaprCMD.Args)
assertArgumentEqual(t, "metrics-port", "9001", output.DaprCMD.Args)
assertArgumentEqual(t, "dapr-http-max-request-size", "-1", output.DaprCMD.Args)
assertArgumentEqual(t, "api-log-level", basicConfig.APILogLevel, output.DaprCMD.Args)
}
func assertAppEnv(t *testing.T, config *RunConfig, output *RunOutput) {
@ -149,7 +148,7 @@ func TestRun(t *testing.T) {
AppSSL: true,
MetricsPort: 9001,
MaxRequestBodySize: -1,
APILogLevel: "INFO",
EnableAPILogging: true,
}
t.Run("run happy http", func(t *testing.T) {
@ -165,7 +164,7 @@ func TestRun(t *testing.T) {
t.Run("run without app command", func(t *testing.T) {
basicConfig.Arguments = nil
basicConfig.LogLevel = "INFO"
basicConfig.APILogLevel = "INFO"
basicConfig.EnableAPILogging = true
basicConfig.ConfigFile = DefaultConfigFilePath()
output, err := Run(basicConfig)
assert.Nil(t, err)

View File

@ -70,7 +70,7 @@ func TestStandaloneInstall(t *testing.T) {
}
}
func TestApiLogLevel(t *testing.T) {
func TestEnableAPILogging(t *testing.T) {
// Ensure a clean environment.
uninstall()
@ -79,7 +79,7 @@ func TestApiLogLevel(t *testing.T) {
phase func(*testing.T)
}{
{"test install", testInstall},
{"test run api log level", testRunApiLogLevel},
{"test run enable api logging", testRunEnableAPILogging},
{"test uninstall", testUninstall},
}
@ -456,17 +456,17 @@ func testRun(t *testing.T) {
})
}
func testRunApiLogLevel(t *testing.T) {
func testRunEnableAPILogging(t *testing.T) {
daprPath := getDaprPath()
args := []string{
"run",
"--app-id", "apiloglevel_info",
"--api-log-level", "info",
"--app-id", "enableApiLogging_info",
"--enable-api-logging",
"--log-level", "info",
"--", "bash", "-c", "echo 'test'",
}
t.Run(fmt.Sprintf("check apiloglevel flag info mode"), func(t *testing.T) {
t.Run(fmt.Sprintf("check enableAPILogging flag in enabled mode"), func(t *testing.T) {
output, err := spawn.Command(daprPath, args...)
t.Log(output)
require.NoError(t, err, "run failed")
@ -477,19 +477,17 @@ func testRunApiLogLevel(t *testing.T) {
args = []string{
"run",
"--app-id", "apiloglevel_debug",
"--api-log-level", "debug",
"--log-level", "debug",
"--app-id", "enableApiLogging_info",
"--", "bash", "-c", "echo 'test'",
}
t.Run(fmt.Sprintf("check apiloglevel flag debug mode"), func(t *testing.T) {
t.Run(fmt.Sprintf("check enableAPILogging flag in disabled mode"), func(t *testing.T) {
output, err := spawn.Command(daprPath, args...)
t.Log(output)
require.NoError(t, err, "run failed")
assert.Contains(t, output, "level=debug msg=\"HTTP API Called: PUT /v1.0/metadata/appCommand\"")
assert.Contains(t, output, "Exited App successfully")
assert.Contains(t, output, "Exited Dapr successfully")
assert.NotContains(t, output, "level=info msg=\"HTTP API Called: PUT /v1.0/metadata/appCommand\"")
})
}