mirror of https://github.com/dapr/cli.git
Added api-log-level flag to log api calls (#903)
* Added api-log-level flag to log api calls Signed-off-by: Amulya Varote <amulyavarote@QTM-SWATHIKIL-1.redmond.corp.microsoft.com> Signed-off-by: Amulya Varote <amulyavarote@Amulyas-MacBook-Pro.local> * Added api-log-level to README Signed-off-by: Amulya Varote <amulyavarote@QTM-SWATHIKIL-1.redmond.corp.microsoft.com> Signed-off-by: Amulya Varote <amulyavarote@Amulyas-MacBook-Pro.local> * Removed the test case for api-log-level Signed-off-by: Amulya Varote <amulyavarote@Amulyas-MacBook-Pro.local> * Removed Readme changes Signed-off-by: Amulya Varote <amulyavarote@Amulyas-MacBook-Pro.local> * Added back all the changes Signed-off-by: Amulya Varote <amulyavarote@Amulyas-MacBook-Pro.local> * Updated dapr RC version Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * kind e2e changes Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Changed README file Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Changed dashboard version Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Fixing Go mod tidy. Signed-off-by: Artur Souza <artursouza.ms@outlook.com> * Reverted dashboard version Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Reverted dashboard version Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Changed dapr dashboard link Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Changed dapr dashboard link Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Changed version extract link for kind Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Changed version extract link for self hosted Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * defined variable in kind Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * stadalone e2e test for api log level Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com> Co-authored-by: Amulya Varote <amulyavarote@Amulyas-MacBook-Pro.local> Co-authored-by: Artur Souza <artursouza.ms@outlook.com> Co-authored-by: Pravin Pushkar <ppushkar@microsoft.com>
This commit is contained in:
parent
6262b933f8
commit
db56a250bc
|
@ -46,8 +46,9 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
env:
|
||||
GOVER: 1.17
|
||||
DAPR_RUNTIME_VERSION: 1.6.0
|
||||
DAPR_DASHBOARD_VERSION: 0.9.0
|
||||
DAPR_RUNTIME_VERSION: 1.7.0-rc.1
|
||||
DAPR_DASHBOARD_VERSION: 0.10.0-rc.1
|
||||
DAPR_TGZ: dapr-1.7.0-rc.1.tgz
|
||||
strategy:
|
||||
fail-fast: false # Keep running if one leg fails.
|
||||
matrix:
|
||||
|
@ -115,10 +116,8 @@ jobs:
|
|||
- role: worker
|
||||
image: kindest/node:${{ matrix.k8s-version }}@${{ matrix.kind-image-sha }}
|
||||
EOF
|
||||
|
||||
# Log the generated kind.yaml for easy reference.
|
||||
cat kind.yaml
|
||||
|
||||
- name: Create KinD Cluster
|
||||
uses: helm/kind-action@v1.0.0
|
||||
with:
|
||||
|
@ -133,7 +132,6 @@ jobs:
|
|||
-lkubernetes.io/hostname!=kind-control-plane \
|
||||
-ojsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}')
|
||||
echo "MINIKUBE_NODE_IP=$NODE_IP" >> $GITHUB_ENV
|
||||
|
||||
- name: Free up some diskspace
|
||||
run: |
|
||||
docker image prune -a -f
|
||||
|
@ -147,7 +145,7 @@ jobs:
|
|||
- name: Determine latest Dapr Dashboard version including Pre-releases
|
||||
if: github.base_ref == 'master'
|
||||
run: |
|
||||
helm pull dapr/dapr --untar && export DASHBOARD_VERSION=$(cat ./dapr/charts/dapr_dashboard/Chart.yaml | grep version | awk '{ print $2; exit }') && rm -rf dapr
|
||||
curl -L -o dapr.tgz https://github.com/dapr/helm-charts/raw/master/$DAPR_TGZ && tar -xzf dapr.tgz && export DASHBOARD_VERSION=$(cat ./dapr/charts/dapr_dashboard/Chart.yaml | grep version | awk '{ print $2; exit }') && rm -rf dapr
|
||||
echo "DAPR_DASHBOARD_VERSION=$DASHBOARD_VERSION" >> $GITHUB_ENV
|
||||
echo "Found $DASHBOARD_VERSION"
|
||||
shell: bash
|
||||
|
|
|
@ -36,8 +36,9 @@ jobs:
|
|||
GOARCH: ${{ matrix.target_arch }}
|
||||
GOPROXY: https://proxy.golang.org
|
||||
ARCHIVE_OUTDIR: dist/archives
|
||||
DAPR_RUNTIME_VERSION: "1.6.0"
|
||||
DAPR_DASHBOARD_VERSION: 0.9.0
|
||||
DAPR_RUNTIME_VERSION: "1.7.0-rc.1"
|
||||
DAPR_DASHBOARD_VERSION: 0.10.0-rc.1
|
||||
DAPR_TGZ: dapr-1.7.0-rc.1.tgz
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
|
@ -72,7 +73,7 @@ jobs:
|
|||
- name: Determine latest Dapr Dashboard version including Pre-releases
|
||||
if: github.base_ref == 'master'
|
||||
run: |
|
||||
helm pull dapr/dapr --untar && export DASHBOARD_VERSION=$(cat ./dapr/charts/dapr_dashboard/Chart.yaml | grep version | awk '{ print $2; exit }') && rm -rf dapr
|
||||
curl -L -o dapr.tgz https://github.com/dapr/helm-charts/raw/master/$DAPR_TGZ && tar -xzf dapr.tgz && export DASHBOARD_VERSION=$(cat ./dapr/charts/dapr_dashboard/Chart.yaml | grep version | awk '{ print $2; exit }') && rm -rf dapr
|
||||
echo "DAPR_DASHBOARD_VERSION=$DASHBOARD_VERSION" >> $GITHUB_ENV
|
||||
echo "Found $DASHBOARD_VERSION"
|
||||
shell: bash
|
||||
|
|
2
Makefile
2
Makefile
|
@ -188,7 +188,7 @@ e2e-build-run-sh: build test-e2e-sh
|
|||
################################################################################
|
||||
.PHONY: go.mod
|
||||
go.mod:
|
||||
go mod tidy
|
||||
go mod tidy -compat=1.17
|
||||
|
||||
################################################################################
|
||||
# Target: check-diff #
|
||||
|
|
11
README.md
11
README.md
|
@ -586,6 +586,17 @@ If you want to invoke your app, also use this flag:
|
|||
$ 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:
|
||||
|
||||
```bash
|
||||
dapr run --app-id nodeapp --app-port 3000 node app.js --api-log-level info
|
||||
```
|
||||
|
||||
This sets the Dapr API log level to `info`.
|
||||
The default is `debug`.
|
||||
|
||||
For more details, please run the command and check the examples to apply to your shell.
|
||||
|
||||
## Reference for the Dapr CLI
|
||||
|
|
|
@ -47,6 +47,7 @@ var (
|
|||
metricsPort int
|
||||
maxRequestBodySize int
|
||||
unixDomainSocket string
|
||||
apiLogLevel string
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -115,6 +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,
|
||||
})
|
||||
if err != nil {
|
||||
print.FailureStatusEvent(os.Stderr, err.Error())
|
||||
|
@ -363,6 +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")
|
||||
|
||||
RootCmd.AddCommand(RunCmd)
|
||||
}
|
||||
|
|
12
go.mod
12
go.mod
|
@ -5,7 +5,7 @@ go 1.17
|
|||
require (
|
||||
github.com/Pallinder/sillyname-go v0.0.0-20130730142914-97aeae9e6ba1
|
||||
github.com/briandowns/spinner v1.6.1
|
||||
github.com/dapr/dapr v1.6.0
|
||||
github.com/dapr/dapr v1.7.0-rc.1
|
||||
github.com/dapr/go-sdk v1.0.0
|
||||
github.com/docker/docker v20.10.12+incompatible
|
||||
github.com/fatih/color v1.13.0
|
||||
|
@ -21,7 +21,7 @@ require (
|
|||
github.com/spf13/cobra v1.3.0
|
||||
github.com/spf13/viper v1.10.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
|
||||
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
helm.sh/helm/v3 v3.8.1
|
||||
k8s.io/api v0.23.4
|
||||
|
@ -99,7 +99,7 @@ require (
|
|||
github.com/jmoiron/sqlx v1.3.4 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.13.6 // indirect
|
||||
github.com/klauspost/compress v1.14.4 // indirect
|
||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
|
||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
|
||||
github.com/lib/pq v1.10.4 // indirect
|
||||
|
@ -131,7 +131,7 @@ require (
|
|||
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/prometheus/client_golang v1.11.0 // indirect
|
||||
github.com/prometheus/client_golang v1.11.1 // indirect
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.32.1 // indirect
|
||||
github.com/prometheus/procfs v0.7.3 // indirect
|
||||
|
@ -152,13 +152,13 @@ require (
|
|||
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
|
||||
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
|
||||
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
|
||||
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 // indirect
|
||||
golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
|
||||
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
|
||||
google.golang.org/grpc v1.43.0 // indirect
|
||||
|
|
|
@ -53,6 +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"`
|
||||
}
|
||||
|
||||
func (meta *DaprMeta) newAppID() string {
|
||||
|
|
|
@ -90,6 +90,7 @@ 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) {
|
||||
|
@ -148,6 +149,7 @@ func TestRun(t *testing.T) {
|
|||
AppSSL: true,
|
||||
MetricsPort: 9001,
|
||||
MaxRequestBodySize: -1,
|
||||
APILogLevel: "INFO",
|
||||
}
|
||||
|
||||
t.Run("run happy http", func(t *testing.T) {
|
||||
|
@ -163,6 +165,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.ConfigFile = DefaultConfigFilePath()
|
||||
output, err := Run(basicConfig)
|
||||
assert.Nil(t, err)
|
||||
|
|
|
@ -70,6 +70,24 @@ func TestStandaloneInstall(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestApiLogLevel(t *testing.T) {
|
||||
// Ensure a clean environment.
|
||||
uninstall()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
phase func(*testing.T)
|
||||
}{
|
||||
{"test install", testInstall},
|
||||
{"test run api log level", testRunApiLogLevel},
|
||||
{"test uninstall", testUninstall},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, tc.phase)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNegativeScenarios(t *testing.T) {
|
||||
// Ensure a clean environment
|
||||
uninstall()
|
||||
|
@ -438,6 +456,43 @@ func testRun(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func testRunApiLogLevel(t *testing.T) {
|
||||
daprPath := getDaprPath()
|
||||
args := []string{
|
||||
"run",
|
||||
"--app-id", "apiloglevel_info",
|
||||
"--api-log-level", "info",
|
||||
"--log-level", "info",
|
||||
"--", "bash", "-c", "echo 'test'",
|
||||
}
|
||||
|
||||
t.Run(fmt.Sprintf("check apiloglevel flag info 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=info msg=\"HTTP API Called: PUT /v1.0/metadata/appCommand\"")
|
||||
assert.Contains(t, output, "Exited App successfully")
|
||||
assert.Contains(t, output, "Exited Dapr successfully")
|
||||
})
|
||||
|
||||
args = []string{
|
||||
"run",
|
||||
"--app-id", "apiloglevel_debug",
|
||||
"--api-log-level", "debug",
|
||||
"--log-level", "debug",
|
||||
"--", "bash", "-c", "echo 'test'",
|
||||
}
|
||||
|
||||
t.Run(fmt.Sprintf("check apiloglevel flag debug 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")
|
||||
})
|
||||
}
|
||||
|
||||
func executeAgainstRunningDapr(t *testing.T, f func(), daprArgs ...string) {
|
||||
daprPath := getDaprPath()
|
||||
|
||||
|
|
|
@ -61,6 +61,22 @@ var supportedUpgradePaths = []upgradePath{
|
|||
CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io"},
|
||||
},
|
||||
},
|
||||
{
|
||||
previous: common.VersionDetails{
|
||||
RuntimeVersion: "1.6.0",
|
||||
DashboardVersion: "0.9.0",
|
||||
ClusterRoles: []string{"dapr-operator-admin", "dashboard-reader"},
|
||||
ClusterRoleBindings: []string{"dapr-operator", "dapr-role-tokenreview-binding", "dashboard-reader-global"},
|
||||
CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io"},
|
||||
},
|
||||
next: common.VersionDetails{
|
||||
RuntimeVersion: "1.7.0-rc.1",
|
||||
DashboardVersion: "0.10.0-rc.1",
|
||||
ClusterRoles: []string{"dapr-operator-admin", "dashboard-reader"},
|
||||
ClusterRoleBindings: []string{"dapr-operator", "dapr-role-tokenreview-binding", "dashboard-reader-global"},
|
||||
CustomResourceDefs: []string{"components.dapr.io", "configurations.dapr.io", "subscriptions.dapr.io"},
|
||||
},
|
||||
},
|
||||
// test downgrade
|
||||
{
|
||||
previous: common.VersionDetails{
|
||||
|
|
Loading…
Reference in New Issue