Move glog/klog logging to klog/v2

This commit is contained in:
Manuel Rüger
2023-09-17 08:57:33 +03:00
committed by Ciprian Hacman
parent eeab0ab06f
commit e43459d86d
56 changed files with 233 additions and 2530 deletions
@@ -21,7 +21,7 @@ import (
"os"
"time"
"github.com/golang/glog"
"k8s.io/klog/v2"
"k8s.io/node-problem-detector/pkg/custompluginmonitor/plugin"
cpmtypes "k8s.io/node-problem-detector/pkg/custompluginmonitor/types"
@@ -59,25 +59,25 @@ func NewCustomPluginMonitorOrDie(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, &c.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 configurations
err = (&c.config).ApplyConfiguration()
if err != nil {
glog.Fatalf("Failed to apply configuration for %q: %v", configPath, err)
klog.Fatalf("Failed to apply configuration for %q: %v", configPath, err)
}
// Validate configurations
err = c.config.Validate()
if err != nil {
glog.Fatalf("Failed to validate custom plugin config %+v: %v", c.config, err)
klog.Fatalf("Failed to validate custom plugin config %+v: %v", c.config, err)
}
glog.Infof("Finish parsing custom plugin monitor config file %s: %+v", c.configPath, c.config)
klog.Infof("Finish parsing custom plugin monitor config file %s: %+v", c.configPath, c.config)
c.plugin = plugin.NewPlugin(c.config)
// A 1000 size channel should be big enough.
@@ -96,26 +96,26 @@ func initializeProblemMetricsOrDie(rules []*cpmtypes.CustomRule) {
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 (c *customPluginMonitor) Start() (<-chan *types.Status, error) {
glog.Infof("Start custom plugin monitor %s", c.configPath)
klog.Infof("Start custom plugin monitor %s", c.configPath)
go c.plugin.Run()
go c.monitorLoop()
return c.statusChan, nil
}
func (c *customPluginMonitor) Stop() {
glog.Infof("Stop custom plugin monitor %s", c.configPath)
klog.Infof("Stop custom plugin monitor %s", c.configPath)
c.tomb.Stop()
}
@@ -133,16 +133,16 @@ func (c *customPluginMonitor) monitorLoop() {
select {
case result, ok := <-resultChan:
if !ok {
glog.Errorf("Result channel closed: %s", c.configPath)
klog.Errorf("Result channel closed: %s", c.configPath)
return
}
glog.V(3).Infof("Receive new plugin result for %s: %+v", c.configPath, result)
klog.V(3).Infof("Receive new plugin result for %s: %+v", c.configPath, result)
status := c.generateStatus(result)
glog.V(3).Infof("New status generated: %+v", status)
klog.V(3).Infof("New status generated: %+v", status)
c.statusChan <- status
case <-c.tomb.Stopping():
c.plugin.Stop()
glog.Infof("Custom plugin monitor stopped: %s", c.configPath)
klog.Infof("Custom plugin monitor stopped: %s", c.configPath)
c.tomb.Done()
return
}
@@ -256,7 +256,7 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat
err := problemmetrics.GlobalProblemMetricsManager.IncrementProblemCounter(
event.Reason, 1)
if err != nil {
glog.Errorf("Failed to update problem counter metrics for %q: %v",
klog.Errorf("Failed to update problem counter metrics for %q: %v",
event.Reason, err)
}
}
@@ -264,7 +264,7 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat
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)
}
}
@@ -277,7 +277,7 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat
}
// Log only if condition has changed
if len(activeProblemEvents) != 0 || len(inactiveProblemEvents) != 0 {
glog.V(0).Infof("New status generated: %+v", status)
klog.V(0).Infof("New status generated: %+v", status)
}
return status
}
@@ -297,7 +297,7 @@ func toConditionStatus(s cpmtypes.Status) types.ConditionStatus {
func (c *customPluginMonitor) initializeStatus() {
// Initialize the default node conditions
c.conditions = initialConditions(c.config.DefaultConditions)
glog.Infof("Initialize condition generated: %+v", c.conditions)
klog.Infof("Initialize condition generated: %+v", c.conditions)
// Update the initial status
c.statusChan <- &types.Status{
Source: c.config.Source,
+21 -21
View File
@@ -26,7 +26,7 @@ import (
"syscall"
"time"
"github.com/golang/glog"
"k8s.io/klog/v2"
cpmtypes "k8s.io/node-problem-detector/pkg/custompluginmonitor/types"
"k8s.io/node-problem-detector/pkg/util"
"k8s.io/node-problem-detector/pkg/util/tomb"
@@ -60,7 +60,7 @@ func (p *Plugin) GetResultChan() <-chan cpmtypes.Result {
func (p *Plugin) Run() {
defer func() {
glog.Info("Stopping plugin execution")
klog.Info("Stopping plugin execution")
close(p.resultChan)
p.tomb.Done()
}()
@@ -89,7 +89,7 @@ func (p *Plugin) Run() {
// run each rule in parallel and wait for them to complete
func (p *Plugin) runRules() {
glog.V(3).Info("Start to run custom plugins")
klog.V(3).Info("Start to run custom plugins")
for _, rule := range p.config.Rules {
// syncChan limits concurrent goroutines to configured PluginGlobalConfig.Concurrency value
@@ -103,12 +103,12 @@ func (p *Plugin) runRules() {
start := time.Now()
exitStatus, message := p.run(*rule)
level := glog.Level(3)
level := klog.Level(3)
if exitStatus != 0 {
level = glog.Level(2)
level = klog.Level(2)
}
glog.V(level).Infof("Rule: %+v. Start time: %v. End time: %v. Duration: %v", rule, start, time.Now(), time.Since(start))
klog.V(level).Infof("Rule: %+v. Start time: %v. End time: %v. Duration: %v", rule, start, time.Now(), time.Since(start))
result := cpmtypes.Result{
Rule: rule,
@@ -120,12 +120,12 @@ func (p *Plugin) runRules() {
p.resultChan <- result
// Let the result be logged at a higher verbosity level. If there is a change in status it is logged later.
glog.V(level).Infof("Add check result %+v for rule %+v", result, rule)
klog.V(level).Infof("Add check result %+v for rule %+v", result, rule)
}(rule)
}
p.Wait()
glog.V(3).Info("Finish running custom plugins")
klog.V(3).Info("Finish running custom plugins")
}
// readFromReader reads the maxBytes from the reader and drains the rest.
@@ -157,16 +157,16 @@ func (p *Plugin) run(rule cpmtypes.CustomRule) (exitStatus cpmtypes.Status, outp
stdoutPipe, err := cmd.StdoutPipe()
if err != nil {
glog.Errorf("Error creating stdout pipe for plugin %q: error - %v", rule.Path, err)
klog.Errorf("Error creating stdout pipe for plugin %q: error - %v", rule.Path, err)
return cpmtypes.Unknown, "Error creating stdout pipe for plugin. Please check the error log"
}
stderrPipe, err := cmd.StderrPipe()
if err != nil {
glog.Errorf("Error creating stderr pipe for plugin %q: error - %v", rule.Path, err)
klog.Errorf("Error creating stderr pipe for plugin %q: error - %v", rule.Path, err)
return cpmtypes.Unknown, "Error creating stderr pipe for plugin. Please check the error log"
}
if err := cmd.Start(); err != nil {
glog.Errorf("Error in starting plugin %q: error - %v", rule.Path, err)
klog.Errorf("Error in starting plugin %q: error - %v", rule.Path, err)
return cpmtypes.Unknown, "Error in starting plugin. Please check the error log"
}
@@ -182,9 +182,9 @@ func (p *Plugin) run(rule cpmtypes.CustomRule) (exitStatus cpmtypes.Status, outp
if ctx.Err() == context.Canceled {
return
}
glog.Errorf("Error in running plugin timeout %q", rule.Path)
klog.Errorf("Error in running plugin timeout %q", rule.Path)
if cmd.Process == nil || cmd.Process.Pid == 0 {
glog.Errorf("Error in cmd.Process check %q", rule.Path)
klog.Errorf("Error in cmd.Process check %q", rule.Path)
break
}
@@ -194,7 +194,7 @@ func (p *Plugin) run(rule cpmtypes.CustomRule) (exitStatus cpmtypes.Status, outp
err := util.Kill(cmd)
if err != nil {
glog.Errorf("Error in kill process %d, %v", cmd.Process.Pid, err)
klog.Errorf("Error in kill process %d, %v", cmd.Process.Pid, err)
}
case <-waitChan:
return
@@ -223,18 +223,18 @@ func (p *Plugin) run(rule cpmtypes.CustomRule) (exitStatus cpmtypes.Status, outp
wg.Wait()
if stdoutErr != nil {
glog.Errorf("Error reading stdout for plugin %q: error - %v", rule.Path, err)
klog.Errorf("Error reading stdout for plugin %q: error - %v", rule.Path, err)
return cpmtypes.Unknown, "Error reading stdout for plugin. Please check the error log"
}
if stderrErr != nil {
glog.Errorf("Error reading stderr for plugin %q: error - %v", rule.Path, err)
klog.Errorf("Error reading stderr for plugin %q: error - %v", rule.Path, err)
return cpmtypes.Unknown, "Error reading stderr for plugin. Please check the error log"
}
if err := cmd.Wait(); err != nil {
if _, ok := err.(*exec.ExitError); !ok {
glog.Errorf("Error in waiting for plugin %q: error - %v. output - %q", rule.Path, err, string(stdout))
klog.Errorf("Error in waiting for plugin %q: error - %v. output - %q", rule.Path, err, string(stdout))
return cpmtypes.Unknown, "Error in waiting for plugin. Please check the error log"
}
}
@@ -273,12 +273,12 @@ func (p *Plugin) run(rule cpmtypes.CustomRule) (exitStatus cpmtypes.Status, outp
// Stop the plugin.
func (p *Plugin) Stop() {
p.tomb.Stop()
glog.Info("Stop plugin execution")
klog.Info("Stop plugin execution")
}
func logPluginStderr(rule cpmtypes.CustomRule, logs string, logLevel glog.Level) {
func logPluginStderr(rule cpmtypes.CustomRule, logs string, logLevel klog.Level) {
if len(logs) != 0 {
glog.V(logLevel).Infof("Start logs from plugin %+v \n %s", rule, logs)
glog.V(logLevel).Infof("End logs from plugin %+v", rule)
klog.V(logLevel).Infof("Start logs from plugin %+v \n %s", rule, logs)
klog.V(logLevel).Infof("End logs from plugin %+v", rule)
}
}
+2 -1
View File
@@ -17,8 +17,9 @@ limitations under the License.
package types
import (
"k8s.io/node-problem-detector/pkg/types"
"time"
"k8s.io/node-problem-detector/pkg/types"
)
type Status int