@@ -17,6 +17,7 @@ limitations under the License.
1717package problemdetector
1818
1919import (
20+ "fmt"
2021"net/http"
2122
2223"github.com/golang/glog"
@@ -26,6 +27,7 @@ import (
2627"k8s.io/node-problem-detector/pkg/condition"
2728"k8s.io/node-problem-detector/pkg/problemclient"
2829"k8s.io/node-problem-detector/pkg/systemlogmonitor"
30+ "k8s.io/node-problem-detector/pkg/types"
2931"k8s.io/node-problem-detector/pkg/util"
3032)
3133
@@ -38,28 +40,39 @@ type ProblemDetector interface {
3840type problemDetector struct {
3941client problemclient.Client
4042conditionManager condition.ConditionManager
41- // TODO(random-liu): Use slices of problem daemons if multiple monitors are needed in the future
42- monitor systemlogmonitor.LogMonitor
43+ monitors map [string ]systemlogmonitor.LogMonitor
4344}
4445
4546// NewProblemDetector creates the problem detector. Currently we just directly passed in the problem daemons, but
4647// in the future we may want to let the problem daemons register themselves.
47- func NewProblemDetector (monitor systemlogmonitor.LogMonitor , client problemclient.Client ) ProblemDetector {
48+ func NewProblemDetector (monitors map [ string ] systemlogmonitor.LogMonitor , client problemclient.Client ) ProblemDetector {
4849return & problemDetector {
4950client : client ,
5051conditionManager : condition .NewConditionManager (client , clock.RealClock {}),
51- monitor : monitor ,
52+ monitors : monitors ,
5253}
5354}
5455
5556// Run starts the problem detector.
5657func (p * problemDetector ) Run () error {
5758p .conditionManager .Start ()
58- ch , err := p .monitor .Start ()
59- if err != nil {
60- return err
59+ // Start the log monitors one by one.
60+ var chans []<- chan * types.Status
61+ for cfg , m := range p .monitors {
62+ ch , err := m .Start ()
63+ if err != nil {
64+ // Do not return error and keep on trying the following config files.
65+ glog .Errorf ("Failed to start log monitor %q: %v" , cfg , err )
66+ continue
67+ }
68+ chans = append (chans , ch )
69+ }
70+ if len (chans ) == 0 {
71+ return fmt .Errorf ("no log montior is successfully setup" )
6172}
73+ ch := groupChannel (chans )
6274glog .Info ("Problem detector started" )
75+
6376for {
6477select {
6578case status := <- ch :
@@ -80,3 +93,15 @@ func (p *problemDetector) RegisterHTTPHandlers() {
8093util .ReturnHTTPJson (w , p .conditionManager .GetConditions ())
8194})
8295}
96+
97+ func groupChannel (chans []<- chan * types.Status ) <- chan * types.Status {
98+ statuses := make (chan * types.Status )
99+ for _ , ch := range chans {
100+ go func (c <- chan * types.Status ) {
101+ for status := range c {
102+ statuses <- status
103+ }
104+ }(ch )
105+ }
106+ return statuses
107+ }
0 commit comments