mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 18:00:08 +00:00
Make file error logging edge triggered to reduce log spam.
This commit is contained in:
parent
cd0b25f1e5
commit
aa703a4e72
@ -34,6 +34,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
@ -77,13 +78,22 @@ func (s ConfigSourceFile) Run() {
|
|||||||
var lastEndpoints []api.Endpoints
|
var lastEndpoints []api.Endpoints
|
||||||
|
|
||||||
sleep := 5 * time.Second
|
sleep := 5 * time.Second
|
||||||
|
// Used to avoid spamming the error log file, makes error logging edge triggered.
|
||||||
|
hadSuccess := true
|
||||||
for {
|
for {
|
||||||
data, err := ioutil.ReadFile(s.filename)
|
data, err := ioutil.ReadFile(s.filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Couldn't read file: %s : %v", s.filename, err)
|
msg := fmt.Sprintf("Couldn't read file: %s : %v", s.filename, err)
|
||||||
|
if hadSuccess {
|
||||||
|
glog.Error(msg)
|
||||||
|
} else {
|
||||||
|
glog.V(1).Info(msg)
|
||||||
|
}
|
||||||
|
hadSuccess = false
|
||||||
time.Sleep(sleep)
|
time.Sleep(sleep)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
hadSuccess = true
|
||||||
|
|
||||||
if bytes.Equal(lastData, data) {
|
if bytes.Equal(lastData, data) {
|
||||||
time.Sleep(sleep)
|
time.Sleep(sleep)
|
||||||
|
Loading…
Reference in New Issue
Block a user