Skip to content

Commit

Permalink
hawkbit-ddi-resource: do not log range requests
Browse files Browse the repository at this point in the history
HawkBit creates ActionStatus entries for each GET request associated with an
artifact of an assigned software module. Amongst others, this severely breaks
RAUC block-based adaptive updates [1], which issue a flurry of range requests
for small chunks, so that the whole image does not have to be streamed in case
of incremental system changes.

[1] https://rauc.readthedocs.io/en/latest/advanced.html#block-based-adaptive-update-block-hash-index

Fixes: eclipse-hawkbit#1249

Signed-off-by: Zygmunt Krynicki <[email protected]>
  • Loading branch information
zyga committed Sep 28, 2023
1 parent 5eb84cb commit db29afd
Showing 1 changed file with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,38 +201,36 @@ public ResponseEntity<InputStream> downloadArtifact(@PathVariable("tenant") fina
if (ifMatch != null && !HttpUtil.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
result = new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
} else {
final ActionStatus action = checkAndLogDownload(requestResponseContextHolder.getHttpServletRequest(),
final ActionStatus maybeAction = checkAndMaybeLogDownload(requestResponseContextHolder.getHttpServletRequest(),
target, module.getId());

final Long statusId = action.getId();

result = FileStreamingUtil.writeFileResponse(file, artifact.getFilename(), artifact.getCreatedAt(),
requestResponseContextHolder.getHttpServletResponse(),
requestResponseContextHolder.getHttpServletRequest(),
(length, shippedSinceLastEvent,
total) -> eventPublisher.publishEvent(new DownloadProgressEvent(
tenantAware.getCurrentTenant(), statusId, shippedSinceLastEvent,
serviceMatcher != null ? serviceMatcher.getBusId() : bus.getId())));

(length, shippedSinceLastEvent, total) -> {
if (maybeAction != null) {
eventPublisher.publishEvent(new DownloadProgressEvent(
tenantAware.getCurrentTenant(), maybeAction.getId(), shippedSinceLastEvent,
serviceMatcher != null ? serviceMatcher.getBusId() : bus.getId()));
}
});
}
}
return result;
}

private ActionStatus checkAndLogDownload(final HttpServletRequest request, final Target target, final Long module) {
private ActionStatus checkAndMaybeLogDownload(final HttpServletRequest request, final Target target, final Long module) {
final Action action = controllerManagement
.getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), module)
.orElseThrow(() -> new SoftwareModuleNotAssignedToTargetException(module, target.getControllerId()));
final String range = request.getHeader("Range");

final String message;
// Logging range requests is pointless as there can be arbitrarily many of them.
final String range = request.getHeader("Range");
if (range != null) {
message = RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: "
+ request.getRequestURI();
} else {
message = RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI();
return null;
}

final String message = RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI();
return controllerManagement.addInformationalActionStatus(
entityFactory.actionStatus().create(action.getId()).status(Status.DOWNLOAD).message(message));
}
Expand Down Expand Up @@ -262,7 +260,7 @@ public ResponseEntity<Void> downloadArtifactMd5(@PathVariable("tenant") final St
final Artifact artifact = module.getArtifactByFilename(fileName)
.orElseThrow(() -> new EntityNotFoundException(Artifact.class, fileName));

checkAndLogDownload(requestResponseContextHolder.getHttpServletRequest(), target, module.getId());
checkAndMaybeLogDownload(requestResponseContextHolder.getHttpServletRequest(), target, module.getId());

try {
FileStreamingUtil.writeMD5FileResponse(requestResponseContextHolder.getHttpServletResponse(),
Expand Down

0 comments on commit db29afd

Please sign in to comment.