Add existing monitors into the problem daemon registration hook.

This commit is contained in:
Xuewei Zhang
2019-06-13 00:51:17 -07:00
parent 63f0e35e56
commit a07176073a
9 changed files with 435 additions and 32 deletions
@@ -25,11 +25,22 @@ import (
"k8s.io/node-problem-detector/pkg/custompluginmonitor/plugin"
cpmtypes "k8s.io/node-problem-detector/pkg/custompluginmonitor/types"
"k8s.io/node-problem-detector/pkg/problemdaemon"
"k8s.io/node-problem-detector/pkg/types"
"k8s.io/node-problem-detector/pkg/util"
"k8s.io/node-problem-detector/pkg/util/tomb"
)
const CustomPluginMonitorName = "custom-plugin-monitor"
func init() {
problemdaemon.Register(
CustomPluginMonitorName,
types.ProblemDaemonHandler{
CreateProblemDaemonOrDie: NewCustomPluginMonitorOrDie,
CmdOptionDescription: "Set to config file paths."})
}
type customPluginMonitor struct {
config cpmtypes.CustomPluginConfig
conditions []types.Condition
@@ -0,0 +1,31 @@
/*
Copyright 2019 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package custompluginmonitor
import (
"testing"
"github.com/stretchr/testify/assert"
"k8s.io/node-problem-detector/pkg/problemdaemon"
)
func TestRegistration(t *testing.T) {
assert.NotPanics(t,
func() { problemdaemon.GetProblemDaemonHandlerOrDie("custom-plugin-monitor") },
"Custom plugin monitor failed to register itself as a problem daemon.")
}
+8 -6
View File
@@ -30,13 +30,13 @@ type ProblemDetector interface {
}
type problemDetector struct {
monitors map[string]types.Monitor
monitors []types.Monitor
exporters []types.Exporter
}
// NewProblemDetector creates the problem detector. Currently we just directly passed in the problem daemons, but
// in the future we may want to let the problem daemons register themselves.
func NewProblemDetector(monitors map[string]types.Monitor, exporters []types.Exporter) ProblemDetector {
func NewProblemDetector(monitors []types.Monitor, exporters []types.Exporter) ProblemDetector {
return &problemDetector{
monitors: monitors,
exporters: exporters,
@@ -47,17 +47,19 @@ func NewProblemDetector(monitors map[string]types.Monitor, exporters []types.Exp
func (p *problemDetector) Run() error {
// Start the log monitors one by one.
var chans []<-chan *types.Status
for cfg, m := range p.monitors {
for _, m := range p.monitors {
ch, err := m.Start()
if err != nil {
// Do not return error and keep on trying the following config files.
glog.Errorf("Failed to start log monitor %q: %v", cfg, err)
glog.Errorf("Failed to start problem daemon %v: %v", m, err)
continue
}
chans = append(chans, ch)
if ch != nil {
chans = append(chans, ch)
}
}
if len(chans) == 0 {
return fmt.Errorf("no log monitor is successfully setup")
return fmt.Errorf("no problem daemon is successfully setup")
}
ch := groupChannel(chans)
glog.Info("Problem detector started")
+11
View File
@@ -23,6 +23,7 @@ import (
"github.com/golang/glog"
"k8s.io/node-problem-detector/pkg/problemdaemon"
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers"
watchertypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
@@ -32,6 +33,16 @@ import (
"k8s.io/node-problem-detector/pkg/util/tomb"
)
const SystemLogMonitorName = "system-log-monitor"
func init() {
problemdaemon.Register(
SystemLogMonitorName,
types.ProblemDaemonHandler{
CreateProblemDaemonOrDie: NewLogMonitorOrDie,
CmdOptionDescription: "Set to config file paths."})
}
type logMonitor struct {
watcher watchertypes.LogWatcher
buffer LogBuffer
+9
View File
@@ -21,6 +21,9 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"k8s.io/node-problem-detector/pkg/problemdaemon"
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
"k8s.io/node-problem-detector/pkg/types"
"k8s.io/node-problem-detector/pkg/util"
@@ -32,6 +35,12 @@ const (
testConditionB = "TestConditionB"
)
func TestRegistration(t *testing.T) {
assert.NotPanics(t,
func() { problemdaemon.GetProblemDaemonHandlerOrDie("system-log-monitor") },
"System log monitor failed to register itself as a problem daemon.")
}
func TestGenerateStatus(t *testing.T) {
initConditions := []types.Condition{
{