Skip to content

Commit

Permalink
Changed API logging feature on CLI (#936)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
amulyavarote and mukundansundar authored Mar 30, 2022
1 parent db56a25 commit 3684654
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/kind_e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/self_hosted_e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
metricsPort int
maxRequestBodySize int
unixDomainSocket string
apiLogLevel string
enableAPILogging bool
)

const (
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/standalone/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions pkg/standalone/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
20 changes: 9 additions & 11 deletions tests/e2e/standalone/standalone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestStandaloneInstall(t *testing.T) {
}
}

func TestApiLogLevel(t *testing.T) {
func TestEnableAPILogging(t *testing.T) {
// Ensure a clean environment.
uninstall()

Expand All @@ -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},
}

Expand Down Expand Up @@ -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")
Expand All @@ -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\"")
})
}

Expand Down

0 comments on commit 3684654

Please sign in to comment.