Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calibration runs failing at DCS SOR + fix AutoEnvs erroring out without proper ERROR state #522

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions core/environment/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ func (envs *Manager) CreateAutoEnvironment(workflowPath string, userVars map[str
log.WithField("partition", env.Id().String()).
WithField("state", envState).
Debug("could not transition to ERROR after failed deployment/configuration, cleanup in progress")

}

envTasks := env.Workflow().GetTasks()
Expand Down Expand Up @@ -973,7 +974,45 @@ func (envs *Manager) CreateAutoEnvironment(workflowPath string, userVars map[str

err = env.TryTransition(trans)
if err != nil {
envState := env.CurrentState()

env.sendEnvironmentEvent(&event.EnvironmentEvent{EnvironmentID: env.Id().String(), Error: err})

log.WithField("state", envState).
WithField("environment", env.Id().String()).
WithError(err).
Warn("environment start activity failed, cleanup in progress")

err = env.TryTransition(NewGoErrorTransition(
envs.taskman),
)
if err != nil {
log.WithField("partition", env.Id().String()).
WithField("state", envState).
Debug("could not transition to ERROR after failed start activity, cleanup in progress")

env.setState("ERROR")
}

envTasks := env.Workflow().GetTasks()
// TeardownEnvironment manages the envs.mu internally
err = envs.TeardownEnvironment(env.Id(), true /*force*/)
if err != nil {
env.sendEnvironmentEvent(&event.EnvironmentEvent{EnvironmentID: env.Id().String(), Error: err})
}

killedTasks, _, rlsErr := envs.taskman.KillTasks(envTasks.GetTaskIds())
if rlsErr != nil {
log.WithError(rlsErr).Warn("task teardown error")
}
log.WithFields(logrus.Fields{
"killedCount": len(killedTasks),
"lastEnvState": envState,
"level": infologger.IL_Support,
"partition": env.Id().String(),
}).Info("environment start activity failed, tasks were cleaned up")

log.WithField("partition", env.Id().String()).Info("environment teardown complete")
return
}

Expand Down
100 changes: 98 additions & 2 deletions core/integration/dcs/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,54 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
return
}

// We acquire a grace period during which we hope that DCS will become compatible with the operation.
// During this period we'll keep checking our internal state for op compatibility as reported by DCS at 1Hz,
// and if we don't get a compatible state within the grace period, we declare the operation failed.
pfrGracePeriod := time.Duration(0)
pfrGracePeriodS, ok := varStack["dcs_pfr_grace_period"]
if ok {
pfrGracePeriod, err = time.ParseDuration(pfrGracePeriodS)
if err != nil {
log.WithError(err).
WithField("level", infologger.IL_Ops).
WithField("partition", envId).
WithField("call", "PrepareForRun").
Warnf("cannot parse DCS PFR grace period, assuming 0 seconds")
}
} else {
log.WithField("level", infologger.IL_Ops).
WithField("partition", envId).
WithField("call", "PrepareForRun").
Info("DCS PFR grace period not set, defaulting to 0 seconds")
}

pfrGraceTimeout := time.Now().Add(pfrGracePeriod)
isCompatibleWithOperation := false

knownDetectorStates := p.getDetectorsPfrAvailability(dcsDetectors)
isCompatibleWithOperation, err := knownDetectorStates.compatibleWithDCSOperation(dcspb.DetectorState_PFR_AVAILABLE)
isCompatibleWithOperation, err = knownDetectorStates.compatibleWithDCSOperation(dcspb.DetectorState_PFR_AVAILABLE)

for {
if isCompatibleWithOperation {
break
} else {
log.WithField("level", infologger.IL_Ops).
WithField("partition", envId).
WithField("call", "PrepareForRun").
WithField("grace_period", pfrGracePeriod.String()).
WithField("remaining_grace_period", pfrGraceTimeout.Sub(time.Now()).String()).
Infof("waiting for DCS operation readiness: %s", err.Error())
time.Sleep(1 * time.Second)
}

if time.Now().Before(pfrGraceTimeout) {
knownDetectorStates = p.getDetectorsPfrAvailability(dcsDetectors)
isCompatibleWithOperation, err = knownDetectorStates.compatibleWithDCSOperation(dcspb.DetectorState_PFR_AVAILABLE)
} else {
break
}
}

if !isCompatibleWithOperation {
log.WithError(err).
WithField("level", infologger.IL_Ops).
Expand All @@ -422,6 +468,8 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
Warnf("cannot determine PFR readiness: %s", err.Error())
}

// By now the DCS must be in a compatible state, so we proceed with gathering params for the operation

log.WithField("partition", envId).
WithField("level", infologger.IL_Ops).
Infof("performing DCS PFR for detectors: %s", strings.Join(dcsDetectors.EcsDetectorsSlice(), " "))
Expand Down Expand Up @@ -790,8 +838,54 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
return
}

// We acquire a grace period during which we hope that DCS will become compatible with the operation.
// During this period we'll keep checking our internal state for op compatibility as reported by DCS at 1Hz,
// and if we don't get a compatible state within the grace period, we declare the operation failed.
sorGracePeriod := time.Duration(0)
sorGracePeriodS, ok := varStack["dcs_sor_grace_period"]
if ok {
sorGracePeriod, err = time.ParseDuration(sorGracePeriodS)
if err != nil {
log.WithError(err).
WithField("level", infologger.IL_Ops).
WithField("partition", envId).
WithField("call", "StartOfRun").
Warnf("cannot parse DCS SOR grace period, assuming 0 seconds")
}
} else {
log.WithField("level", infologger.IL_Ops).
WithField("partition", envId).
WithField("call", "StartOfRun").
Info("DCS SOR grace period not set, defaulting to 0 seconds")
}

sorGraceTimeout := time.Now().Add(sorGracePeriod)
isCompatibleWithOperation := false

knownDetectorStates := p.getDetectorsSorAvailability(dcsDetectors)
isCompatibleWithOperation, err := knownDetectorStates.compatibleWithDCSOperation(dcspb.DetectorState_SOR_AVAILABLE)
isCompatibleWithOperation, err = knownDetectorStates.compatibleWithDCSOperation(dcspb.DetectorState_SOR_AVAILABLE)

for {
if isCompatibleWithOperation {
break
} else {
log.WithField("level", infologger.IL_Ops).
WithField("partition", envId).
WithField("call", "StartOfRun").
WithField("grace_period", sorGracePeriod.String()).
WithField("remaining_grace_period", sorGraceTimeout.Sub(time.Now()).String()).
Infof("waiting for DCS operation readiness: %s", err.Error())
time.Sleep(1 * time.Second)
}

if time.Now().Before(sorGraceTimeout) {
knownDetectorStates = p.getDetectorsSorAvailability(dcsDetectors)
isCompatibleWithOperation, err = knownDetectorStates.compatibleWithDCSOperation(dcspb.DetectorState_SOR_AVAILABLE)
} else {
break
}
}

if !isCompatibleWithOperation {
log.WithError(err).
WithField("level", infologger.IL_Ops).
Expand All @@ -810,6 +904,8 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
Warnf("cannot determine SOR readiness: %s", err.Error())
}

// By now the DCS must be in a compatible state, so we proceed with gathering params for the operation

log.WithField("partition", envId).
WithField("level", infologger.IL_Ops).
WithField("run", runNumber64).
Expand Down
Loading