From db29afd7d8b1539c7346430a6fa5c5e9be95117f Mon Sep 17 00:00:00 2001 From: Zygmunt Krynicki Date: Thu, 28 Sep 2023 15:27:54 +0200 Subject: [PATCH] hawkbit-ddi-resource: do not log range requests 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: https://github.com/eclipse/hawkbit/issues/1249 Signed-off-by: Zygmunt Krynicki --- .../ddi/rest/resource/DdiRootController.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/hawkbit-rest/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-rest/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java index 0801e5d59c..088b809405 100644 --- a/hawkbit-rest/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java +++ b/hawkbit-rest/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java @@ -201,38 +201,36 @@ public ResponseEntity 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)); } @@ -262,7 +260,7 @@ public ResponseEntity 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(),