Commit a9f0c468 authored by Alex Robinson's avatar Alex Robinson

Limit the logging from kubelet attempting to read its manifest URL.

Without this, it logs an error every 20 seconds if nothing is at the provided URL.
parent cf011cad
......@@ -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
}
}
}
......
......@@ -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)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment