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.
This commit is contained in:
Ta-Ching Chen
2019-11-12 03:05:22 +08:00
committed by GitHub
parent 4474f5f813
commit d0276f1d52
4 changed files with 9 additions and 3 deletions
+5 -1
View File
@@ -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{
+1 -1
View File
@@ -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{})
+1 -1
View File
@@ -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)
}