소스 검색

Merge pull request #26972 from allencloud/clear-health-monitor-log

make health check log more readable
Vincent Demeester 8 년 전
부모
커밋
601004e1a7
2개의 변경된 파일9개의 추가작업 그리고 9개의 파일을 삭제
  1. 8 8
      daemon/health.go
  2. 1 1
      daemon/monitor.go

+ 8 - 8
daemon/health.go

@@ -94,7 +94,7 @@ func (p *cmdProbe) run(ctx context.Context, d *Daemon, container *container.Cont
 		return nil, err
 		return nil, err
 	}
 	}
 	if info.ExitCode == nil {
 	if info.ExitCode == nil {
-		return nil, fmt.Errorf("Healthcheck has no exit code!")
+		return nil, fmt.Errorf("Healthcheck for container %s has no exit code!", container.ID)
 	}
 	}
 	// Note: Go's json package will handle invalid UTF-8 for us
 	// Note: Go's json package will handle invalid UTF-8 for us
 	out := output.String()
 	out := output.String()
@@ -149,17 +149,17 @@ func monitor(d *Daemon, c *container.Container, stop chan struct{}, probe probe)
 	for {
 	for {
 		select {
 		select {
 		case <-stop:
 		case <-stop:
-			logrus.Debug("Stop healthcheck monitoring (received while idle)")
+			logrus.Debugf("Stop healthcheck monitoring for container %s (received while idle)", c.ID)
 			return
 			return
 		case <-time.After(probeInterval):
 		case <-time.After(probeInterval):
-			logrus.Debug("Running health check...")
+			logrus.Debugf("Running health check for container %s ...", c.ID)
 			startTime := time.Now()
 			startTime := time.Now()
 			ctx, cancelProbe := context.WithTimeout(context.Background(), probeTimeout)
 			ctx, cancelProbe := context.WithTimeout(context.Background(), probeTimeout)
 			results := make(chan *types.HealthcheckResult)
 			results := make(chan *types.HealthcheckResult)
 			go func() {
 			go func() {
 				result, err := probe.run(ctx, d, c)
 				result, err := probe.run(ctx, d, c)
 				if err != nil {
 				if err != nil {
-					logrus.Warnf("Health check error: %v", err)
+					logrus.Warnf("Health check for container %s error: %v", c.ID, err)
 					results <- &types.HealthcheckResult{
 					results <- &types.HealthcheckResult{
 						ExitCode: -1,
 						ExitCode: -1,
 						Output:   err.Error(),
 						Output:   err.Error(),
@@ -168,14 +168,14 @@ func monitor(d *Daemon, c *container.Container, stop chan struct{}, probe probe)
 					}
 					}
 				} else {
 				} else {
 					result.Start = startTime
 					result.Start = startTime
-					logrus.Debugf("Health check done (exitCode=%d)", result.ExitCode)
+					logrus.Debugf("Health check for container %s done (exitCode=%d)", c.ID, result.ExitCode)
 					results <- result
 					results <- result
 				}
 				}
 				close(results)
 				close(results)
 			}()
 			}()
 			select {
 			select {
 			case <-stop:
 			case <-stop:
-				logrus.Debug("Stop healthcheck monitoring (received while probing)")
+				logrus.Debugf("Stop healthcheck monitoring for container %s (received while probing)", c.ID)
 				// Stop timeout and kill probe, but don't wait for probe to exit.
 				// Stop timeout and kill probe, but don't wait for probe to exit.
 				cancelProbe()
 				cancelProbe()
 				return
 				return
@@ -184,7 +184,7 @@ func monitor(d *Daemon, c *container.Container, stop chan struct{}, probe probe)
 				// Stop timeout
 				// Stop timeout
 				cancelProbe()
 				cancelProbe()
 			case <-ctx.Done():
 			case <-ctx.Done():
-				logrus.Debug("Health check taking too long")
+				logrus.Debugf("Health check for container %s taking too long", c.ID)
 				handleProbeResult(d, c, &types.HealthcheckResult{
 				handleProbeResult(d, c, &types.HealthcheckResult{
 					ExitCode: -1,
 					ExitCode: -1,
 					Output:   fmt.Sprintf("Health check exceeded timeout (%v)", probeTimeout),
 					Output:   fmt.Sprintf("Health check exceeded timeout (%v)", probeTimeout),
@@ -213,7 +213,7 @@ func getProbe(c *container.Container) probe {
 	case "CMD-SHELL":
 	case "CMD-SHELL":
 		return &cmdProbe{shell: true}
 		return &cmdProbe{shell: true}
 	default:
 	default:
-		logrus.Warnf("Unknown healthcheck type '%s' (expected 'CMD')", config.Test[0])
+		logrus.Warnf("Unknown healthcheck type '%s' (expected 'CMD') in container %s", config.Test[0], c.ID)
 		return nil
 		return nil
 	}
 	}
 }
 }

+ 1 - 1
daemon/monitor.go

@@ -30,7 +30,7 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error {
 		daemon.updateHealthMonitor(c)
 		daemon.updateHealthMonitor(c)
 		daemon.LogContainerEvent(c, "oom")
 		daemon.LogContainerEvent(c, "oom")
 	case libcontainerd.StateExit:
 	case libcontainerd.StateExit:
-		// if containers AutoRemove flag is set, remove it after clean up
+		// if container's AutoRemove flag is set, remove it after clean up
 		if c.HostConfig.AutoRemove {
 		if c.HostConfig.AutoRemove {
 			defer func() {
 			defer func() {
 				if err := daemon.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: true, RemoveVolume: true}); err != nil {
 				if err := daemon.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: true, RemoveVolume: true}); err != nil {