-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TSPS-181 Add stairway hooks for failed flights - update metrics and s…
…tatus (#141)
- Loading branch information
1 parent
d78464e
commit 69441a7
Showing
50 changed files
with
862 additions
and
545 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
service/src/main/java/bio/terra/pipelines/common/utils/StairwayFailedMetricsCounterHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package bio.terra.pipelines.common.utils; | ||
|
||
import static bio.terra.pipelines.common.utils.FlightUtils.flightMapKeyIsTrue; | ||
|
||
import bio.terra.pipelines.app.common.MetricsUtils; | ||
import bio.terra.pipelines.dependencies.stairway.JobMapKeys; | ||
import bio.terra.stairway.FlightContext; | ||
import bio.terra.stairway.FlightStatus; | ||
import bio.terra.stairway.HookAction; | ||
import bio.terra.stairway.StairwayHook; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* A {@link StairwayHook} that logs a pipeline failure to Prometheus metrics upon flight failure. | ||
* | ||
* <p>This hook action will only run if the flight's input parameters contain the JobMapKeys key for | ||
* DO_INCREMENT_METRICS_FAILED_COUNTER_HOOK and the flight's status is not SUCCESS. | ||
* | ||
* <p>The JobMapKeys key for PIPELINE_NAME is required to increment the failed flight. | ||
*/ | ||
@Component | ||
public class StairwayFailedMetricsCounterHook implements StairwayHook { | ||
private static final Logger logger = | ||
LoggerFactory.getLogger(StairwayFailedMetricsCounterHook.class); | ||
|
||
@Override | ||
public HookAction endFlight(FlightContext context) { | ||
|
||
if (flightMapKeyIsTrue( | ||
context.getInputParameters(), JobMapKeys.DO_INCREMENT_METRICS_FAILED_COUNTER_HOOK) | ||
&& context.getFlightStatus() != FlightStatus.SUCCESS) { | ||
logger.info( | ||
"Flight has status {}, incrementing failed flight counter", context.getFlightStatus()); | ||
|
||
// increment failed runs counter metric | ||
PipelinesEnum pipelinesEnum = | ||
PipelinesEnum.valueOf( | ||
context.getInputParameters().get(JobMapKeys.PIPELINE_NAME, String.class)); | ||
MetricsUtils.incrementPipelineRunFailed(pipelinesEnum); | ||
} | ||
return HookAction.CONTINUE; | ||
} | ||
} |
70 changes: 0 additions & 70 deletions
70
service/src/main/java/bio/terra/pipelines/common/utils/StairwayLoggingHook.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
service/src/main/java/bio/terra/pipelines/common/utils/StairwaySetPipelineRunStatusHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package bio.terra.pipelines.common.utils; | ||
|
||
import static bio.terra.pipelines.common.utils.FlightUtils.flightMapKeyIsTrue; | ||
|
||
import bio.terra.pipelines.dependencies.stairway.JobMapKeys; | ||
import bio.terra.pipelines.service.PipelineRunsService; | ||
import bio.terra.stairway.FlightContext; | ||
import bio.terra.stairway.FlightStatus; | ||
import bio.terra.stairway.HookAction; | ||
import bio.terra.stairway.StairwayHook; | ||
import java.util.UUID; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* A {@link StairwayHook} that updates the PipelineRun status to FAILED on flight failure. | ||
* | ||
* <p>This the endFlight hook action will only run if the flight's input parameters contain the | ||
* JobMapKeys key for DO_SET_PIPELINE_RUN_STATUS_FAILED_HOOK and the flight's status is not SUCCESS. | ||
* | ||
* <p>The JobMapKeys key for USER_ID is required to set the PipelineRun status to FAILED. | ||
*/ | ||
@Component | ||
public class StairwaySetPipelineRunStatusHook implements StairwayHook { | ||
private static final Logger logger = | ||
LoggerFactory.getLogger(StairwaySetPipelineRunStatusHook.class); | ||
private final PipelineRunsService pipelineRunsService; | ||
|
||
public StairwaySetPipelineRunStatusHook(PipelineRunsService pipelineRunsService) { | ||
this.pipelineRunsService = pipelineRunsService; | ||
} | ||
|
||
@Override | ||
public HookAction endFlight(FlightContext context) { | ||
|
||
if (flightMapKeyIsTrue( | ||
context.getInputParameters(), JobMapKeys.DO_SET_PIPELINE_RUN_STATUS_FAILED_HOOK) | ||
&& context.getFlightStatus() != FlightStatus.SUCCESS) { | ||
logger.info( | ||
"Flight has status {}, setting PipelineRun status to FAILED", context.getFlightStatus()); | ||
|
||
// set PipelineRun status to FAILED | ||
pipelineRunsService.markPipelineRunFailed( | ||
UUID.fromString(context.getFlightId()), | ||
context.getInputParameters().get(JobMapKeys.USER_ID, String.class)); | ||
} | ||
|
||
return HookAction.CONTINUE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.