Skip to content

Commit

Permalink
Add /canary/ endpoint, remove metricSetPairListId from old location (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Graff committed Dec 21, 2017
1 parent 8c5bd7a commit ca30f02
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public class CanaryExecutionStatusResponse {

protected CanaryResult result;

// TODO: (mgraff) Remove this once our UIs are set up to get it from the canary result itself
protected String metricSetPairListId;

//
// buildTime is when the pipeline was first created.
// startTime refers to the time the pipeline started running.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,85 @@ public CanaryExecutionResponse initiateCanary(@RequestParam(required = false) fi
return CanaryExecutionResponse.builder().canaryExecutionId(pipeline.getId()).build();
}

//
// Get the results of a canary run by ID
//
@ApiOperation(value = "Retrieve status and results for a canary run")
@RequestMapping(value = "/{canaryExecutionId:.+}", method = RequestMethod.GET)
public CanaryExecutionStatusResponse getCanaryResults(@RequestParam(required = false) final String storageAccountName,
@PathVariable String canaryExecutionId) throws JsonProcessingException {
String resolvedStorageAccountName = CredentialsHelper.resolveAccountByNameOrType(storageAccountName,
AccountCredentials.Type.OBJECT_STORE,
accountCredentialsRepository);

StorageService storageService =
storageServiceRepository
.getOne(resolvedStorageAccountName)
.orElseThrow(() -> new IllegalArgumentException("No storage service was configured; unable to retrieve results."));

Execution pipeline = executionRepository.retrieve(Execution.ExecutionType.PIPELINE, canaryExecutionId);
Stage judgeStage = pipeline.getStages().stream()
.filter(stage -> stage.getRefId().equals(REFID_JUDGE))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unable to find stage '" + REFID_JUDGE + "' in pipeline ID '" + canaryExecutionId + "'"));
Map<String, Object> judgeContext = judgeStage.getContext();

Stage contextStage = pipeline.getStages().stream()
.filter(stage -> stage.getRefId().equals(REFID_SET_CONTEXT))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unable to find stage '" + REFID_SET_CONTEXT + "' in pipeline ID '" + canaryExecutionId + "'"));
Map<String, Object> contextContext = contextStage.getContext();

Stage mixerStage = pipeline.getStages().stream()
.filter(stage -> stage.getRefId().equals(REFID_MIX_METRICS))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unable to find stage '" + REFID_MIX_METRICS + "' in pipeline ID '" + canaryExecutionId + "'"));
Map<String, Object> mixerContext = mixerStage.getContext();

if (!contextContext.containsKey("canaryConfigId")) {
throw new IllegalArgumentException("The judge stage does not contain a canaryConfigId reference");
}

CanaryExecutionStatusResponse.CanaryExecutionStatusResponseBuilder canaryExecutionStatusResponseBuilder = CanaryExecutionStatusResponse.builder();

Map<String, String> stageStatus = pipeline.getStages()
.stream()
.collect(Collectors.toMap(Stage::getRefId, s -> s.getStatus().toString().toLowerCase()));

Boolean isComplete = pipeline.getStatus().isComplete();
String pipelineStatus = pipeline.getStatus().toString().toLowerCase();
canaryExecutionStatusResponseBuilder.stageStatus(stageStatus);
canaryExecutionStatusResponseBuilder.complete(isComplete);
canaryExecutionStatusResponseBuilder.status(pipelineStatus);

Long buildTime = pipeline.getBuildTime();
if (buildTime != null) {
canaryExecutionStatusResponseBuilder.buildTimeMillis(buildTime);
canaryExecutionStatusResponseBuilder.buildTimeIso(Instant.ofEpochMilli(buildTime) + "");
}

Long startTime = pipeline.getStartTime();
if (startTime != null) {
canaryExecutionStatusResponseBuilder.startTimeMillis(startTime);
canaryExecutionStatusResponseBuilder.startTimeIso(Instant.ofEpochMilli(startTime) + "");
}

Long endTime = pipeline.getEndTime();
if (endTime != null) {
canaryExecutionStatusResponseBuilder.endTimeMillis(endTime);
canaryExecutionStatusResponseBuilder.endTimeIso(Instant.ofEpochMilli(endTime) + "");
}

if (isComplete && pipelineStatus.equals("succeeded")) {
if (judgeContext.containsKey("canaryJudgeResultId")) {
String canaryJudgeResultId = (String)judgeContext.get("canaryJudgeResultId");
canaryExecutionStatusResponseBuilder.result(storageService.loadObject(resolvedStorageAccountName, ObjectType.CANARY_RESULT, canaryJudgeResultId));
}
}

return canaryExecutionStatusResponseBuilder.build();
}

//
// Get the results of a canary run by ID
//
Expand Down Expand Up @@ -293,9 +372,6 @@ public CanaryExecutionStatusResponse getCanaryResults(@RequestParam(required = f
canaryExecutionStatusResponseBuilder.endTimeIso(Instant.ofEpochMilli(endTime) + "");
}

// TODO: (mgraff) Remove this once our UIs are set up to get it from the canary result itself
canaryExecutionStatusResponseBuilder.metricSetPairListId((String)mixerContext.get("metricSetPairListId"));

if (isComplete && pipelineStatus.equals("succeeded")) {
if (judgeContext.containsKey("canaryJudgeResultId")) {
String canaryJudgeResultId = (String)judgeContext.get("canaryJudgeResultId");
Expand Down

0 comments on commit ca30f02

Please sign in to comment.