From 69c72280069766ddc10a95c69efec0f5e25d573c Mon Sep 17 00:00:00 2001 From: jhadvig Date: Tue, 21 Oct 2014 01:39:01 +0200 Subject: [PATCH 1/2] Flush data periodically instead of their buffering --- pkg/apiserver/proxy.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/apiserver/proxy.go b/pkg/apiserver/proxy.go index a8abe07826a..879a88819fb 100644 --- a/pkg/apiserver/proxy.go +++ b/pkg/apiserver/proxy.go @@ -25,6 +25,7 @@ import ( "net/url" "path" "strings" + "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/httplog" @@ -137,6 +138,7 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { proxyHost: req.URL.Host, proxyPathPrepend: path.Join(r.prefix, resourceName, id), } + proxy.FlushInterval = 200 * time.Millisecond proxy.ServeHTTP(w, newReq) } From f759bfdf7153d70d1964a21ca579eec92c88a612 Mon Sep 17 00:00:00 2001 From: jhadvig Date: Tue, 21 Oct 2014 01:41:23 +0200 Subject: [PATCH 2/2] Implementing Flush method to httplog --- pkg/httplog/log.go | 10 ++++++++++ pkg/kubelet/server.go | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/httplog/log.go b/pkg/httplog/log.go index fc594fd1d0a..757a15b5e5c 100644 --- a/pkg/httplog/log.go +++ b/pkg/httplog/log.go @@ -161,6 +161,16 @@ func (rl *respLogger) Write(b []byte) (int, error) { return rl.w.Write(b) } +// Flush implements http.Flusher even if the underlying http.Writer doesn't implement it. +// Flush is used for streaming purposes and allows to flush buffered data to the client. +func (rl *respLogger) Flush() { + if flusher, ok := rl.w.(http.Flusher); ok { + flusher.Flush() + } else { + glog.V(2).Infof("Unable to convert %v into http.Flusher", rl.w) + } +} + // WriteHeader implements http.ResponseWriter. func (rl *respLogger) WriteHeader(status int) { rl.status = status diff --git a/pkg/kubelet/server.go b/pkg/kubelet/server.go index 3840598fe4c..0971317d6cc 100644 --- a/pkg/kubelet/server.go +++ b/pkg/kubelet/server.go @@ -212,8 +212,10 @@ func (s *Server) handleContainerLogs(w http.ResponseWriter, req *http.Request) { }) fw := FlushWriter{writer: w} - if flusher, ok := w.(http.Flusher); ok { + if flusher, ok := fw.writer.(http.Flusher); ok { fw.flusher = flusher + } else { + s.error(w, fmt.Errorf("Unable to convert %v into http.Flusher", fw)) } w.Header().Set("Transfer-Encoding", "chunked") w.WriteHeader(http.StatusOK)