Skip to content
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

Add ResolutionEventListener#downloadMetadataSuccess to communicate long download times to consumers of MavenPomDownloader #4566

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;

@SuppressWarnings("OptionalAssignedToNull")
public class MavenPomDownloader {
private static final RetryPolicy<Object> retryPolicy = RetryPolicy.builder()
.handle(SocketTimeoutException.class, TimeoutException.class)
Expand Down Expand Up @@ -333,7 +332,8 @@ public MavenMetadata downloadMetadata(GroupArtifactVersion gav, @Nullable Resolv
.setRepositoryResponses(repositoryResponses);
}

sample.stop(timer.tags("outcome", "success").register(Metrics.globalRegistry));
long nanos = sample.stop(timer.tags("outcome", "success").register(Metrics.globalRegistry));
ctx.getResolutionListener().downloadMetadataSuccess(mavenMetadata, containingPom, Duration.ofNanos(nanos));
return mavenMetadata;
}

Expand Down Expand Up @@ -580,7 +580,7 @@ public Pom download(GroupArtifactVersion gav,
pom = pom.withGav(pom.getGav().withDatedSnapshotVersion(versionMaybeDatedSnapshot));
}
mavenCache.putPom(resolvedGav, pom);
ctx.getResolutionListener().downloadSuccess(resolvedGav, containingPom);
ctx.getResolutionListener().downloadSuccess(resolvedGav, containingPom, Duration.ZERO);
sample.stop(timer.tags("outcome", "from maven local").register(Metrics.globalRegistry));
return pom;
}
Expand All @@ -602,8 +602,9 @@ public Pom download(GroupArtifactVersion gav,
pom = pom.withGav(pom.getGav().withDatedSnapshotVersion(versionMaybeDatedSnapshot));
}
mavenCache.putPom(resolvedGav, pom);
ctx.getResolutionListener().downloadSuccess(resolvedGav, containingPom);
sample.stop(timer.tags("outcome", "downloaded").register(Metrics.globalRegistry));
long nanos = sample.stop(timer.tags("outcome", "downloaded").register(Metrics.globalRegistry));
ctx.getResolutionListener()
.downloadSuccess(resolvedGav, containingPom, Duration.ofNanos(nanos));
Comment on lines +606 to +607
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the old, durationless event type still exists but will now never be called? That isn't great. If the old event is still going to exist it should continue to be called.

Copy link
Contributor Author

@bryceatmoderne bryceatmoderne Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to remove the old event under the assumption only Moderne is consumers of it. Thoughts?

return pom;
} catch (HttpSenderResponseException e) {
repositoryResponses.put(repo, e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.jspecify.annotations.Nullable;

import java.time.Duration;
import java.util.List;

@SuppressWarnings("unused")
Expand All @@ -33,9 +34,15 @@ default void downloadMetadata(GroupArtifactVersion gav) {
default void download(GroupArtifactVersion gav) {
}

default void downloadMetadataSuccess(MavenMetadata mavenMetadata, @Nullable ResolvedPom containing, Duration duration) {
}

default void downloadSuccess(ResolvedGroupArtifactVersion gav, @Nullable ResolvedPom containing) {
}

default void downloadSuccess(ResolvedGroupArtifactVersion gav, @Nullable ResolvedPom containing, Duration duration) {
}

/**
* @param gav - GAV coordinate of the dependency which failed to download
* @param attemptedUris - The URIs which were attempted, in the order they were attempted, before resolution was determined to have failed
Expand Down