1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-16 18:01:34 +00:00

fixup service names in log & error messages

This commit is contained in:
Mathieu Fenniak 2025-08-05 21:10:50 -06:00
parent aa70cb7d7b
commit fdec3fe75b
2 changed files with 13 additions and 12 deletions

View file

@ -745,16 +745,14 @@ func (rc *RunContext) startServiceContainers(_ string) common.Executor {
} }
} }
func (rc *RunContext) waitForServiceContainer(c container.ExecutionsEnvironment) common.Executor { func (rc *RunContext) waitForServiceContainer(c container.ExecutionsEnvironment, serviceID string) common.Executor {
// FIXME: GetName() is definitely 'wrong' because it just returns "NAME". :-p
return func(ctx context.Context) error { return func(ctx context.Context) error {
logger := common.Logger(ctx) logger := common.Logger(ctx)
timeout, err := c.GetHealthCheckTimeout(ctx) timeout, err := c.GetHealthCheckTimeout(ctx)
if err != nil { if err != nil {
return fmt.Errorf("service container %s could not detect health check timeout due to error, no health check wait will occur: %v", c.GetName(), err) return fmt.Errorf("service container %s: error retrieving health check details: %v", serviceID, err)
} else if timeout == nil { } else if timeout == nil {
logger.Debugf("service container %s had no health check", c.GetName()) logger.Debugf("service container %s: skipping health check wait", serviceID)
return nil return nil
} }
@ -765,7 +763,7 @@ func (rc *RunContext) waitForServiceContainer(c container.ExecutionsEnvironment)
for { for {
health, err := c.GetHealth(ctx) health, err := c.GetHealth(ctx)
if errors.Is(err, context.DeadlineExceeded) { if errors.Is(err, context.DeadlineExceeded) {
return fmt.Errorf("service container %s: timed out while waiting for healthy or unhealthy status to be reported", c.GetName()) return fmt.Errorf("service container %s: timed out while waiting for healthy or unhealthy status to be reported", serviceID)
} else if errors.Is(err, context.Canceled) { } else if errors.Is(err, context.Canceled) {
return err return err
} else if errors.Is(err, container.ErrContainerNotFound) || (err == nil && health == container.HealthUnHealthy) { } else if errors.Is(err, container.ErrContainerNotFound) || (err == nil && health == container.HealthUnHealthy) {
@ -774,10 +772,10 @@ func (rc *RunContext) waitForServiceContainer(c container.ExecutionsEnvironment)
// then start reporting container not found; so, report both the same. Without any detection of the // then start reporting container not found; so, report both the same. Without any detection of the
// ErrContainerNotFound case we would just treat it as a transient failure and timeout, which would be a // ErrContainerNotFound case we would just treat it as a transient failure and timeout, which would be a
// slower error mode that this is working to avoid. // slower error mode that this is working to avoid.
return fmt.Errorf("service container %s: failed health check or terminated before becoming healthy", c.GetName()) return fmt.Errorf("service container %s: failed health check or terminated before becoming healthy", serviceID)
} else if err != nil { } else if err != nil {
// assume transient error in the execution environment // assume transient error in the execution environment
logger.Warnf("service container %s: error while checking for health state, will retry: %v", c.GetName(), err) logger.Warnf("service container %s: error while checking for health state, will retry: %v", serviceID, err)
} else if health == container.HealthHealthy { } else if health == container.HealthHealthy {
return nil return nil
} }
@ -793,8 +791,11 @@ func (rc *RunContext) waitForServiceContainer(c container.ExecutionsEnvironment)
func (rc *RunContext) waitForServiceContainers() common.Executor { func (rc *RunContext) waitForServiceContainers() common.Executor {
return func(ctx context.Context) error { return func(ctx context.Context) error {
execs := []common.Executor{} execs := []common.Executor{}
for _, c := range rc.ServiceContainers { i := 0
execs = append(execs, rc.waitForServiceContainer(c)) for serviceID := range rc.Run.Job().Services {
c := rc.ServiceContainers[i]
execs = append(execs, rc.waitForServiceContainer(c, serviceID))
i++
} }
return common.NewParallelExecutor(len(execs), execs...)(ctx) return common.NewParallelExecutor(len(execs), execs...)(ctx)
} }

View file

@ -323,8 +323,8 @@ func TestRunner_RunEvent(t *testing.T) {
{workdir, "services", "push", "", platforms, secrets}, {workdir, "services", "push", "", platforms, secrets},
{workdir, "services-with-container", "push", "", platforms, secrets}, {workdir, "services-with-container", "push", "", platforms, secrets},
{workdir, "mysql-service-container-with-health-check", "push", "", platforms, secrets}, {workdir, "mysql-service-container-with-health-check", "push", "", platforms, secrets},
{workdir, "mysql-service-container-failed-health-check", "push", "service container NAME: failed health check or terminated before becoming healthy", platforms, secrets}, {workdir, "mysql-service-container-failed-health-check", "push", "service container maindb: failed health check or terminated before becoming healthy", platforms, secrets},
{workdir, "mysql-service-container-premature-terminate", "push", "service container NAME: failed health check or terminated before becoming healthy", platforms, secrets}, {workdir, "mysql-service-container-premature-terminate", "push", "service container maindb: failed health check or terminated before becoming healthy", platforms, secrets},
} }
for _, table := range tables { for _, table := range tables {