mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-03-02 17:50:34 +00:00
Move glog/klog logging to klog/v2
This commit is contained in:
committed by
Ciprian Hacman
parent
eeab0ab06f
commit
e43459d86d
@@ -21,7 +21,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/node-problem-detector/pkg/problemdaemon"
|
||||
"k8s.io/node-problem-detector/pkg/problemmetrics"
|
||||
@@ -63,19 +63,19 @@ func NewLogMonitorOrDie(configPath string) types.Monitor {
|
||||
|
||||
f, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to read configuration file %q: %v", configPath, err)
|
||||
klog.Fatalf("Failed to read configuration file %q: %v", configPath, err)
|
||||
}
|
||||
err = json.Unmarshal(f, &l.config)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to unmarshal configuration file %q: %v", configPath, err)
|
||||
klog.Fatalf("Failed to unmarshal configuration file %q: %v", configPath, err)
|
||||
}
|
||||
// Apply default configurations
|
||||
(&l.config).ApplyDefaultConfiguration()
|
||||
err = l.config.ValidateRules()
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to validate %s matching rules %+v: %v", l.configPath, l.config.Rules, err)
|
||||
klog.Fatalf("Failed to validate %s matching rules %+v: %v", l.configPath, l.config.Rules, err)
|
||||
}
|
||||
glog.Infof("Finish parsing log monitor config file %s: %+v", l.configPath, l.config)
|
||||
klog.Infof("Finish parsing log monitor config file %s: %+v", l.configPath, l.config)
|
||||
|
||||
l.watcher = logwatchers.GetLogWatcherOrDie(l.config.WatcherConfig)
|
||||
l.buffer = NewLogBuffer(l.config.BufferSize)
|
||||
@@ -95,19 +95,19 @@ func initializeProblemMetricsOrDie(rules []systemlogtypes.Rule) {
|
||||
if rule.Type == types.Perm {
|
||||
err := problemmetrics.GlobalProblemMetricsManager.SetProblemGauge(rule.Condition, rule.Reason, false)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to initialize problem gauge metrics for problem %q, reason %q: %v",
|
||||
klog.Fatalf("Failed to initialize problem gauge metrics for problem %q, reason %q: %v",
|
||||
rule.Condition, rule.Reason, err)
|
||||
}
|
||||
}
|
||||
err := problemmetrics.GlobalProblemMetricsManager.IncrementProblemCounter(rule.Reason, 0)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to initialize problem counter metrics for %q: %v", rule.Reason, err)
|
||||
klog.Fatalf("Failed to initialize problem counter metrics for %q: %v", rule.Reason, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (l *logMonitor) Start() (<-chan *types.Status, error) {
|
||||
glog.Infof("Start log monitor %s", l.configPath)
|
||||
klog.Infof("Start log monitor %s", l.configPath)
|
||||
var err error
|
||||
l.logCh, err = l.watcher.Watch()
|
||||
if err != nil {
|
||||
@@ -118,7 +118,7 @@ func (l *logMonitor) Start() (<-chan *types.Status, error) {
|
||||
}
|
||||
|
||||
func (l *logMonitor) Stop() {
|
||||
glog.Infof("Stop log monitor %s", l.configPath)
|
||||
klog.Infof("Stop log monitor %s", l.configPath)
|
||||
l.tomb.Stop()
|
||||
}
|
||||
|
||||
@@ -133,13 +133,13 @@ func (l *logMonitor) monitorLoop() {
|
||||
select {
|
||||
case log, ok := <-l.logCh:
|
||||
if !ok {
|
||||
glog.Errorf("Log channel closed: %s", l.configPath)
|
||||
klog.Errorf("Log channel closed: %s", l.configPath)
|
||||
return
|
||||
}
|
||||
l.parseLog(log)
|
||||
case <-l.tomb.Stopping():
|
||||
l.watcher.Stop()
|
||||
glog.Infof("Log monitor stopped: %s", l.configPath)
|
||||
klog.Infof("Log monitor stopped: %s", l.configPath)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -156,7 +156,7 @@ func (l *logMonitor) parseLog(log *systemlogtypes.Log) {
|
||||
continue
|
||||
}
|
||||
status := l.generateStatus(matched, rule)
|
||||
glog.Infof("New status generated: %+v", status)
|
||||
klog.Infof("New status generated: %+v", status)
|
||||
l.output <- status
|
||||
}
|
||||
}
|
||||
@@ -207,14 +207,14 @@ func (l *logMonitor) generateStatus(logs []*systemlogtypes.Log, rule systemlogty
|
||||
for _, event := range events {
|
||||
err := problemmetrics.GlobalProblemMetricsManager.IncrementProblemCounter(event.Reason, 1)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to update problem counter metrics for %q: %v", event.Reason, err)
|
||||
klog.Errorf("Failed to update problem counter metrics for %q: %v", event.Reason, err)
|
||||
}
|
||||
}
|
||||
for _, condition := range changedConditions {
|
||||
err := problemmetrics.GlobalProblemMetricsManager.SetProblemGauge(
|
||||
condition.Type, condition.Reason, condition.Status == types.True)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to update problem gauge metrics for problem %q, reason %q: %v",
|
||||
klog.Errorf("Failed to update problem gauge metrics for problem %q, reason %q: %v",
|
||||
condition.Type, condition.Reason, err)
|
||||
}
|
||||
}
|
||||
@@ -232,7 +232,7 @@ func (l *logMonitor) generateStatus(logs []*systemlogtypes.Log, rule systemlogty
|
||||
func (l *logMonitor) initializeStatus() {
|
||||
// Initialize the default node conditions
|
||||
l.conditions = initialConditions(l.config.DefaultConditions)
|
||||
glog.Infof("Initialize condition generated: %+v", l.conditions)
|
||||
klog.Infof("Initialize condition generated: %+v", l.conditions)
|
||||
// Update the initial status
|
||||
l.output <- &types.Status{
|
||||
Source: l.config.Source,
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"time"
|
||||
|
||||
utilclock "code.cloudfoundry.org/clock"
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
|
||||
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
|
||||
@@ -48,11 +48,11 @@ type filelogWatcher struct {
|
||||
func NewSyslogWatcherOrDie(cfg types.WatcherConfig) types.LogWatcher {
|
||||
uptime, err := util.GetUptimeDuration()
|
||||
if err != nil {
|
||||
glog.Fatalf("failed to get uptime: %v", err)
|
||||
klog.Fatalf("failed to get uptime: %v", err)
|
||||
}
|
||||
startTime, err := util.GetStartTime(time.Now(), uptime, cfg.Lookback, cfg.Delay)
|
||||
if err != nil {
|
||||
glog.Fatalf("failed to get start time: %v", err)
|
||||
klog.Fatalf("failed to get start time: %v", err)
|
||||
}
|
||||
|
||||
return &filelogWatcher{
|
||||
@@ -77,7 +77,7 @@ func (s *filelogWatcher) Watch() (<-chan *logtypes.Log, error) {
|
||||
}
|
||||
s.reader = bufio.NewReader(r)
|
||||
s.closer = r
|
||||
glog.Info("Start watching filelog")
|
||||
klog.Info("Start watching filelog")
|
||||
go s.watchLoop()
|
||||
return s.logCh, nil
|
||||
}
|
||||
@@ -102,14 +102,14 @@ func (s *filelogWatcher) watchLoop() {
|
||||
for {
|
||||
select {
|
||||
case <-s.tomb.Stopping():
|
||||
glog.Infof("Stop watching filelog")
|
||||
klog.Infof("Stop watching filelog")
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
line, err := s.reader.ReadString('\n')
|
||||
if err != nil && err != io.EOF {
|
||||
glog.Errorf("Exiting filelog watch with error: %v", err)
|
||||
klog.Errorf("Exiting filelog watch with error: %v", err)
|
||||
return
|
||||
}
|
||||
buffer.WriteString(line)
|
||||
@@ -121,12 +121,12 @@ func (s *filelogWatcher) watchLoop() {
|
||||
buffer.Reset()
|
||||
log, err := s.translator.translate(strings.TrimSuffix(line, "\n"))
|
||||
if err != nil {
|
||||
glog.Warningf("Unable to parse line: %q, %v", line, err)
|
||||
klog.Warningf("Unable to parse line: %q, %v", line, err)
|
||||
continue
|
||||
}
|
||||
// Discard messages before start time.
|
||||
if log.Timestamp.Before(s.startTime) {
|
||||
glog.V(5).Infof("Throwing away msg %q before start time: %v < %v", log.Message, log.Timestamp, s.startTime)
|
||||
klog.V(5).Infof("Throwing away msg %q before start time: %v < %v", log.Message, log.Timestamp, s.startTime)
|
||||
continue
|
||||
}
|
||||
s.logCh <- log
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
// translator translates log line into internal log type based on user defined
|
||||
@@ -46,7 +46,7 @@ const (
|
||||
|
||||
func newTranslatorOrDie(pluginConfig map[string]string) *translator {
|
||||
if err := validatePluginConfig(pluginConfig); err != nil {
|
||||
glog.Errorf("Failed to validate plugin configuration %+v: %v", pluginConfig, err)
|
||||
klog.Errorf("Failed to validate plugin configuration %+v: %v", pluginConfig, err)
|
||||
}
|
||||
return &translator{
|
||||
timestampRegexp: regexp.MustCompile(pluginConfig[timestampKey]),
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/coreos/go-systemd/sdjournal"
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
|
||||
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
|
||||
@@ -52,11 +52,11 @@ type journaldWatcher struct {
|
||||
func NewJournaldWatcher(cfg types.WatcherConfig) types.LogWatcher {
|
||||
uptime, err := util.GetUptimeDuration()
|
||||
if err != nil {
|
||||
glog.Fatalf("failed to get uptime: %v", err)
|
||||
klog.Fatalf("failed to get uptime: %v", err)
|
||||
}
|
||||
startTime, err := util.GetStartTime(time.Now(), uptime, cfg.Lookback, cfg.Delay)
|
||||
if err != nil {
|
||||
glog.Fatalf("failed to get start time: %v", err)
|
||||
klog.Fatalf("failed to get start time: %v", err)
|
||||
}
|
||||
|
||||
return &journaldWatcher{
|
||||
@@ -95,21 +95,21 @@ func (j *journaldWatcher) watchLoop() {
|
||||
startTimestamp := timeToJournalTimestamp(j.startTime)
|
||||
defer func() {
|
||||
if err := j.journal.Close(); err != nil {
|
||||
glog.Errorf("Failed to close journal client: %v", err)
|
||||
klog.Errorf("Failed to close journal client: %v", err)
|
||||
}
|
||||
j.tomb.Done()
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case <-j.tomb.Stopping():
|
||||
glog.Infof("Stop watching journald")
|
||||
klog.Infof("Stop watching journald")
|
||||
return
|
||||
default:
|
||||
}
|
||||
// Get next log entry.
|
||||
n, err := j.journal.Next()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to get next journal entry: %v", err)
|
||||
klog.Errorf("Failed to get next journal entry: %v", err)
|
||||
continue
|
||||
}
|
||||
// If next reaches the end, wait for waitLogTimeout.
|
||||
@@ -120,12 +120,12 @@ func (j *journaldWatcher) watchLoop() {
|
||||
|
||||
entry, err := j.journal.GetEntry()
|
||||
if err != nil {
|
||||
glog.Errorf("failed to get journal entry: %v", err)
|
||||
klog.Errorf("failed to get journal entry: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if entry.RealtimeTimestamp < startTimestamp {
|
||||
glog.V(5).Infof("Throwing away journal entry %q before start time: %v < %v",
|
||||
klog.V(5).Infof("Throwing away journal entry %q before start time: %v < %v",
|
||||
entry.Fields[sdjournal.SD_JOURNAL_FIELD_MESSAGE], entry.RealtimeTimestamp, startTimestamp)
|
||||
continue
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func getJournal(cfg types.WatcherConfig, startTime time.Time) (*sdjournal.Journa
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create journal client from default log path: %v", err)
|
||||
}
|
||||
glog.Info("unspecified log path so using systemd default")
|
||||
klog.Info("unspecified log path so using systemd default")
|
||||
} else {
|
||||
// If the path doesn't exist, NewJournalFromDir will
|
||||
// create it instead of returning error. So check the
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
utilclock "code.cloudfoundry.org/clock"
|
||||
"github.com/euank/go-kmsg-parser/kmsgparser"
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
|
||||
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
|
||||
@@ -45,11 +45,11 @@ type kernelLogWatcher struct {
|
||||
func NewKmsgWatcher(cfg types.WatcherConfig) types.LogWatcher {
|
||||
uptime, err := util.GetUptimeDuration()
|
||||
if err != nil {
|
||||
glog.Fatalf("failed to get uptime: %v", err)
|
||||
klog.Fatalf("failed to get uptime: %v", err)
|
||||
}
|
||||
startTime, err := util.GetStartTime(time.Now(), uptime, cfg.Lookback, cfg.Delay)
|
||||
if err != nil {
|
||||
glog.Fatalf("failed to get start time: %v", err)
|
||||
klog.Fatalf("failed to get start time: %v", err)
|
||||
}
|
||||
|
||||
return &kernelLogWatcher{
|
||||
@@ -89,7 +89,7 @@ func (k *kernelLogWatcher) watchLoop() {
|
||||
kmsgs := k.kmsgParser.Parse()
|
||||
defer func() {
|
||||
if err := k.kmsgParser.Close(); err != nil {
|
||||
glog.Errorf("Failed to close kmsg parser: %v", err)
|
||||
klog.Errorf("Failed to close kmsg parser: %v", err)
|
||||
}
|
||||
close(k.logCh)
|
||||
k.tomb.Done()
|
||||
@@ -98,21 +98,21 @@ func (k *kernelLogWatcher) watchLoop() {
|
||||
for {
|
||||
select {
|
||||
case <-k.tomb.Stopping():
|
||||
glog.Infof("Stop watching kernel log")
|
||||
klog.Infof("Stop watching kernel log")
|
||||
return
|
||||
case msg, ok := <-kmsgs:
|
||||
if !ok {
|
||||
glog.Error("Kmsg channel closed")
|
||||
klog.Error("Kmsg channel closed")
|
||||
return
|
||||
}
|
||||
glog.V(5).Infof("got kernel message: %+v", msg)
|
||||
klog.V(5).Infof("got kernel message: %+v", msg)
|
||||
if msg.Message == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Discard messages before start time.
|
||||
if msg.Timestamp.Before(k.startTime) {
|
||||
glog.V(5).Infof("Throwing away msg %q before start time: %v < %v", msg.Message, msg.Timestamp, k.startTime)
|
||||
klog.V(5).Infof("Throwing away msg %q before start time: %v < %v", msg.Message, msg.Timestamp, k.startTime)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -19,13 +19,13 @@ package kmsg
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
|
||||
)
|
||||
|
||||
// NewKmsgWatcher creates a watcher which will read messages from /dev/kmsg
|
||||
func NewKmsgWatcher(cfg types.WatcherConfig) types.LogWatcher {
|
||||
glog.Fatalf("kmsg parser is not supported in %s", runtime.GOOS)
|
||||
klog.Fatalf("kmsg parser is not supported in %s", runtime.GOOS)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package logwatchers
|
||||
import (
|
||||
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
// createFuncs is a table of createFuncs for all supported log watchers.
|
||||
@@ -35,8 +35,8 @@ func registerLogWatcher(name string, create types.WatcherCreateFunc) {
|
||||
func GetLogWatcherOrDie(config types.WatcherConfig) types.LogWatcher {
|
||||
create, ok := createFuncs[config.Plugin]
|
||||
if !ok {
|
||||
glog.Fatalf("No create function found for plugin %q", config.Plugin)
|
||||
klog.Fatalf("No create function found for plugin %q", config.Plugin)
|
||||
}
|
||||
glog.Infof("Use log watcher of plugin %q", config.Plugin)
|
||||
klog.Infof("Use log watcher of plugin %q", config.Plugin)
|
||||
return create(config)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user