@Test public void test_that_calculateStartAndEndForJudgement_has_expected_start_and_end_when_start_and_end_are_supplied_in_the_scopes_with_warmup() { Instant definedStart = now.minus(5, ChronoUnit.MINUTES); Instant definedEnd = now.plus(20, ChronoUnit.MINUTES); CanaryAnalysisExecutionRequest request = CanaryAnalysisExecutionRequest.builder() .beginAfterMins(4L) .scopes( ImmutableList.of( CanaryAnalysisExecutionRequestScope.builder() .startTimeIso(definedStart.toString()) .endTimeIso(definedEnd.toString()) .build())) .build(); Duration intervalDuration = Duration.ofMinutes(3); for (int i = 1; i < 6; i++) { SetupAndExecuteCanariesStage.ScopeTimeConfig conf = stage.calculateStartAndEndForJudgement(request, i, intervalDuration); assertEquals(definedStart, conf.getStart()); assertEquals(definedStart.plus(i * 3, 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; }