From d0276f1d52b3b0801b2ee824739a293829c273f6 Mon Sep 17 00:00:00 2001 From: Ta-Ching Chen Date: Tue, 12 Nov 2019 03:05:22 +0800 Subject: [PATCH] Fix fn test failed to query logs from log database (#1401) When `fn test` failed to retrieve logs from the function pod, it turns to query logs from the log database. However, the logdb type flag is not set to `fn test`, hence the logdb type is empty (even without default value) and cause `fn logs` returns an error due to unable to find the corresponding log database type. This PR adds logdb type flag to `fn test` to resolve the problem. --- pkg/fission-cli/cmd/function/command.go | 6 +++++- pkg/fission-cli/cmd/function/log.go | 2 +- pkg/fission-cli/cmd/function/test.go | 2 +- test/tests/test_ingress.sh | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/fission-cli/cmd/function/command.go b/pkg/fission-cli/cmd/function/command.go index 9e3a5719..ecfc66a3 100644 --- a/pkg/fission-cli/cmd/function/command.go +++ b/pkg/fission-cli/cmd/function/command.go @@ -138,7 +138,11 @@ func Commands() *cobra.Command { wrapper.SetFlags(testCmd, flag.FlagSet{ Required: []flag.Flag{flag.FnName}, Optional: []flag.Flag{flag.HtMethod, flag.FnTestHeader, flag.FnTestBody, - flag.FnTestQuery, flag.FnTestTimeout, flag.NamespaceFunction}, + flag.FnTestQuery, flag.FnTestTimeout, flag.NamespaceFunction, + // for getting log from log database if + // we failed to get logs from function pod. + flag.FnLogDBType, + }, }) command := &cobra.Command{ diff --git a/pkg/fission-cli/cmd/function/log.go b/pkg/fission-cli/cmd/function/log.go index 37de32e2..52930982 100644 --- a/pkg/fission-cli/cmd/function/log.go +++ b/pkg/fission-cli/cmd/function/log.go @@ -73,7 +73,7 @@ func (opts *LogSubCommand) do(input cli.Input) error { // request the controller to establish a proxy server to the database. logDB, err := logdb.GetLogDB(dbType, server) if err != nil { - return errors.New("failed to connect log database") + return errors.Wrapf(err, "failed to get log database") } requestChan := make(chan struct{}) diff --git a/pkg/fission-cli/cmd/function/test.go b/pkg/fission-cli/cmd/function/test.go index 2ae4cd7a..47798275 100644 --- a/pkg/fission-cli/cmd/function/test.go +++ b/pkg/fission-cli/cmd/function/test.go @@ -119,13 +119,13 @@ func (opts *TestSubCommand) do(input cli.Input) error { if resp.StatusCode < 400 { fmt.Print(string(body)) - return nil } fmt.Printf("Error calling function %s: %d; Please try again or fix the error: %s", m.Name, resp.StatusCode, string(body)) err = printPodLogs(input) if err != nil { + fmt.Printf("Error getting function logs from pod: %v. Try to get logs from log database", err) return Log(input) } diff --git a/test/tests/test_ingress.sh b/test/tests/test_ingress.sh index 15157c08..5b9b028f 100755 --- a/test/tests/test_ingress.sh +++ b/test/tests/test_ingress.sh @@ -75,9 +75,11 @@ createFn() { log "Creating function" fission fn create --name $functionName --env $env --code $ROOT/examples/nodejs/hello.js + sleep 3 log "Doing an HTTP GET on the function's route" response=$(fission fn test --name $functionName) + echo $response log "Checking for valid response" echo $response | grep -i hello