Skip to content

Commit

Permalink
feature(Kayenta Standalone): allow specifying a control offset in sta…
Browse files Browse the repository at this point in the history
…ndalone kayenta (#825)

* feat(standalone-canary-analysis): allow specifying a control offset in standalone kayenta

* feat(standalone-canary-analysis): add the baseline to end time

* chore(standalone-canary-analysis): tweak control offset field name to make units clear, add unit test

Co-authored-by: AbdulRahman AlHamali <[email protected]>
  • Loading branch information
fieldju and AbdulRahman AlHamali authored Dec 21, 2020
1 parent 6b387f3 commit bf6c47e
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 3 deletions.
64 changes: 64 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public class CanaryAnalysisExecutionRequestScope {
example = "us-west-2")
String controlLocation;

@ApiModelProperty(
value =
"The time offset in minutes to be subtracted from the control start and end time. If none is provided, the control is "
+ "evaluated at the same time as the experiment.",
example = "10")
@Builder.Default
Long controlOffsetInMinutes = 0L;

@ApiModelProperty(
value =
"This value is used to fetch the data for the experiment from the metrics service. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ protected Map<String, CanaryScopePair> buildRequestScopes(
new CanaryScope(
scope.getControlScope(),
scope.getControlLocation(),
scopeTimeConfig.start,
scopeTimeConfig.end,
scopeTimeConfig.start.minus(
Duration.ofMinutes(scope.getControlOffsetInMinutes())),
scopeTimeConfig.end.minus(
Duration.ofMinutes(scope.getControlOffsetInMinutes())),
config.getStep().getSeconds(),
scope.getExtendedScopeParams());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,27 @@ public void test_that_calculateLifetime_uses_supplied_start_and_end_time_if_prov
assertEquals(Instant.parse(startIso), actual.getStart());
assertEquals(Instant.parse(startIso).plus(3L, ChronoUnit.MINUTES), actual.getEnd());
}

@Test
public void
test_that_buildRequestScopes_has_expected_start_and_end_when_control_offset_is_supplied() {
int interval = 1;
String startIso = "2018-12-17T20:56:39.689Z";
Duration lifetimeDuration = Duration.ofMinutes(3L);
CanaryAnalysisExecutionRequest request =
CanaryAnalysisExecutionRequest.builder()
.scopes(
ImmutableList.of(
CanaryAnalysisExecutionRequestScope.builder()
.controlOffsetInMinutes(5L)
.startTimeIso(startIso)
.build()))
.build();

var requestScopes = stage.buildRequestScopes(request, interval, lifetimeDuration);
var defaultScope = requestScopes.get("default");
var expectedControlStartIso = "2018-12-17T20:51:39.689Z";
assertEquals(Instant.parse(startIso), defaultScope.getExperimentScope().getStart());
assertEquals(Instant.parse(expectedControlStartIso), defaultScope.getControlScope().getStart());
}
}

0 comments on commit bf6c47e

Please sign in to comment.