mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-23 22:26:27 +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/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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/utils/clock"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -162,7 +162,7 @@ func (c *conditionManager) sync(ctx context.Context) {
|
||||
}
|
||||
if err := c.client.SetConditions(ctx, conditions); err != nil {
|
||||
// The conditions will be updated again in future sync
|
||||
glog.Errorf("failed to update node conditions: %v", err)
|
||||
klog.Errorf("failed to update node conditions: %v", err)
|
||||
c.resyncNeeded = true
|
||||
return
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
_ "net/http/pprof"
|
||||
"strconv"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/utils/clock"
|
||||
@@ -52,9 +52,9 @@ func NewExporterOrDie(ctx context.Context, npdo *options.NodeProblemDetectorOpti
|
||||
|
||||
c := problemclient.NewClientOrDie(npdo)
|
||||
|
||||
glog.Infof("Waiting for kube-apiserver to be ready (timeout %v)...", npdo.APIServerWaitTimeout)
|
||||
klog.Infof("Waiting for kube-apiserver to be ready (timeout %v)...", npdo.APIServerWaitTimeout)
|
||||
if err := waitForAPIServerReadyWithTimeout(ctx, c, npdo); err != nil {
|
||||
glog.Warningf("kube-apiserver did not become ready: timed out on waiting for kube-apiserver to return the node object: %v", err)
|
||||
klog.Warningf("kube-apiserver did not become ready: timed out on waiting for kube-apiserver to return the node object: %v", err)
|
||||
}
|
||||
|
||||
ke := k8sExporter{
|
||||
@@ -99,7 +99,7 @@ func (ke *k8sExporter) startHTTPReporting(npdo *options.NodeProblemDetectorOptio
|
||||
go func() {
|
||||
err := http.ListenAndServe(addr, mux)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to start server: %v", err)
|
||||
klog.Fatalf("Failed to start server: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -109,7 +109,7 @@ func waitForAPIServerReadyWithTimeout(ctx context.Context, c problemclient.Clien
|
||||
// If NPD can get the node object from kube-apiserver, the server is
|
||||
// ready and the RBAC permission is set correctly.
|
||||
if _, err := c.GetNode(ctx); err != nil {
|
||||
glog.Errorf("Can't get node object: %v", err)
|
||||
klog.Errorf("Can't get node object: %v", err)
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/golang/glog"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
@@ -32,6 +31,7 @@ import (
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
"k8s.io/client-go/tools/record"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/utils/clock"
|
||||
|
||||
"k8s.io/node-problem-detector/cmd/options"
|
||||
@@ -136,7 +136,7 @@ func generatePatch(conditions []v1.NodeCondition) ([]byte, error) {
|
||||
// getEventRecorder generates a recorder for specific node name and source.
|
||||
func getEventRecorder(c typedcorev1.CoreV1Interface, namespace, nodeName, source string) record.EventRecorder {
|
||||
eventBroadcaster := record.NewBroadcaster()
|
||||
eventBroadcaster.StartLogging(glog.V(4).Infof)
|
||||
eventBroadcaster.StartLogging(klog.V(4).Infof)
|
||||
recorder := eventBroadcaster.NewRecorder(runtime.NewScheme(), v1.EventSource{Component: source, Host: nodeName})
|
||||
eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: c.Events(namespace)})
|
||||
return recorder
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
"strconv"
|
||||
|
||||
"contrib.go.opencensus.io/exporter/prometheus"
|
||||
"github.com/golang/glog"
|
||||
"go.opencensus.io/stats/view"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/node-problem-detector/cmd/options"
|
||||
"k8s.io/node-problem-detector/pkg/types"
|
||||
@@ -40,13 +40,13 @@ func NewExporterOrDie(npdo *options.NodeProblemDetectorOptions) types.Exporter {
|
||||
addr := net.JoinHostPort(npdo.PrometheusServerAddress, strconv.Itoa(npdo.PrometheusServerPort))
|
||||
pe, err := prometheus.NewExporter(prometheus.Options{})
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to create Prometheus exporter: %v", err)
|
||||
klog.Fatalf("Failed to create Prometheus exporter: %v", err)
|
||||
}
|
||||
go func() {
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/metrics", pe)
|
||||
if err := http.ListenAndServe(addr, mux); err != nil {
|
||||
glog.Fatalf("Failed to start Prometheus scrape endpoint: %v", err)
|
||||
klog.Fatalf("Failed to start Prometheus scrape endpoint: %v", err)
|
||||
}
|
||||
}()
|
||||
view.RegisterExporter(pe)
|
||||
|
||||
@@ -18,7 +18,7 @@ package gce
|
||||
|
||||
import (
|
||||
"cloud.google.com/go/compute/metadata"
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
type Metadata struct {
|
||||
@@ -37,7 +37,7 @@ func (md *Metadata) HasMissingField() bool {
|
||||
|
||||
func (md *Metadata) PopulateFromGCE() error {
|
||||
var err error
|
||||
glog.Info("Fetching GCE metadata from metadata server")
|
||||
klog.Info("Fetching GCE metadata from metadata server")
|
||||
if md.ProjectID == "" {
|
||||
md.ProjectID, err = metadata.ProjectID()
|
||||
if err != nil {
|
||||
|
||||
@@ -25,10 +25,10 @@ import (
|
||||
|
||||
"contrib.go.opencensus.io/exporter/stackdriver"
|
||||
monitoredres "contrib.go.opencensus.io/exporter/stackdriver/monitoredresource"
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/pflag"
|
||||
"go.opencensus.io/stats/view"
|
||||
"google.golang.org/api/option"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"github.com/avast/retry-go"
|
||||
"k8s.io/node-problem-detector/pkg/exporters"
|
||||
@@ -137,12 +137,12 @@ func (se *stackdriverExporter) setupOpenCensusViewExporterOrDie() {
|
||||
DefaultMonitoringLabels: &globalLabels,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to create Stackdriver OpenCensus view exporter: %v", err)
|
||||
klog.Fatalf("Failed to create Stackdriver OpenCensus view exporter: %v", err)
|
||||
}
|
||||
|
||||
exportPeriod, err := time.ParseDuration(se.config.ExportPeriod)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to parse ExportPeriod %q: %v", se.config.ExportPeriod, err)
|
||||
klog.Fatalf("Failed to parse ExportPeriod %q: %v", se.config.ExportPeriod, err)
|
||||
}
|
||||
|
||||
view.SetReportingPeriod(exportPeriod)
|
||||
@@ -151,33 +151,33 @@ func (se *stackdriverExporter) setupOpenCensusViewExporterOrDie() {
|
||||
|
||||
func (se *stackdriverExporter) populateMetadataOrDie() {
|
||||
if !se.config.GCEMetadata.HasMissingField() {
|
||||
glog.Infof("Using GCE metadata specified in the config file: %+v", se.config.GCEMetadata)
|
||||
klog.Infof("Using GCE metadata specified in the config file: %+v", se.config.GCEMetadata)
|
||||
return
|
||||
}
|
||||
|
||||
metadataFetchTimeout, err := time.ParseDuration(se.config.MetadataFetchTimeout)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to parse MetadataFetchTimeout %q: %v", se.config.MetadataFetchTimeout, err)
|
||||
klog.Fatalf("Failed to parse MetadataFetchTimeout %q: %v", se.config.MetadataFetchTimeout, err)
|
||||
}
|
||||
|
||||
metadataFetchInterval, err := time.ParseDuration(se.config.MetadataFetchInterval)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to parse MetadataFetchInterval %q: %v", se.config.MetadataFetchInterval, err)
|
||||
klog.Fatalf("Failed to parse MetadataFetchInterval %q: %v", se.config.MetadataFetchInterval, err)
|
||||
}
|
||||
|
||||
glog.Infof("Populating GCE metadata by querying GCE metadata server.")
|
||||
klog.Infof("Populating GCE metadata by querying GCE metadata server.")
|
||||
err = retry.Do(se.config.GCEMetadata.PopulateFromGCE,
|
||||
retry.Delay(metadataFetchInterval),
|
||||
retry.Attempts(uint(metadataFetchTimeout/metadataFetchInterval)),
|
||||
retry.DelayType(retry.FixedDelay))
|
||||
if err == nil {
|
||||
glog.Infof("Using GCE metadata: %+v", se.config.GCEMetadata)
|
||||
klog.Infof("Using GCE metadata: %+v", se.config.GCEMetadata)
|
||||
return
|
||||
}
|
||||
if se.config.PanicOnMetadataFetchFailure {
|
||||
glog.Fatalf("Failed to populate GCE metadata: %v", err)
|
||||
klog.Fatalf("Failed to populate GCE metadata: %v", err)
|
||||
} else {
|
||||
glog.Errorf("Failed to populate GCE metadata: %v", err)
|
||||
klog.Errorf("Failed to populate GCE metadata: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ func (clo *commandLineOptions) SetFlags(fs *pflag.FlagSet) {
|
||||
func NewExporterOrDie(clo types.CommandLineOptions) types.Exporter {
|
||||
options, ok := clo.(*commandLineOptions)
|
||||
if !ok {
|
||||
glog.Fatalf("Wrong type for the command line options of Stackdriver Exporter: %s.", reflect.TypeOf(clo))
|
||||
klog.Fatalf("Wrong type for the command line options of Stackdriver Exporter: %s.", reflect.TypeOf(clo))
|
||||
}
|
||||
if options.configPath == "" {
|
||||
return nil
|
||||
@@ -211,15 +211,15 @@ func NewExporterOrDie(clo types.CommandLineOptions) types.Exporter {
|
||||
// Apply configurations.
|
||||
f, err := os.ReadFile(options.configPath)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to read configuration file %q: %v", options.configPath, err)
|
||||
klog.Fatalf("Failed to read configuration file %q: %v", options.configPath, err)
|
||||
}
|
||||
err = json.Unmarshal(f, &se.config)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to unmarshal configuration file %q: %v", options.configPath, err)
|
||||
klog.Fatalf("Failed to unmarshal configuration file %q: %v", options.configPath, err)
|
||||
}
|
||||
se.config.ApplyConfiguration()
|
||||
|
||||
glog.Infof("Starting Stackdriver exporter %s", options.configPath)
|
||||
klog.Infof("Starting Stackdriver exporter %s", options.configPath)
|
||||
|
||||
se.populateMetadataOrDie()
|
||||
se.setupOpenCensusViewExporterOrDie()
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/node-problem-detector/cmd/healthchecker/options"
|
||||
"k8s.io/node-problem-detector/pkg/healthchecker/types"
|
||||
)
|
||||
@@ -83,12 +83,12 @@ func (hc *healthChecker) CheckHealth() (bool, error) {
|
||||
// repair if the service has been up for the cool down period.
|
||||
uptime, err := hc.uptimeFunc()
|
||||
if err != nil {
|
||||
glog.Infof("error in getting uptime for %v: %v\n", hc.component, err)
|
||||
klog.Infof("error in getting uptime for %v: %v\n", hc.component, err)
|
||||
return false, nil
|
||||
}
|
||||
glog.Infof("%v is unhealthy, component uptime: %v\n", hc.component, uptime)
|
||||
klog.Infof("%v is unhealthy, component uptime: %v\n", hc.component, uptime)
|
||||
if uptime > hc.coolDownTime {
|
||||
glog.Infof("%v cooldown period of %v exceeded, repairing", hc.component, hc.coolDownTime)
|
||||
klog.Infof("%v cooldown period of %v exceeded, repairing", hc.component, hc.coolDownTime)
|
||||
hc.repairFunc()
|
||||
}
|
||||
}
|
||||
@@ -102,10 +102,10 @@ func logPatternHealthCheck(service string, loopBackTime time.Duration, logPatter
|
||||
return true, nil
|
||||
}
|
||||
uptimeFunc := getUptimeFunc(service)
|
||||
glog.Infof("Getting uptime for service: %v\n", service)
|
||||
klog.Infof("Getting uptime for service: %v\n", service)
|
||||
uptime, err := uptimeFunc()
|
||||
if err != nil {
|
||||
glog.Warningf("Failed to get the uptime: %+v", err)
|
||||
klog.Warningf("Failed to get the uptime: %+v", err)
|
||||
return true, err
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ func getHealthCheckFunc(hco *options.HealthCheckerOptions) func() (bool, error)
|
||||
return true, nil
|
||||
}
|
||||
default:
|
||||
glog.Warningf("Unsupported component: %v", hco.Component)
|
||||
klog.Warningf("Unsupported component: %v", hco.Component)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -177,7 +177,7 @@ func execCommand(timeout time.Duration, command string, args ...string) (string,
|
||||
cmd := exec.CommandContext(ctx, command, args...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
glog.Infof("command %v failed: %v, %v\n", cmd, err, out)
|
||||
klog.Infof("command %v failed: %v, %v\n", cmd, err, out)
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/node-problem-detector/cmd/healthchecker/options"
|
||||
"k8s.io/node-problem-detector/pkg/healthchecker/types"
|
||||
@@ -90,7 +90,7 @@ func checkForPattern(service, logStartTime, logPattern string, logCountThreshold
|
||||
return true, err
|
||||
}
|
||||
if occurrences >= logCountThreshold {
|
||||
glog.Infof("%s failed log pattern check, %s occurrences: %v", service, logPattern, occurrences)
|
||||
klog.Infof("%s failed log pattern check, %s occurrences: %v", service, logPattern, occurrences)
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/node-problem-detector/cmd/healthchecker/options"
|
||||
"k8s.io/node-problem-detector/pkg/healthchecker/types"
|
||||
@@ -80,7 +80,7 @@ func powershell(args ...string) (string, error) {
|
||||
func extractCommandOutput(cmd *exec.Cmd) (string, error) {
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
glog.Infof("command %v failed: %v, %v\n", cmd, err, out)
|
||||
klog.Infof("command %v failed: %v, %v\n", cmd, err, out)
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimSuffix(string(out), "\r\n"), nil
|
||||
@@ -101,7 +101,7 @@ func checkForPattern(service, logStartTime, logPattern string, logCountThreshold
|
||||
return true, err
|
||||
}
|
||||
if occurrences >= logCountThreshold {
|
||||
glog.Infof("%s failed log pattern check, %s occurrences: %v", service, logPattern, occurrences)
|
||||
klog.Infof("%s failed log pattern check, %s occurrences: %v", service, logPattern, occurrences)
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
|
||||
@@ -19,7 +19,7 @@ package problemdaemon
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/node-problem-detector/pkg/types"
|
||||
)
|
||||
@@ -58,7 +58,7 @@ func NewProblemDaemons(monitorConfigPaths types.ProblemDaemonConfigPathMap) []ty
|
||||
for _, config := range *configs {
|
||||
if _, ok := problemDaemonMap[config]; ok {
|
||||
// Skip the config if it's duplicated.
|
||||
glog.Warningf("Duplicated problem daemon configuration %q", config)
|
||||
klog.Warningf("Duplicated problem daemon configuration %q", config)
|
||||
continue
|
||||
}
|
||||
problemDaemonMap[config] = handlers[problemDaemonType].CreateProblemDaemonOrDie(config)
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/node-problem-detector/pkg/types"
|
||||
)
|
||||
@@ -53,7 +53,7 @@ func (p *problemDetector) Run(ctx context.Context) error {
|
||||
ch, err := m.Start()
|
||||
if err != nil {
|
||||
// Do not return error and keep on trying the following config files.
|
||||
glog.Errorf("Failed to start problem daemon %v: %v", m, err)
|
||||
klog.Errorf("Failed to start problem daemon %v: %v", m, err)
|
||||
failureCount++
|
||||
continue
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func (p *problemDetector) Run(ctx context.Context) error {
|
||||
}()
|
||||
|
||||
ch := groupChannel(chans)
|
||||
glog.Info("Problem detector started")
|
||||
klog.Info("Problem detector started")
|
||||
|
||||
for {
|
||||
select {
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/node-problem-detector/pkg/util/metrics"
|
||||
)
|
||||
@@ -56,7 +56,7 @@ func NewProblemMetricsManagerOrDie() *ProblemMetricsManager {
|
||||
metrics.Sum,
|
||||
[]string{"reason"})
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to create problem_counter metric: %v", err)
|
||||
klog.Fatalf("Failed to create problem_counter metric: %v", err)
|
||||
}
|
||||
|
||||
pmm.problemGauge, err = metrics.NewInt64Metric(
|
||||
@@ -67,7 +67,7 @@ func NewProblemMetricsManagerOrDie() *ProblemMetricsManager {
|
||||
metrics.LastValue,
|
||||
[]string{"type", "reason"})
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to create problem_gauge metric: %v", err)
|
||||
klog.Fatalf("Failed to create problem_gauge metric: %v", err)
|
||||
}
|
||||
|
||||
pmm.problemTypeToReason = make(map[string]string)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ limitations under the License.
|
||||
package systemstatsmonitor
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"github.com/shirou/gopsutil/v3/cpu"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
|
||||
"k8s.io/node-problem-detector/pkg/util/metrics"
|
||||
@@ -67,7 +67,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig, procPath string) *
|
||||
metrics.LastValue,
|
||||
[]string{})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.CPURunnableTaskCountID, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.CPURunnableTaskCountID, err)
|
||||
}
|
||||
|
||||
cc.mUsageTime, err = metrics.NewFloat64Metric(
|
||||
@@ -78,7 +78,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig, procPath string) *
|
||||
metrics.Sum,
|
||||
[]string{stateLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.CPUUsageTimeID, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.CPUUsageTimeID, err)
|
||||
}
|
||||
|
||||
cc.mCpuLoad1m, err = metrics.NewFloat64Metric(
|
||||
@@ -89,7 +89,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig, procPath string) *
|
||||
metrics.LastValue,
|
||||
[]string{})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.CPULoad1m, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.CPULoad1m, err)
|
||||
}
|
||||
|
||||
cc.mCpuLoad5m, err = metrics.NewFloat64Metric(
|
||||
@@ -100,7 +100,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig, procPath string) *
|
||||
metrics.LastValue,
|
||||
[]string{})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.CPULoad5m, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.CPULoad5m, err)
|
||||
}
|
||||
|
||||
cc.mCpuLoad15m, err = metrics.NewFloat64Metric(
|
||||
@@ -111,7 +111,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig, procPath string) *
|
||||
metrics.LastValue,
|
||||
[]string{})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.CPULoad15m, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.CPULoad15m, err)
|
||||
}
|
||||
|
||||
cc.mSystemProcessesTotal, err = metrics.NewInt64Metric(
|
||||
@@ -122,7 +122,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig, procPath string) *
|
||||
metrics.Sum,
|
||||
[]string{})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemProcessesTotal, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.SystemProcessesTotal, err)
|
||||
}
|
||||
|
||||
cc.mSystemProcsRunning, err = metrics.NewInt64Metric(
|
||||
@@ -133,7 +133,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig, procPath string) *
|
||||
metrics.LastValue,
|
||||
[]string{})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemProcsRunning, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.SystemProcsRunning, err)
|
||||
}
|
||||
|
||||
cc.mSystemProcsBlocked, err = metrics.NewInt64Metric(
|
||||
@@ -144,7 +144,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig, procPath string) *
|
||||
metrics.LastValue,
|
||||
[]string{})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemProcsBlocked, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.SystemProcsBlocked, err)
|
||||
}
|
||||
|
||||
cc.mSystemInterruptsTotal, err = metrics.NewInt64Metric(
|
||||
@@ -155,7 +155,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig, procPath string) *
|
||||
metrics.Sum,
|
||||
[]string{})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemInterruptsTotal, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.SystemInterruptsTotal, err)
|
||||
}
|
||||
|
||||
cc.mSystemCPUStat, err = metrics.NewFloat64Metric(
|
||||
@@ -166,7 +166,7 @@ func NewCPUCollectorOrDie(cpuConfig *ssmtypes.CPUStatsConfig, procPath string) *
|
||||
metrics.Sum,
|
||||
[]string{cpuLabel, stageLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.SystemCPUStat, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.SystemCPUStat, err)
|
||||
}
|
||||
|
||||
cc.lastUsageTime = make(map[string]float64)
|
||||
@@ -182,7 +182,7 @@ func (cc *cpuCollector) recordUsage() {
|
||||
// Set percpu=false to get aggregated usage from all CPUs.
|
||||
timersStats, err := cpu.Times(false)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to retrieve CPU timers stat: %v", err)
|
||||
klog.Errorf("Failed to retrieve CPU timers stat: %v", err)
|
||||
return
|
||||
}
|
||||
timersStat := timersStats[0]
|
||||
|
||||
@@ -21,9 +21,9 @@ package systemstatsmonitor
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/procfs"
|
||||
"github.com/shirou/gopsutil/v3/load"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func (cc *cpuCollector) recordLoad() {
|
||||
@@ -35,7 +35,7 @@ func (cc *cpuCollector) recordLoad() {
|
||||
|
||||
loadAvg, err := load.Avg()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to retrieve average CPU load: %v", err)
|
||||
klog.Errorf("Failed to retrieve average CPU load: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ func (cc *cpuCollector) recordSystemStats() {
|
||||
fs, err := procfs.NewFS(cc.procPath)
|
||||
stats, err := fs.Stat()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to retrieve cpu/process stats: %v", err)
|
||||
klog.Errorf("Failed to retrieve cpu/process stats: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/shirou/gopsutil/v3/disk"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
|
||||
"k8s.io/node-problem-detector/pkg/util/metrics"
|
||||
@@ -69,7 +69,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
|
||||
metrics.Sum,
|
||||
[]string{deviceNameLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for disk/io_time: %v", err)
|
||||
klog.Fatalf("Error initializing metric for disk/io_time: %v", err)
|
||||
}
|
||||
|
||||
// Use metrics.Sum aggregation method to ensure the metric is a counter/cumulative metric.
|
||||
@@ -81,7 +81,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
|
||||
metrics.Sum,
|
||||
[]string{deviceNameLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for disk/weighted_io: %v", err)
|
||||
klog.Fatalf("Error initializing metric for disk/weighted_io: %v", err)
|
||||
}
|
||||
|
||||
dc.mAvgQueueLen, err = metrics.NewFloat64Metric(
|
||||
@@ -92,7 +92,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
|
||||
metrics.LastValue,
|
||||
[]string{deviceNameLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for disk/avg_queue_len: %v", err)
|
||||
klog.Fatalf("Error initializing metric for disk/avg_queue_len: %v", err)
|
||||
}
|
||||
|
||||
dc.mOpsCount, err = metrics.NewInt64Metric(
|
||||
@@ -103,7 +103,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
|
||||
metrics.Sum,
|
||||
[]string{deviceNameLabel, directionLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.DiskOpsCountID, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.DiskOpsCountID, err)
|
||||
}
|
||||
|
||||
dc.mMergedOpsCount, err = metrics.NewInt64Metric(
|
||||
@@ -114,7 +114,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
|
||||
metrics.Sum,
|
||||
[]string{deviceNameLabel, directionLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.DiskMergedOpsCountID, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.DiskMergedOpsCountID, err)
|
||||
}
|
||||
|
||||
dc.mOpsBytes, err = metrics.NewInt64Metric(
|
||||
@@ -125,7 +125,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
|
||||
metrics.Sum,
|
||||
[]string{deviceNameLabel, directionLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.DiskOpsBytesID, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.DiskOpsBytesID, err)
|
||||
}
|
||||
|
||||
dc.mOpsTime, err = metrics.NewInt64Metric(
|
||||
@@ -136,7 +136,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
|
||||
metrics.Sum,
|
||||
[]string{deviceNameLabel, directionLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.DiskOpsTimeID, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.DiskOpsTimeID, err)
|
||||
}
|
||||
|
||||
dc.mBytesUsed, err = metrics.NewInt64Metric(
|
||||
@@ -147,7 +147,7 @@ func NewDiskCollectorOrDie(diskConfig *ssmtypes.DiskStatsConfig) *diskCollector
|
||||
metrics.LastValue,
|
||||
[]string{deviceNameLabel, fsTypeLabel, mountOptionLabel, stateLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.DiskBytesUsedID, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.DiskBytesUsedID, err)
|
||||
}
|
||||
|
||||
dc.lastIOTime = make(map[string]uint64)
|
||||
@@ -247,7 +247,7 @@ func (dc *diskCollector) collect() {
|
||||
|
||||
partitions, err := disk.Partitions(false)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to list disk partitions: %v", err)
|
||||
klog.Errorf("Failed to list disk partitions: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ func (dc *diskCollector) collect() {
|
||||
// Fetch metrics from /proc, /sys.
|
||||
ioCountersStats, err := disk.IOCounters(devices...)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to retrieve disk IO counters: %v", err)
|
||||
klog.Errorf("Failed to retrieve disk IO counters: %v", err)
|
||||
return
|
||||
}
|
||||
sampleTime := time.Now()
|
||||
@@ -283,7 +283,7 @@ func (dc *diskCollector) collect() {
|
||||
seen[partition.Device] = true
|
||||
usageStat, err := disk.Usage(partition.Mountpoint)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to retrieve disk usage for %q: %v", partition.Mountpoint, err)
|
||||
klog.Errorf("Failed to retrieve disk usage for %q: %v", partition.Mountpoint, err)
|
||||
continue
|
||||
}
|
||||
deviceName := strings.TrimPrefix(partition.Device, "/dev/")
|
||||
@@ -306,7 +306,7 @@ func listRootBlockDevices(timeout time.Duration) []string {
|
||||
cmd := exec.CommandContext(ctx, "lsblk", "-d", "-n", "-o", "NAME")
|
||||
stdout, err := cmd.Output()
|
||||
if err != nil {
|
||||
glog.Errorf("Error calling lsblk")
|
||||
klog.Errorf("Error calling lsblk")
|
||||
}
|
||||
return strings.Split(strings.TrimSpace(string(stdout)), "\n")
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ limitations under the License.
|
||||
package systemstatsmonitor
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"github.com/shirou/gopsutil/v3/host"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
|
||||
"k8s.io/node-problem-detector/pkg/util"
|
||||
@@ -35,13 +35,13 @@ func NewHostCollectorOrDie(hostConfig *ssmtypes.HostStatsConfig) *hostCollector
|
||||
|
||||
kernelVersion, err := host.KernelVersion()
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to retrieve kernel version: %v", err)
|
||||
klog.Fatalf("Failed to retrieve kernel version: %v", err)
|
||||
}
|
||||
hc.tags["kernel_version"] = kernelVersion
|
||||
|
||||
osVersion, err := util.GetOSVersion()
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to retrieve OS version: %v", err)
|
||||
klog.Fatalf("Failed to retrieve OS version: %v", err)
|
||||
}
|
||||
hc.tags["os_version"] = osVersion
|
||||
|
||||
@@ -55,7 +55,7 @@ func NewHostCollectorOrDie(hostConfig *ssmtypes.HostStatsConfig) *hostCollector
|
||||
metrics.LastValue,
|
||||
[]string{"kernel_version", "os_version"})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for host/uptime: %v", err)
|
||||
klog.Fatalf("Error initializing metric for host/uptime: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func (hc *hostCollector) collect() {
|
||||
|
||||
uptime, err := host.Uptime()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to retrieve uptime of the host: %v", err)
|
||||
klog.Errorf("Failed to retrieve uptime of the host: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ limitations under the License.
|
||||
package systemstatsmonitor
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
|
||||
"k8s.io/node-problem-detector/pkg/util/metrics"
|
||||
@@ -46,7 +46,7 @@ func NewMemoryCollectorOrDie(memoryConfig *ssmtypes.MemoryStatsConfig) *memoryCo
|
||||
metrics.LastValue,
|
||||
[]string{stateLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.MemoryBytesUsedID, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.MemoryBytesUsedID, err)
|
||||
}
|
||||
|
||||
mc.mAnonymousUsed, err = metrics.NewInt64Metric(
|
||||
@@ -57,7 +57,7 @@ func NewMemoryCollectorOrDie(memoryConfig *ssmtypes.MemoryStatsConfig) *memoryCo
|
||||
metrics.LastValue,
|
||||
[]string{stateLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.MemoryAnonymousUsedID, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.MemoryAnonymousUsedID, err)
|
||||
}
|
||||
|
||||
mc.mPageCacheUsed, err = metrics.NewInt64Metric(
|
||||
@@ -68,7 +68,7 @@ func NewMemoryCollectorOrDie(memoryConfig *ssmtypes.MemoryStatsConfig) *memoryCo
|
||||
metrics.LastValue,
|
||||
[]string{stateLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.MemoryPageCacheUsedID, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.MemoryPageCacheUsedID, err)
|
||||
}
|
||||
|
||||
mc.mUnevictableUsed, err = metrics.NewInt64Metric(
|
||||
@@ -79,7 +79,7 @@ func NewMemoryCollectorOrDie(memoryConfig *ssmtypes.MemoryStatsConfig) *memoryCo
|
||||
metrics.LastValue,
|
||||
[]string{})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.MemoryUnevictableUsedID, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.MemoryUnevictableUsedID, err)
|
||||
}
|
||||
|
||||
mc.mDirtyUsed, err = metrics.NewInt64Metric(
|
||||
@@ -90,7 +90,7 @@ func NewMemoryCollectorOrDie(memoryConfig *ssmtypes.MemoryStatsConfig) *memoryCo
|
||||
metrics.LastValue,
|
||||
[]string{stateLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for %q: %v", metrics.MemoryDirtyUsedID, err)
|
||||
klog.Fatalf("Error initializing metric for %q: %v", metrics.MemoryDirtyUsedID, err)
|
||||
}
|
||||
|
||||
return &mc
|
||||
|
||||
@@ -19,8 +19,8 @@ limitations under the License.
|
||||
package systemstatsmonitor
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/procfs"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func (mc *memoryCollector) collect() {
|
||||
@@ -30,12 +30,12 @@ func (mc *memoryCollector) collect() {
|
||||
|
||||
proc, err := procfs.NewDefaultFS()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to find /proc mount point: %v", err)
|
||||
klog.Errorf("Failed to find /proc mount point: %v", err)
|
||||
return
|
||||
}
|
||||
meminfo, err := proc.Meminfo()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to retrieve memory stats: %v", err)
|
||||
klog.Errorf("Failed to retrieve memory stats: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ limitations under the License.
|
||||
package systemstatsmonitor
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"github.com/shirou/gopsutil/v3/mem"
|
||||
)
|
||||
@@ -29,7 +29,7 @@ func (mc *memoryCollector) collect() {
|
||||
|
||||
meminfo, err := mem.VirtualMemory()
|
||||
if err != nil {
|
||||
glog.Errorf("cannot get windows memory metrics from GlobalMemoryStatusEx: %v", err)
|
||||
klog.Errorf("cannot get windows memory metrics from GlobalMemoryStatusEx: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
|
||||
"k8s.io/node-problem-detector/pkg/util/metrics"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/procfs"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
type newInt64MetricFn func(metricID metrics.MetricID, viewName string, description string, unit string, aggregation metrics.Aggregation, tagNames []string) (metrics.Int64MetricInterface, error)
|
||||
@@ -208,12 +208,12 @@ func (nc *netCollector) mustRegisterMetric(metricID metrics.MetricID, descriptio
|
||||
aggregation metrics.Aggregation, exporter func(stat procfs.NetDevLine) int64) {
|
||||
metricConfig, ok := nc.config.MetricsConfigs[string(metricID)]
|
||||
if !ok {
|
||||
glog.Fatalf("Metric config `%q` not found", metricID)
|
||||
klog.Fatalf("Metric config `%q` not found", metricID)
|
||||
}
|
||||
err := nc.recorder.Register(metricID, metricConfig.DisplayName, description, unit,
|
||||
aggregation, []string{interfaceNameLabel}, exporter)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to initialize metric %q: %v", metricID, err)
|
||||
klog.Fatalf("Failed to initialize metric %q: %v", metricID, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,14 +221,14 @@ func (nc *netCollector) recordNetDev() {
|
||||
fs, err := procfs.NewFS(nc.procPath)
|
||||
stats, err := fs.NetDev()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to retrieve net dev stat: %v", err)
|
||||
klog.Errorf("Failed to retrieve net dev stat: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
excludeInterfaceRegexp := nc.config.ExcludeInterfaceRegexp.R
|
||||
for iface, ifaceStats := range stats {
|
||||
if excludeInterfaceRegexp != nil && excludeInterfaceRegexp.MatchString(iface) {
|
||||
glog.V(6).Infof("Network interface %s matched exclude regexp %q, skipping recording", iface, excludeInterfaceRegexp)
|
||||
klog.V(6).Infof("Network interface %s matched exclude regexp %q, skipping recording", iface, excludeInterfaceRegexp)
|
||||
continue
|
||||
}
|
||||
tags := map[string]string{}
|
||||
@@ -282,7 +282,7 @@ func (r ifaceStatRecorder) RecordWithSameTags(stat procfs.NetDevLine, tags map[s
|
||||
for metricID, collector := range r.collectors {
|
||||
measurement := collector.exporter(stat)
|
||||
collector.metric.Record(tags, measurement)
|
||||
glog.V(6).Infof("Metric %q record measurement %d with tags %v", metricID, measurement, tags)
|
||||
klog.V(6).Infof("Metric %q record measurement %d with tags %v", metricID, measurement, tags)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
|
||||
"k8s.io/node-problem-detector/pkg/util/metrics"
|
||||
"k8s.io/node-problem-detector/pkg/util/metrics/system"
|
||||
@@ -48,7 +48,7 @@ func NewOsFeatureCollectorOrDie(osFeatureConfig *ssmtypes.OSFeatureStatsConfig,
|
||||
metrics.LastValue,
|
||||
[]string{featureLabel, valueLabel})
|
||||
if err != nil {
|
||||
glog.Fatalf("Error initializing metric for system/os_feature: %v", err)
|
||||
klog.Fatalf("Error initializing metric for system/os_feature: %v", err)
|
||||
}
|
||||
}
|
||||
return &oc
|
||||
@@ -104,7 +104,7 @@ func (ofc *osFeatureCollector) recordFeaturesFromModules(modules []system.Module
|
||||
var knownModules []system.Module
|
||||
f, err := os.ReadFile(ofc.config.KnownModulesConfigPath)
|
||||
if err != nil {
|
||||
glog.Warningf("Failed to read configuration file %s: %v",
|
||||
klog.Warningf("Failed to read configuration file %s: %v",
|
||||
ofc.config.KnownModulesConfigPath, err)
|
||||
}
|
||||
// When the knownModulesConfigPath is not set
|
||||
@@ -112,7 +112,7 @@ func (ofc *osFeatureCollector) recordFeaturesFromModules(modules []system.Module
|
||||
if f != nil {
|
||||
err = json.Unmarshal(f, &knownModules)
|
||||
if err != nil {
|
||||
glog.Warningf("Failed to retrieve known modules %v", err)
|
||||
klog.Warningf("Failed to retrieve known modules %v", err)
|
||||
}
|
||||
} else {
|
||||
knownModules = []system.Module{}
|
||||
@@ -152,12 +152,12 @@ func (ofc *osFeatureCollector) collect() {
|
||||
}
|
||||
cmdlineArgs, err := system.CmdlineArgs(filepath.Join(ofc.procPath, "/cmdline"))
|
||||
if err != nil {
|
||||
glog.Fatalf("Error retrieving cmdline args: %v", err)
|
||||
klog.Fatalf("Error retrieving cmdline args: %v", err)
|
||||
}
|
||||
ofc.recordFeaturesFromCmdline(cmdlineArgs)
|
||||
modules, err := system.Modules(filepath.Join(ofc.procPath, "/modules"))
|
||||
if err != nil {
|
||||
glog.Fatalf("Error retrieving kernel modules: %v", err)
|
||||
klog.Fatalf("Error retrieving kernel modules: %v", err)
|
||||
}
|
||||
ofc.recordFeaturesFromModules(modules)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"k8s.io/node-problem-detector/pkg/problemdaemon"
|
||||
ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types"
|
||||
@@ -60,21 +60,21 @@ func NewSystemStatsMonitorOrDie(configPath string) types.Monitor {
|
||||
// Apply configurations.
|
||||
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, &ssm.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)
|
||||
}
|
||||
|
||||
err = ssm.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)
|
||||
}
|
||||
|
||||
err = ssm.config.Validate()
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to validate %s configuration %+v: %v", ssm.configPath, ssm.config, err)
|
||||
klog.Fatalf("Failed to validate %s configuration %+v: %v", ssm.configPath, ssm.config, err)
|
||||
}
|
||||
|
||||
if len(ssm.config.CPUConfig.MetricsConfigs) > 0 {
|
||||
@@ -105,7 +105,7 @@ func NewSystemStatsMonitorOrDie(configPath string) types.Monitor {
|
||||
}
|
||||
|
||||
func (ssm *systemStatsMonitor) Start() (<-chan *types.Status, error) {
|
||||
glog.Infof("Start system stats monitor %s", ssm.configPath)
|
||||
klog.Infof("Start system stats monitor %s", ssm.configPath)
|
||||
go ssm.monitorLoop()
|
||||
return nil, nil
|
||||
}
|
||||
@@ -118,7 +118,7 @@ func (ssm *systemStatsMonitor) monitorLoop() {
|
||||
|
||||
select {
|
||||
case <-ssm.tomb.Stopping():
|
||||
glog.Infof("System stats monitor stopped: %s", ssm.configPath)
|
||||
klog.Infof("System stats monitor stopped: %s", ssm.configPath)
|
||||
return
|
||||
default:
|
||||
ssm.cpuCollector.collect()
|
||||
@@ -139,13 +139,13 @@ func (ssm *systemStatsMonitor) monitorLoop() {
|
||||
ssm.osFeatureCollector.collect()
|
||||
ssm.netCollector.collect()
|
||||
case <-ssm.tomb.Stopping():
|
||||
glog.Infof("System stats monitor stopped: %s", ssm.configPath)
|
||||
klog.Infof("System stats monitor stopped: %s", ssm.configPath)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ssm *systemStatsMonitor) Stop() {
|
||||
glog.Infof("Stop system stats monitor %s", ssm.configPath)
|
||||
klog.Infof("Stop system stats monitor %s", ssm.configPath)
|
||||
ssm.tomb.Stop()
|
||||
}
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ package util
|
||||
import (
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"k8s.io/node-problem-detector/pkg/types"
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/node-problem-detector/pkg/types"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user