@Test public void test_that_calculateStartAndEndForJudgement_has_expected_start_and_end_when_lookback_is_defined() { CanaryAnalysisExecutionRequest request = CanaryAnalysisExecutionRequest.builder() .lookbackMins(5L) .scopes(ImmutableList.of(CanaryAnalysisExecutionRequestScope.builder().build())) .build(); Duration intervalDuration = Duration.ofMinutes(5); for (int i = 1; i < 6; i++) { SetupAndExecuteCanariesStage.ScopeTimeConfig conf = stage.calculateStartAndEndForJudgement(request, i, intervalDuration); assertEquals(now.plus((i - 1) * 5, ChronoUnit.MINUTES), conf.getStart()); assertEquals(now.plus(i * 5, ChronoUnit.MINUTES), conf.getEnd()); } }
protected ScopeTimeConfig calculateStartAndEndForJudgement( CanaryAnalysisExecutionRequest config, long judgementNumber, Duration judgementDuration) { Duration warmupDuration = config.getBeginCanaryAnalysisAfterAsDuration(); Duration offset = judgementDuration.multipliedBy(judgementNumber); ScopeTimeConfig scopeTimeConfig = new ScopeTimeConfig(); Instant startTime = Optional.ofNullable(config.getStartTime()).orElse(now(clock)); scopeTimeConfig.start = startTime; scopeTimeConfig.end = startTime.plus(offset); if (config.getEndTime() == null) { scopeTimeConfig.start = scopeTimeConfig.start.plus(warmupDuration); scopeTimeConfig.end = scopeTimeConfig.end.plus(warmupDuration); } if (config.getLookBackAsInstant().isAfter(ZERO_AS_INSTANT)) { scopeTimeConfig.start = scopeTimeConfig.end.minus(config.getLookBackAsDuration()); } return scopeTimeConfig; }
SetupAndExecuteCanariesStage implements StageDefinitionBuilder { protected ScopeTimeConfig calculateStartAndEndForJudgement( CanaryAnalysisExecutionRequest config, long judgementNumber, Duration judgementDuration) { Duration warmupDuration = config.getBeginCanaryAnalysisAfterAsDuration(); Duration offset = judgementDuration.multipliedBy(judgementNumber); ScopeTimeConfig scopeTimeConfig = new ScopeTimeConfig(); Instant startTime = Optional.ofNullable(config.getStartTime()).orElse(now(clock)); scopeTimeConfig.start = startTime; scopeTimeConfig.end = startTime.plus(offset); if (config.getEndTime() == null) { scopeTimeConfig.start = scopeTimeConfig.start.plus(warmupDuration); scopeTimeConfig.end = scopeTimeConfig.end.plus(warmupDuration); } if (config.getLookBackAsInstant().isAfter(ZERO_AS_INSTANT)) { scopeTimeConfig.start = scopeTimeConfig.end.minus(config.getLookBackAsDuration()); } return scopeTimeConfig; } }
SetupAndExecuteCanariesStage implements StageDefinitionBuilder { protected ScopeTimeConfig calculateStartAndEndForJudgement( CanaryAnalysisExecutionRequest config, long judgementNumber, Duration judgementDuration) { Duration warmupDuration = config.getBeginCanaryAnalysisAfterAsDuration(); Duration offset = judgementDuration.multipliedBy(judgementNumber); ScopeTimeConfig scopeTimeConfig = new ScopeTimeConfig(); Instant startTime = Optional.ofNullable(config.getStartTime()).orElse(now(clock)); scopeTimeConfig.start = startTime; scopeTimeConfig.end = startTime.plus(offset); if (config.getEndTime() == null) { scopeTimeConfig.start = scopeTimeConfig.start.plus(warmupDuration); scopeTimeConfig.end = scopeTimeConfig.end.plus(warmupDuration); } if (config.getLookBackAsInstant().isAfter(ZERO_AS_INSTANT)) { scopeTimeConfig.start = scopeTimeConfig.end.minus(config.getLookBackAsDuration()); } return scopeTimeConfig; } @Autowired  SetupAndExecuteCanariesStage(Clock clock, ObjectMapper kayentaObjectMapper); }
SetupAndExecuteCanariesStage implements StageDefinitionBuilder { protected ScopeTimeConfig calculateStartAndEndForJudgement( CanaryAnalysisExecutionRequest config, long judgementNumber, Duration judgementDuration) { Duration warmupDuration = config.getBeginCanaryAnalysisAfterAsDuration(); Duration offset = judgementDuration.multipliedBy(judgementNumber); ScopeTimeConfig scopeTimeConfig = new ScopeTimeConfig(); Instant startTime = Optional.ofNullable(config.getStartTime()).orElse(now(clock)); scopeTimeConfig.start = startTime; scopeTimeConfig.end = startTime.plus(offset); if (config.getEndTime() == null) { scopeTimeConfig.start = scopeTimeConfig.start.plus(warmupDuration); scopeTimeConfig.end = scopeTimeConfig.end.plus(warmupDuration); } if (config.getLookBackAsInstant().isAfter(ZERO_AS_INSTANT)) { scopeTimeConfig.start = scopeTimeConfig.end.minus(config.getLookBackAsDuration()); } return scopeTimeConfig; } @Autowired  SetupAndExecuteCanariesStage(Clock clock, ObjectMapper kayentaObjectMapper); @Override void taskGraph(@Nonnull StageExecution stage, @Nonnull TaskNode.Builder builder); @Override void beforeStages(@Nonnull StageExecution parent, @Nonnull StageGraphBuilder graph); @Override void onFailureStages(@Nonnull StageExecution parent, @Nonnull StageGraphBuilder graph); @Override void afterStages(@Nonnull StageExecution parent, @Nonnull StageGraphBuilder graph); @Nonnull @Override String getType(); }
SetupAndExecuteCanariesStage implements StageDefinitionBuilder { protected ScopeTimeConfig calculateStartAndEndForJudgement( CanaryAnalysisExecutionRequest config, long judgementNumber, Duration judgementDuration) { Duration warmupDuration = config.getBeginCanaryAnalysisAfterAsDuration(); Duration offset = judgementDuration.multipliedBy(judgementNumber); ScopeTimeConfig scopeTimeConfig = new ScopeTimeConfig(); Instant startTime = Optional.ofNullable(config.getStartTime()).orElse(now(clock)); scopeTimeConfig.start = startTime; scopeTimeConfig.end = startTime.plus(offset); if (config.getEndTime() == null) { scopeTimeConfig.start = scopeTimeConfig.start.plus(warmupDuration); scopeTimeConfig.end = scopeTimeConfig.end.plus(warmupDuration); } if (config.getLookBackAsInstant().isAfter(ZERO_AS_INSTANT)) { scopeTimeConfig.start = scopeTimeConfig.end.minus(config.getLookBackAsDuration()); } return scopeTimeConfig; } @Autowired  SetupAndExecuteCanariesStage(Clock clock, ObjectMapper kayentaObjectMapper); @Override void taskGraph(@Nonnull StageExecution stage, @Nonnull TaskNode.Builder builder); @Override void beforeStages(@Nonnull StageExecution parent, @Nonnull StageGraphBuilder graph); @Override void onFailureStages(@Nonnull StageExecution parent, @Nonnull StageGraphBuilder graph); @Override void afterStages(@Nonnull StageExecution parent, @Nonnull StageGraphBuilder graph); @Nonnull @Override String getType(); static final String STAGE_TYPE; static final String STAGE_DESCRIPTION; }