Skip to content

Commit 3684654

Browse files
Changed API logging feature on CLI (#936)
* Changed API logging feature on CLI Signed-off-by: Amulya Varote <[email protected]> * Chnaged based on the review comments Signed-off-by: Amulya Varote <[email protected]> * Changes based on the review comments in test Signed-off-by: Amulya Varote <[email protected]> * change to 1.7.0-rc.2 Signed-off-by: Mukundan Sundararajan <[email protected]> * fix linter errors Signed-off-by: Mukundan Sundararajan <[email protected]> * fix method name Signed-off-by: Mukundan Sundararajan <[email protected]> Co-authored-by: Mukundan Sundararajan <[email protected]>
1 parent db56a25 commit 3684654

File tree

7 files changed

+22
-26
lines changed

7 files changed

+22
-26
lines changed

.github/workflows/kind_e2e.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ jobs:
4646
runs-on: ubuntu-latest
4747
env:
4848
GOVER: 1.17
49-
DAPR_RUNTIME_VERSION: 1.7.0-rc.1
49+
DAPR_RUNTIME_VERSION: 1.7.0-rc.2
5050
DAPR_DASHBOARD_VERSION: 0.10.0-rc.1
51-
DAPR_TGZ: dapr-1.7.0-rc.1.tgz
51+
DAPR_TGZ: dapr-1.7.0-rc.2.tgz
5252
strategy:
5353
fail-fast: false # Keep running if one leg fails.
5454
matrix:

.github/workflows/self_hosted_e2e.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ jobs:
3636
GOARCH: ${{ matrix.target_arch }}
3737
GOPROXY: https://proxy.golang.org
3838
ARCHIVE_OUTDIR: dist/archives
39-
DAPR_RUNTIME_VERSION: "1.7.0-rc.1"
39+
DAPR_RUNTIME_VERSION: "1.7.0-rc.2"
4040
DAPR_DASHBOARD_VERSION: 0.10.0-rc.1
41-
DAPR_TGZ: dapr-1.7.0-rc.1.tgz
41+
DAPR_TGZ: dapr-1.7.0-rc.2.tgz
4242
strategy:
4343
matrix:
4444
os: [ubuntu-latest, macos-latest]

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,14 +588,13 @@ $ dapr invoke --app-id nodeapp --unix-domain-socket --method mymethod
588588

589589
### Set API log level
590590

591-
In order to set the Dapr runtime API calls log verbosity level, use the `api-log-level` flag:
591+
In order to set the Dapr runtime to log API calls with `INFO` log verbosity, use the `enable-api-logging` flag:
592592

593593
```bash
594-
dapr run --app-id nodeapp --app-port 3000 node app.js --api-log-level info
594+
dapr run --app-id nodeapp --app-port 3000 node app.js enable-api-logging
595595
```
596596

597-
This sets the Dapr API log level to `info`.
598-
The default is `debug`.
597+
The default is `false`.
599598

600599
For more details, please run the command and check the examples to apply to your shell.
601600

cmd/run.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var (
4747
metricsPort int
4848
maxRequestBodySize int
4949
unixDomainSocket string
50-
apiLogLevel string
50+
enableAPILogging bool
5151
)
5252

5353
const (
@@ -116,7 +116,7 @@ dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
116116
MetricsPort: metricsPort,
117117
MaxRequestBodySize: maxRequestBodySize,
118118
UnixDomainSocket: unixDomainSocket,
119-
APILogLevel: apiLogLevel,
119+
EnableAPILogging: enableAPILogging,
120120
})
121121
if err != nil {
122122
print.FailureStatusEvent(os.Stderr, err.Error())
@@ -365,7 +365,7 @@ func init() {
365365
RunCmd.Flags().BoolP("help", "h", false, "Print this help message")
366366
RunCmd.Flags().IntVarP(&maxRequestBodySize, "dapr-http-max-request-size", "", -1, "Max size of request body in MB")
367367
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")
368-
RunCmd.Flags().StringVarP(&apiLogLevel, "api-log-level", "", "debug", "The api calls log verbosity. Valid values are: debug, info, off")
368+
RunCmd.Flags().BoolVar(&enableAPILogging, "enable-api-logging", false, "Log API calls at INFO verbosity. Valid values are: true or false")
369369

370370
RootCmd.AddCommand(RunCmd)
371371
}

pkg/standalone/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type RunConfig struct {
5353
MetricsPort int `env:"DAPR_METRICS_PORT" arg:"metrics-port"`
5454
MaxRequestBodySize int `arg:"dapr-http-max-request-size"`
5555
UnixDomainSocket string `arg:"unix-domain-socket"`
56-
APILogLevel string `arg:"api-log-level"`
56+
EnableAPILogging bool `arg:"enable-api-logging"`
5757
}
5858

5959
func (meta *DaprMeta) newAppID() string {

pkg/standalone/run_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ func assertCommonArgs(t *testing.T, basicConfig *RunConfig, output *RunOutput) {
9090
assertArgumentEqual(t, "app-ssl", "", output.DaprCMD.Args)
9191
assertArgumentEqual(t, "metrics-port", "9001", output.DaprCMD.Args)
9292
assertArgumentEqual(t, "dapr-http-max-request-size", "-1", output.DaprCMD.Args)
93-
assertArgumentEqual(t, "api-log-level", basicConfig.APILogLevel, output.DaprCMD.Args)
9493
}
9594

9695
func assertAppEnv(t *testing.T, config *RunConfig, output *RunOutput) {
@@ -149,7 +148,7 @@ func TestRun(t *testing.T) {
149148
AppSSL: true,
150149
MetricsPort: 9001,
151150
MaxRequestBodySize: -1,
152-
APILogLevel: "INFO",
151+
EnableAPILogging: true,
153152
}
154153

155154
t.Run("run happy http", func(t *testing.T) {
@@ -165,7 +164,7 @@ func TestRun(t *testing.T) {
165164
t.Run("run without app command", func(t *testing.T) {
166165
basicConfig.Arguments = nil
167166
basicConfig.LogLevel = "INFO"
168-
basicConfig.APILogLevel = "INFO"
167+
basicConfig.EnableAPILogging = true
169168
basicConfig.ConfigFile = DefaultConfigFilePath()
170169
output, err := Run(basicConfig)
171170
assert.Nil(t, err)

tests/e2e/standalone/standalone_test.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestStandaloneInstall(t *testing.T) {
7070
}
7171
}
7272

73-
func TestApiLogLevel(t *testing.T) {
73+
func TestEnableAPILogging(t *testing.T) {
7474
// Ensure a clean environment.
7575
uninstall()
7676

@@ -79,7 +79,7 @@ func TestApiLogLevel(t *testing.T) {
7979
phase func(*testing.T)
8080
}{
8181
{"test install", testInstall},
82-
{"test run api log level", testRunApiLogLevel},
82+
{"test run enable api logging", testRunEnableAPILogging},
8383
{"test uninstall", testUninstall},
8484
}
8585

@@ -456,17 +456,17 @@ func testRun(t *testing.T) {
456456
})
457457
}
458458

459-
func testRunApiLogLevel(t *testing.T) {
459+
func testRunEnableAPILogging(t *testing.T) {
460460
daprPath := getDaprPath()
461461
args := []string{
462462
"run",
463-
"--app-id", "apiloglevel_info",
464-
"--api-log-level", "info",
463+
"--app-id", "enableApiLogging_info",
464+
"--enable-api-logging",
465465
"--log-level", "info",
466466
"--", "bash", "-c", "echo 'test'",
467467
}
468468

469-
t.Run(fmt.Sprintf("check apiloglevel flag info mode"), func(t *testing.T) {
469+
t.Run(fmt.Sprintf("check enableAPILogging flag in enabled mode"), func(t *testing.T) {
470470
output, err := spawn.Command(daprPath, args...)
471471
t.Log(output)
472472
require.NoError(t, err, "run failed")
@@ -477,19 +477,17 @@ func testRunApiLogLevel(t *testing.T) {
477477

478478
args = []string{
479479
"run",
480-
"--app-id", "apiloglevel_debug",
481-
"--api-log-level", "debug",
482-
"--log-level", "debug",
480+
"--app-id", "enableApiLogging_info",
483481
"--", "bash", "-c", "echo 'test'",
484482
}
485483

486-
t.Run(fmt.Sprintf("check apiloglevel flag debug mode"), func(t *testing.T) {
484+
t.Run(fmt.Sprintf("check enableAPILogging flag in disabled mode"), func(t *testing.T) {
487485
output, err := spawn.Command(daprPath, args...)
488486
t.Log(output)
489487
require.NoError(t, err, "run failed")
490-
assert.Contains(t, output, "level=debug msg=\"HTTP API Called: PUT /v1.0/metadata/appCommand\"")
491488
assert.Contains(t, output, "Exited App successfully")
492489
assert.Contains(t, output, "Exited Dapr successfully")
490+
assert.NotContains(t, output, "level=info msg=\"HTTP API Called: PUT /v1.0/metadata/appCommand\"")
493491
})
494492
}
495493

0 commit comments

Comments
 (0)