From 8f89c14ea117a18baec71d9be2589539ca19ebaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Pa=C3=9F?= <22845248+mpass99@users.noreply.github.com> Date: Wed, 10 May 2023 11:29:31 +0100 Subject: [PATCH] Cleanup logs for Allocation recovery on startup. The changes do not have functional consequences as adding the allocation just overwrites the old one. --- internal/nomad/nomad.go | 14 ++++++++------ internal/runner/nomad_manager.go | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/nomad/nomad.go b/internal/nomad/nomad.go index 9da8ec2..85abe56 100644 --- a/internal/nomad/nomad.go +++ b/internal/nomad/nomad.go @@ -150,7 +150,7 @@ func (a *APIClient) LoadRunnerPortMappings(runnerID string) ([]nomadApi.PortMapp } func (a *APIClient) LoadRunnerJobs(environmentID dto.EnvironmentID) ([]*nomadApi.Job, error) { - go a.initializeAllocations() + go a.initializeAllocations(environmentID) runnerIDs, err := a.LoadRunnerIDs(RunnerJobID(environmentID, "")) if err != nil { @@ -234,17 +234,19 @@ func dumpNomadEventToInflux(event *nomadApi.Event) { monitoring.WriteInfluxPoint(p) } -func (a *APIClient) initializeAllocations() { +func (a *APIClient) initializeAllocations(environmentID dto.EnvironmentID) { allocationStubs, err := a.listAllocations() if err != nil { log.WithError(err).Warn("Could not initialize allocations") } else { for _, stub := range allocationStubs { - if IsEnvironmentTemplateID(stub.JobID) { + switch { + case IsEnvironmentTemplateID(stub.JobID): continue - } else if stub.ClientStatus == structs.AllocClientStatusPending || - stub.ClientStatus == structs.AllocClientStatusRunning { - log.WithField("jobID", stub.JobID).WithField("status", stub.ClientStatus).Debug("Recovered Runner") + case !strings.HasPrefix(stub.JobID, RunnerJobID(environmentID, "")): + continue + case stub.ClientStatus == structs.AllocClientStatusPending || stub.ClientStatus == structs.AllocClientStatusRunning: + log.WithField("jobID", stub.JobID).WithField("status", stub.ClientStatus).Debug("Recovered Allocation") a.allocations.Add(stub.ID, &allocationData{allocClientStatus: stub.ClientStatus, start: time.Unix(0, stub.CreateTime), jobID: stub.JobID}) } diff --git a/internal/runner/nomad_manager.go b/internal/runner/nomad_manager.go index 02260a2..def4cbd 100644 --- a/internal/runner/nomad_manager.go +++ b/internal/runner/nomad_manager.go @@ -115,6 +115,7 @@ func (m *NomadRunnerManager) loadSingleJob(job *nomadApi.Job, environmentLogger return } newJob := NewNomadJob(*job.ID, portMappings, m.apiClient, m.Return) + log.WithField("isUsed", isUsed).WithField("runner_id", newJob.ID()).Debug("Recovered Runner") if isUsed { m.usedRunners.Add(newJob.ID(), newJob) timeout, err := strconv.Atoi(configTaskGroup.Meta[nomad.ConfigMetaTimeoutKey])