add --debug to show queries and error details

This commit is contained in:
Victor Shyba 2021-08-13 18:36:43 -03:00
parent d71e91c58e
commit b4782ce6ac
3 changed files with 9 additions and 1 deletions

View file

@ -49,6 +49,7 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
parser := argparse.NewParser("hub", "hub server and client")
serveCmd := parser.NewCommand("serve", "start the hub server")
debug := parser.Flag("", "debug", &argparse.Options{Required: false, Help: "enable debug logging", Default: false})
host := parser.String("", "rpchost", &argparse.Options{Required: false, Help: "RPC host", Default: defaultHost})
port := parser.String("", "rpcport", &argparse.Options{Required: false, Help: "RPC port", Default: defaultPort})
@ -79,6 +80,7 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
EsHost: *esHost,
EsPort: *esPort,
EsIndex: *esIndex,
Debug: *debug,
}
if esHost, ok := environment["ELASTIC_HOST"]; ok {

View file

@ -8,6 +8,7 @@ import (
"fmt"
"log"
"math"
"os"
"reflect"
"strings"
"time"
@ -146,7 +147,11 @@ func (s *Server) Search(ctx context.Context, in *pb.SearchRequest) (*pb.Outputs,
var client *elastic.Client = nil
if s.EsClient == nil {
esUrl := s.Args.EsHost + ":" + s.Args.EsPort
tmpClient, err := elastic.NewClient(elastic.SetURL(esUrl), elastic.SetSniff(false))
opts := []elastic.ClientOptionFunc{elastic.SetSniff(false), elastic.SetURL(esUrl)}
if s.Args.Debug {
opts = append(opts, elastic.SetTraceLog(log.New(os.Stderr, "[[ELASTIC]]", 0)))
}
tmpClient, err := elastic.NewClient(opts...)
if err != nil {
log.Println(err)
return nil, err

View file

@ -25,6 +25,7 @@ type Args struct {
EsHost string
EsPort string
EsIndex string
Debug bool
}
/*