diff --git a/pkg/kubelet/config/http.go b/pkg/kubelet/config/http.go index 8e2c0d96fc5..9467915b966 100644 --- a/pkg/kubelet/config/http.go +++ b/pkg/kubelet/config/http.go @@ -32,11 +32,12 @@ import ( ) type sourceURL struct { - url string - header http.Header - nodeName string - updates chan<- interface{} - data []byte + url string + header http.Header + nodeName string + updates chan<- interface{} + data []byte + failureLogs int } func NewSourceURL(url string, header http.Header, nodeName string, period time.Duration, updates chan<- interface{}) { @@ -53,7 +54,19 @@ func NewSourceURL(url string, header http.Header, nodeName string, period time.D func (s *sourceURL) run() { if err := s.extractFromURL(); err != nil { - glog.Errorf("Failed to read URL: %v", err) + // Don't log this multiple times per minute. The first few entries should be + // enough to get the point across. + if s.failureLogs < 3 { + glog.Warningf("Failed to read pods from URL: %v", err) + } else if s.failureLogs == 3 { + glog.Warningf("Failed to read pods from URL. Won't log this message anymore: %v", err) + } + s.failureLogs++ + } else { + if s.failureLogs > 0 { + glog.Info("Successfully read pods from URL.") + s.failureLogs = 0 + } } } diff --git a/pkg/kubelet/config/http_test.go b/pkg/kubelet/config/http_test.go index 3c71f310c9d..69e3faaa146 100644 --- a/pkg/kubelet/config/http_test.go +++ b/pkg/kubelet/config/http_test.go @@ -44,7 +44,7 @@ func TestURLErrorNotExistNoUpdate(t *testing.T) { func TestExtractFromHttpBadness(t *testing.T) { ch := make(chan interface{}, 1) - c := sourceURL{"http://localhost:49575/_not_found_", http.Header{}, "other", ch, nil} + c := sourceURL{"http://localhost:49575/_not_found_", http.Header{}, "other", ch, nil, 0} if err := c.extractFromURL(); err == nil { t.Errorf("Expected error") } @@ -113,7 +113,7 @@ func TestExtractInvalidPods(t *testing.T) { testServer := httptest.NewServer(&fakeHandler) defer testServer.Close() ch := make(chan interface{}, 1) - c := sourceURL{testServer.URL, http.Header{}, "localhost", ch, nil} + c := sourceURL{testServer.URL, http.Header{}, "localhost", ch, nil, 0} if err := c.extractFromURL(); err == nil { t.Errorf("%s: Expected error", testCase.desc) } @@ -260,7 +260,7 @@ func TestExtractPodsFromHTTP(t *testing.T) { testServer := httptest.NewServer(&fakeHandler) defer testServer.Close() ch := make(chan interface{}, 1) - c := sourceURL{testServer.URL, http.Header{}, hostname, ch, nil} + c := sourceURL{testServer.URL, http.Header{}, hostname, ch, nil, 0} if err := c.extractFromURL(); err != nil { t.Errorf("%s: Unexpected error: %v", testCase.desc, err) continue @@ -307,7 +307,7 @@ func TestURLWithHeader(t *testing.T) { ch := make(chan interface{}, 1) header := make(http.Header) header.Set("Metadata-Flavor", "Google") - c := sourceURL{testServer.URL, header, "localhost", ch, nil} + c := sourceURL{testServer.URL, header, "localhost", ch, nil, 0} if err := c.extractFromURL(); err != nil { t.Fatalf("Unexpected error extracting from URL: %v", err) }