-
Notifications
You must be signed in to change notification settings - Fork 202
Distinguish cache hits from real downloads in p2 transport log #5971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 Lars Vogel and others. | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| *******************************************************************************/ | ||
| package org.eclipse.tycho.p2maven.transport; | ||
|
|
||
| /** | ||
| * Describes the outcome of a {@link HttpCache} access, so that callers can | ||
| * produce accurate log output (e.g. distinguish "Downloading" from "Fetched | ||
| * from cache"). | ||
| */ | ||
| public enum CacheState { | ||
| /** The file was served from the local cache without any network access. */ | ||
| FROM_CACHE, | ||
| /** A conditional request was performed and the server answered 304 Not Modified. */ | ||
| NOT_MODIFIED, | ||
| /** The file was downloaded (full 2xx response with body). */ | ||
| DOWNLOADED, | ||
| /** No information available (e.g. non-HTTP transport or not yet accessed). */ | ||
| UNKNOWN | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,9 @@ public Thread newThread(Runnable r) { | |
| @Requirement | ||
| TransportCacheConfig cacheConfig; | ||
|
|
||
| @Requirement | ||
| HttpCache httpCache; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not bind directly to a specific cache implementation there might be other caching techniques see comment below. |
||
|
|
||
| @Requirement(role = TransportProtocolHandler.class) | ||
| Map<String, TransportProtocolHandler> transportProtocolHandlers; | ||
|
|
||
|
|
@@ -108,18 +111,18 @@ public IStatus downloadArtifact(URI source, OutputStream target, IArtifactDescri | |
| } | ||
| } | ||
| String id = "p2"; // TODO we might compute the id from the IRepositoryIdManager based on the URI? | ||
| if (cacheConfig.isInteractive()) { | ||
| logger.info("Downloading from " + id + ": " + source); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This log message should remain to stay consistent with how maven works and to know that the download has started. |
||
| try { | ||
| DownloadStatusOutputStream statusOutputStream = new DownloadStatusOutputStream(target, | ||
| "Download of " + source); | ||
| stream(source, monitor).transferTo(statusOutputStream); | ||
| DownloadStatus downloadStatus = statusOutputStream.getStatus(); | ||
| if (cacheConfig.isInteractive()) { | ||
| logger.info("Downloaded from " + id + ": " + source + " (" | ||
| + FileUtils.byteCountToDisplaySize(downloadStatus.getFileSize()) + " at " | ||
| + FileUtils.byteCountToDisplaySize(downloadStatus.getTransferRate()) + "/s)"); | ||
| CacheState state = httpCache.getLastCacheState(source); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using a side-car approach here, the information should be transported through the |
||
| if (state == CacheState.DOWNLOADED || state == CacheState.UNKNOWN) { | ||
| logger.info("Downloaded from " + id + ": " + source + " (" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The info should always be logged and we should just replace the transfer rate by a status e.g. Downloaded from " + id + ": " + source + " (" |
||
| + FileUtils.byteCountToDisplaySize(downloadStatus.getFileSize()) + " at " | ||
| + FileUtils.byteCountToDisplaySize(downloadStatus.getTransferRate()) + "/s)"); | ||
| } | ||
| } | ||
| return reportStatus(downloadStatus, target); | ||
| } catch (AuthenticationFailedException e) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please think about better naming here that is independent from caching and agnostic from the transport technique. e.g. we also have ftp transports that have no meaning of (http) status codes.