Skip to content

Commit c15d463

Browse files
committed
Finish the journald support
1 parent f0ed07a commit c15d463

16 files changed

+663
-306
lines changed

cmd/node_problem_detector.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ package main
1818

1919
import (
2020
"flag"
21+
"fmt"
2122
"net/url"
2223
"os"
2324

25+
"github.com/golang/glog"
26+
2427
"k8s.io/node-problem-detector/pkg/kernelmonitor"
2528
"k8s.io/node-problem-detector/pkg/problemdetector"
2629
"k8s.io/node-problem-detector/pkg/version"
27-
28-
"github.com/golang/glog"
29-
"fmt"
3030
)
3131

3232
// TODO: Move flags to options directory.
@@ -86,5 +86,7 @@ func main() {
8686

8787
k := kernelmonitor.NewKernelMonitorOrDie(*kernelMonitorConfigPath)
8888
p := problemdetector.NewProblemDetector(k, *apiServerOverride, nodeName)
89-
p.Run()
89+
if err := p.Run(); err != nil {
90+
glog.Fatalf("Problem detector failed with error: %v", err)
91+
}
9092
}

config/kernel-monitor.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"logPath": "/log/kern.log",
2+
"plugin": "journald",
3+
"logPath": "/log/journal",
34
"lookback": "10m",
45
"startPattern": "Initializing cgroup subsys cpuset",
56
"bufferSize": 10,

node-problem-detector.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ spec:
2626
- name: log
2727
mountPath: /log
2828
readOnly: true
29+
# Make sure node problem detector is in the same timezone
30+
# with the host.
31+
- name: localtime
32+
mountPath: /etc/localtime
33+
readOnly: true
2934
- name: config
3035
mountPath: /config
3136
readOnly: true
@@ -34,6 +39,9 @@ spec:
3439
# Config `log` to your system log directory
3540
hostPath:
3641
path: /var/log/
42+
- name: localtime
43+
hostPath:
44+
path: /etc/localtime
3745
- name: config
3846
configMap:
3947
name: node-problem-detector-config

pkg/kernelmonitor/config.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2016 The Kubernetes Authors All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package kernelmonitor
18+
19+
import (
20+
watchertypes "k8s.io/node-problem-detector/pkg/kernelmonitor/logwatchers/types"
21+
kerntypes "k8s.io/node-problem-detector/pkg/kernelmonitor/types"
22+
"k8s.io/node-problem-detector/pkg/types"
23+
)
24+
25+
// MonitorConfig is the configuration of kernel monitor.
26+
type MonitorConfig struct {
27+
// WatcherConfig is the configuration of kernel log watcher.
28+
watchertypes.WatcherConfig
29+
// BufferSize is the size (in lines) of the log buffer.
30+
BufferSize int `json:"bufferSize"`
31+
// Source is the source name of the kernel monitor
32+
Source string `json:"source"`
33+
// DefaultConditions are the default states of all the conditions kernel monitor should handle.
34+
DefaultConditions []types.Condition `json:"conditions"`
35+
// Rules are the rules kernel monitor will follow to parse the log file.
36+
Rules []kerntypes.Rule `json:"rules"`
37+
// StartPattern is the pattern of the start line
38+
StartPattern string `json:"startPattern, omitempty"`
39+
}
40+
41+
// applyDefaultConfiguration applies default configurations.
42+
func applyDefaultConfiguration(cfg *MonitorConfig) {
43+
if cfg.BufferSize == 0 {
44+
cfg.BufferSize = 10
45+
}
46+
if cfg.WatcherConfig.Lookback == "" {
47+
cfg.WatcherConfig.Lookback = "0"
48+
}
49+
}

pkg/kernelmonitor/kernel_log_watcher.go

Lines changed: 0 additions & 213 deletions
This file was deleted.

pkg/kernelmonitor/kernel_monitor.go

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,15 @@ import (
2222
"regexp"
2323
"time"
2424

25+
"k8s.io/node-problem-detector/pkg/kernelmonitor/logwatchers"
26+
watchertypes "k8s.io/node-problem-detector/pkg/kernelmonitor/logwatchers/types"
2527
kerntypes "k8s.io/node-problem-detector/pkg/kernelmonitor/types"
2628
"k8s.io/node-problem-detector/pkg/kernelmonitor/util"
2729
"k8s.io/node-problem-detector/pkg/types"
2830

2931
"github.com/golang/glog"
3032
)
3133

32-
// MonitorConfig is the configuration of kernel monitor.
33-
type MonitorConfig struct {
34-
// WatcherConfig is the configuration of kernel log watcher.
35-
WatcherConfig
36-
// BufferSize is the size (in lines) of the log buffer.
37-
BufferSize int `json:"bufferSize"`
38-
// Source is the source name of the kernel monitor
39-
Source string `json:"source"`
40-
// DefaultConditions are the default states of all the conditions kernel monitor should handle.
41-
DefaultConditions []types.Condition `json:"conditions"`
42-
// Rules are the rules kernel monitor will follow to parse the log file.
43-
Rules []kerntypes.Rule `json:"rules"`
44-
}
45-
4634
// KernelMonitor monitors the kernel log and reports node problem condition and event according to
4735
// the rules.
4836
type KernelMonitor interface {
@@ -53,7 +41,7 @@ type KernelMonitor interface {
5341
}
5442

5543
type kernelMonitor struct {
56-
watcher KernelLogWatcher
44+
watcher watchertypes.LogWatcher
5745
buffer LogBuffer
5846
config MonitorConfig
5947
conditions []types.Condition
@@ -69,18 +57,23 @@ func NewKernelMonitorOrDie(configPath string) KernelMonitor {
6957
}
7058
f, err := ioutil.ReadFile(configPath)
7159
if err != nil {
72-
panic(err)
60+
glog.Fatalf("Failed to read configuration file %q: %v", configPath, err)
7361
}
7462
err = json.Unmarshal(f, &k.config)
7563
if err != nil {
76-
panic(err)
64+
glog.Fatalf("Failed to unmarshal configuration file %q: %v", configPath, err)
7765
}
66+
// Apply default configurations
67+
applyDefaultConfiguration(&k.config)
7868
err = validateRules(k.config.Rules)
7969
if err != nil {
80-
panic(err)
70+
glog.Fatalf("Failed to validate matching rules %#v: %v", k.config.Rules, err)
8171
}
8272
glog.Infof("Finish parsing log file: %+v", k.config)
83-
k.watcher = NewKernelLogWatcher(k.config.WatcherConfig)
73+
k.watcher, err = logwatchers.GetLogWatcher(k.config.WatcherConfig)
74+
if err != nil {
75+
glog.Fatalf("Failed to create log watcher with watcher config %#v: %v", k.config.WatcherConfig, err)
76+
}
8477
k.buffer = NewLogBuffer(k.config.BufferSize)
8578
// A 1000 size channel should be big enough.
8679
k.output = make(chan *types.Status, 1000)

0 commit comments

Comments
 (0)