Skip to content

Commit

Permalink
Log unexpectedly stopped environments
Browse files Browse the repository at this point in the history
  • Loading branch information
mpass99 authored and MrSerth committed Sep 2, 2024
1 parent 13b33b0 commit a8de9b2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/runner/nomad_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,17 @@ func (m *NomadRunnerManager) onAllocationStopped(ctx context.Context, runnerID s
log.WithField(dto.KeyRunnerID, runnerID).Debug("Runner stopped")

if nomad.IsEnvironmentTemplateID(runnerID) {
return false
environmentID, err := nomad.EnvironmentIDFromTemplateJobID(runnerID)
if err != nil {
log.WithError(err).WithField(dto.KeyEnvironmentID, runnerID).WithField("reason", reason).
Error("Cannot parse environment id")
return false

Check warning on line 317 in internal/runner/nomad_manager.go

View check run for this annotation

Codecov / codecov/patch

internal/runner/nomad_manager.go#L315-L317

Added lines #L315 - L317 were not covered by tests
}
_, ok := m.environments.Get(environmentID.ToString())
if ok {
log.WithField(dto.KeyEnvironmentID, environmentID).Warn("Environment stopped unexpectedly")
}
return !ok
}

environmentID, err := nomad.EnvironmentIDFromRunnerID(runnerID)
Expand Down
19 changes: 19 additions & 0 deletions internal/runner/nomad_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,25 @@ func (s *ManagerTestSuite) TestOnAllocationStopped() {
s.True(alreadyRemoved)
})
})
s.Run("logs unexpectedly stopped environments", func() {
logger, hook := test.NewNullLogger()
log = logger.WithField("package", "runner")

alreadyRemoved := s.nomadRunnerManager.onAllocationStopped(s.TestCtx, tests.DefaultTemplateJobID, nil)
s.False(alreadyRemoved)

s.Len(hook.Entries, 1)
s.Equal(logrus.WarnLevel, hook.LastEntry().Level)
})
s.Run("does not log expectedly stopped environments", func() {
logger, hook := test.NewNullLogger()
log = logger.WithField("package", "runner")

s.nomadRunnerManager.DeleteEnvironment(tests.DefaultEnvironmentIDAsInteger)
alreadyRemoved := s.nomadRunnerManager.onAllocationStopped(s.TestCtx, tests.DefaultTemplateJobID, nil)
s.True(alreadyRemoved)
s.Empty(hook.Entries)
})
}

func testStoppedInactivityTimer(s *ManagerTestSuite) (r Runner, destroyed chan struct{}) {
Expand Down

0 comments on commit a8de9b2

Please sign in to comment.