Skip to content

Commit

Permalink
Make mirror parse errors configurable
Browse files Browse the repository at this point in the history
Currently Tycho tests are quite unstable because it could happen that
mirrors list can't be processed and then an error occur in the logs what
make the test fail their "no errors".

But also as a user one might be annoyed to see errors because mirror
list can't be processed.

This adds a new static MIRROR_PARSE_ERROR_LEVEL filed to allow
configuration of the error level.
  • Loading branch information
laeubi committed Dec 16, 2023
1 parent ce7353e commit ba8f64a
Showing 1 changed file with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* IBM Corporation - initial API and implementation
* Cloudsmith Inc - bug fixes
Expand Down Expand Up @@ -36,15 +36,22 @@

/**
* Mirror support class for repositories. This class implements
* mirror support equivalent to the mirroring of update manager sites. A repository
* optionally provides a mirror URL via the {@link IRepository#PROP_MIRRORS_URL} key.
* The contents of the file at this URL is expected to be an XML document
* containing a list of <mirror> elements. The mirrors are assumed to be already
* mirror support equivalent to the mirroring of update manager sites. A repository
* optionally provides a mirror URL via the {@link IRepository#PROP_MIRRORS_URL} key.
* The contents of the file at this URL is expected to be an XML document
* containing a list of <mirror> elements. The mirrors are assumed to be already
* sorted geographically with closer mirrors first.
* <br><br>
* Always use {@link MirrorSelector.MirrorInfoComparator} for comparison.
*/
public class MirrorSelector {

/**
* Allows to globally control the level at what mirror errors are logged that
* originate from not being able to process mirror urls, the default is error.
*/
public static volatile int MIRROR_PARSE_ERROR_LEVEL = IStatus.ERROR;

private static final double LOG2 = Math.log(2);

/**
Expand Down Expand Up @@ -179,15 +186,15 @@ public MirrorSelector(IRepository<?> repository, Transport transport) {
* <pre>
* -> ->
* q * t (dot product)
* sim(q,t) = ---------------------------
* sim(q,t) = ---------------------------
* / || -> || || -> || \
* | || q || * || t || | (euclidean lengths)
* \ /
*
*
* N
* ---
* \
* > Q * T
* > Q * T
* / ai ai
* ---
* i = 1
Expand All @@ -199,7 +206,7 @@ public MirrorSelector(IRepository<?> repository, Transport transport) {
* | \ | > Q * \ | > T |
* | \| / ai \| / ai |
* | | --- | --- |
* \ | i = 1 | i = 1 /
* \ | i = 1 | i = 1 /
* </pre>
*/
public static final class MirrorInfoComparator implements Comparator<MirrorInfo> {
Expand All @@ -210,7 +217,7 @@ public static final class MirrorInfoComparator implements Comparator<MirrorInfo>
static final double WEIGHT_BYTESPERSECOND = 1d / 25000d;
/**
* This weight influences the failureCount classification
* Value was calculated by empirical tests.
* Value was calculated by empirical tests.
*/
static final double WEIGHT_FAILURECOUNT = 1.75d;

Expand Down Expand Up @@ -249,7 +256,7 @@ public int compare(MirrorInfo o1, MirrorInfo o2) {
/**
* Parses the given mirror URL to obtain the list of mirrors. Returns the mirrors,
* or null if mirrors could not be computed.
*
*
* Originally copied from DefaultSiteParser.getMirrors in org.eclipse.update.core
*/
private MirrorInfo[] computeMirrors(String mirrorsURL, IProgressMonitor monitor) {
Expand All @@ -275,7 +282,9 @@ private MirrorInfo[] computeMirrors(String mirrorsURL, IProgressMonitor monitor)
LogHelper.log(new Status(IStatus.WARNING, Activator.ID,
String.format("Mirrors URL %s was not found", mirrorsURL))); //$NON-NLS-1$
} else {
log("Error processing mirrors URL: " + mirrorsURL, e); //$NON-NLS-1$
LogHelper.log(
new Status(MIRROR_PARSE_ERROR_LEVEL, Activator.ID,
"Error processing mirrors URL: " + mirrorsURL, e)); //$NON-NLS-1$
}
}
return null;
Expand Down Expand Up @@ -322,7 +331,7 @@ private String enrichWithClientLocation(String baseURL) {
}

/**
* Returns an equivalent location for the given artifact location in the base
* Returns an equivalent location for the given artifact location in the base
* repository. Always falls back to the given input location in case of failure
* to compute mirrors. Never returns null.
*/
Expand Down Expand Up @@ -371,7 +380,7 @@ private MirrorInfoComparator getComparator() {
}

private void log(String message, Throwable exception) {
LogHelper.log(new Status(IStatus.ERROR, Activator.ID, message, exception));
LogHelper.log(new Status(MIRROR_PARSE_ERROR_LEVEL, Activator.ID, message, exception));
}

/**
Expand Down Expand Up @@ -409,7 +418,7 @@ public synchronized void reportResult(String toDownload, IStatus result) {
}
}

/**
/**
* Return whether or not all the mirrors for this selector have proven to be invalid
* @return whether or not there is a valid mirror in this selector.
*/
Expand Down Expand Up @@ -438,8 +447,8 @@ private MirrorInfo selectMirror(IProgressMonitor monitor) {
Arrays.sort(mirrors, getComparator());
for (;;) {
//this is a function that randomly selects a mirror based on a logarithmic
//distribution. Mirror 0 has a 1/2 chance of being selected, mirror 1 has a 1/4 chance,
// mirror 2 has a 1/8 chance, etc. This introduces some variation in the mirror
//distribution. Mirror 0 has a 1/2 chance of being selected, mirror 1 has a 1/4 chance,
// mirror 2 has a 1/8 chance, etc. This introduces some variation in the mirror
//selection, while still heavily favoring better mirrors
//the algorithm computes the most significant digit in a binary number by computing the base 2 logarithm
//if the first digit is most significant, mirror 0 is selected, if the second is most significant, mirror 1 is selected, etc
Expand Down

0 comments on commit ba8f64a

Please sign in to comment.