protected Duration calculateLifetime(
      Instant start,
      Instant endTime,
      CanaryAnalysisExecutionRequest canaryAnalysisExecutionRequest) {

    Duration lifetime;
    if (endTime != null) {
      lifetime = Duration.ofMinutes(start.until(endTime, MINUTES));
    } else if (canaryAnalysisExecutionRequest.getLifetimeDuration() != null) {
      lifetime = canaryAnalysisExecutionRequest.getLifetimeDuration();
    } else {
      throw new IllegalArgumentException(
          "Canary StageExecution configuration must include either `endTime` or `lifetimeDuration`.");
    }

    return lifetime;
  }
@Test
  public void test_that_calculateLifetime_uses_supplied_start_and_end_time_if_provided() {
    int lifetimeInMinutes = 5;
    Instant now = Instant.now();
    Instant later = now.plus(lifetimeInMinutes, ChronoUnit.MINUTES);
    CanaryAnalysisExecutionRequest request = CanaryAnalysisExecutionRequest.builder().build();

    Duration actual = stage.calculateLifetime(now, later, request);
    Duration expected = Duration.ofMinutes(lifetimeInMinutes);

    assertEquals(expected, actual, "The duration should be 5 minutes");
  }