From 5686f8e7fb68934acc9d1477e84267bece5437fb Mon Sep 17 00:00:00 2001 From: zhuangqh Date: Wed, 17 Oct 2018 21:53:44 +0800 Subject: [PATCH] fix several inconsistent Signed-off-by: zhuangqh --- apis/server/exec_bridge.go | 3 +++ apis/server/log_filter_writer.go | 21 +++++++++++++++++++++ apis/server/server.go | 11 ++++++++++- daemon/mgr/container_utils.go | 7 +------ 4 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 apis/server/log_filter_writer.go diff --git a/apis/server/exec_bridge.go b/apis/server/exec_bridge.go index 7c5924c6b..f3467d7a6 100644 --- a/apis/server/exec_bridge.go +++ b/apis/server/exec_bridge.go @@ -57,6 +57,9 @@ func (s *Server) startContainerExec(ctx context.Context, rw http.ResponseWriter, name := mux.Vars(req)["name"] _, upgrade := req.Header["Upgrade"] + ba, _ := json.Marshal(config) + logrus.Infof("start exec %s, upgrade: %v, body: %s", name, upgrade, string(ba)) + if err := s.ContainerMgr.CheckExecExist(ctx, name); err != nil { return err } diff --git a/apis/server/log_filter_writer.go b/apis/server/log_filter_writer.go new file mode 100644 index 000000000..547513e58 --- /dev/null +++ b/apis/server/log_filter_writer.go @@ -0,0 +1,21 @@ +package server + +import ( + "bytes" + "io" + "os" +) + +type filterLogWriter struct { + io.Writer +} + +var stdFilterLogWriter filterLogWriter +var filterString = []byte("http: TLS handshake error from") + +func (w filterLogWriter) Write(p []byte) (n int, err error) { + if bytes.Contains(p, filterString) { + return 0, nil + } + return os.Stderr.Write(p) +} diff --git a/apis/server/server.go b/apis/server/server.go index 18546672d..0f302cbcf 100644 --- a/apis/server/server.go +++ b/apis/server/server.go @@ -2,10 +2,12 @@ package server import ( "crypto/tls" + "log" "net" "net/http" "strings" "sync" + "time" "github.com/alibaba/pouch/apis/plugins" "github.com/alibaba/pouch/cri/stream" @@ -68,7 +70,14 @@ func (s *Server) Start(readyCh chan bool) (err error) { s.listeners = append(s.listeners, l) go func(l net.Listener) { - errCh <- http.Serve(l, router) + s := &http.Server{ + Handler: router, + ErrorLog: log.New(stdFilterLogWriter, "", 0), + ReadTimeout: time.Minute * 10, + ReadHeaderTimeout: time.Minute * 10, + IdleTimeout: time.Minute * 10, + } + errCh <- s.Serve(l) }(l) } diff --git a/daemon/mgr/container_utils.go b/daemon/mgr/container_utils.go index e586f2258..530bcdd0e 100644 --- a/daemon/mgr/container_utils.go +++ b/daemon/mgr/container_utils.go @@ -50,18 +50,13 @@ func (mgr *ContainerManager) containerID(nameOrPrefix string) (string, error) { } func (mgr *ContainerManager) container(nameOrPrefix string) (*Container, error) { - res, ok := mgr.cache.Get(nameOrPrefix).Result() - if ok { - return res.(*Container), nil - } - id, err := mgr.containerID(nameOrPrefix) if err != nil { return nil, err } // lookup again - res, ok = mgr.cache.Get(id).Result() + res, ok := mgr.cache.Get(id).Result() if ok { return res.(*Container), nil }