-
Notifications
You must be signed in to change notification settings - Fork 30
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
#126: Monitoring for ide-urls #160
Changes from 10 commits
af9910e
a1e90ed
8c5b0c9
fd59fa5
3e23ec0
4ee4271
f6baefa
0719028
9d73cc1
438e695
f24262f
08f42ef
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,50 @@ | ||
package com.devonfw.tools.ide.url.model; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Class that outputs a report for all {@link UrlErrorState} after url updated | ||
*/ | ||
public class UrlErrorReport { | ||
alfeilex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private static final UrlErrorReport instance = new UrlErrorReport(); | ||
|
||
private static UrlErrorReport getInstance() { | ||
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. why do we need to make all this static? |
||
return instance; | ||
} | ||
|
||
public static List<UrlErrorState> urlErrorStates = new ArrayList<>(); | ||
|
||
private static UrlErrorState addErrorState(String toolWithEdition) { | ||
UrlErrorState state = new UrlErrorState(toolWithEdition); | ||
urlErrorStates.add(state); | ||
return state; | ||
} | ||
|
||
public static UrlErrorState getErrorState(String toolWithEdition) { | ||
if (!urlErrorStates.isEmpty()) { | ||
for (UrlErrorState state : urlErrorStates) { | ||
if (state.getToolWithEdition().equals(toolWithEdition)) { | ||
return state; | ||
} else { | ||
return addErrorState(toolWithEdition); | ||
} | ||
} | ||
} else { | ||
return addErrorState(toolWithEdition); | ||
} | ||
return null; | ||
} | ||
|
||
public static String getReport() { | ||
StringBuilder report = new StringBuilder(); | ||
report.append("\nERROR REPORT FROM: ").append(LocalDateTime.now()).append("\n"); | ||
for (UrlErrorState state : urlErrorStates) { | ||
report.append(state.toString()).append("\n"); | ||
} | ||
report.append("ERROR REPORT ENDS").append("\n"); | ||
return report.toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.devonfw.tools.ide.url.model; | ||
|
||
/** | ||
* Class that collects the number of successful or failed additions and verifications of tools with editions and calculates the error rate when updating urls. | ||
*/ | ||
public final class UrlErrorState { | ||
alfeilex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final String toolWithEdition; | ||
private int additionSuccesses; | ||
private int additionFailures; | ||
private int verificationSuccesses; | ||
private int verificationFailures; | ||
|
||
public UrlErrorState(String toolWithEdition) { | ||
|
||
this.toolWithEdition = toolWithEdition; | ||
this.additionSuccesses = 0; | ||
this.additionFailures = 0; | ||
this.verificationSuccesses = 0; | ||
this.verificationFailures = 0; | ||
} | ||
|
||
public String getToolWithEdition() { | ||
|
||
return toolWithEdition; | ||
} | ||
|
||
public int getAdditionSuccesses() { | ||
|
||
return additionSuccesses; | ||
} | ||
|
||
public void setAdditionSuccesses(int additionSuccesses) { | ||
|
||
this.additionSuccesses = additionSuccesses; | ||
} | ||
|
||
public int getAdditionFailures() { | ||
|
||
return additionFailures; | ||
} | ||
|
||
public void setAdditionFailures(int additionFailures) { | ||
|
||
this.additionFailures = additionFailures; | ||
} | ||
|
||
public int getVerificationSuccesses() { | ||
|
||
return verificationSuccesses; | ||
} | ||
|
||
public void setVerificationSuccesses(int verificationSuccesses) { | ||
|
||
this.verificationSuccesses = verificationSuccesses; | ||
} | ||
|
||
public int getVerificationFailures() { | ||
|
||
return verificationFailures; | ||
} | ||
|
||
public void setVerificationFailures(int verificationFailures) { | ||
|
||
this.verificationFailures = verificationFailures; | ||
} | ||
|
||
private int getTotalAdditions() { | ||
return this.additionFailures + this.additionSuccesses; | ||
} | ||
|
||
private int getTotalVerification() { | ||
return this.verificationFailures + this.verificationSuccesses; | ||
} | ||
|
||
private String getErrorRate(int failures, int totals) { | ||
if (failures == 0) { | ||
return "0.00"; | ||
} else { | ||
double errorRate = (double) failures / totals * 100; | ||
return String.format("%.2f", errorRate); | ||
} | ||
} | ||
|
||
public void updateAdditions(boolean success) { | ||
if (success) { | ||
this.additionSuccesses += 1; | ||
} else { | ||
this.additionFailures += 1; | ||
} | ||
} | ||
|
||
public void updateVerifications(boolean success) { | ||
if (success) { | ||
this.verificationSuccesses += 1; | ||
} else { | ||
this.verificationFailures += 1; | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
|
||
String additionState = "versions added: " + getAdditionFailures() + " failed, " + getAdditionSuccesses() + " succeeded, " | ||
+ getTotalAdditions() + " total, " + getErrorRate(getAdditionFailures(), getTotalAdditions()) + "% error"; | ||
|
||
String verificationState = " - versions verified: " + getVerificationFailures() + " failed, " + getVerificationSuccesses() + | ||
" succeeded, " + getTotalVerification() + " total, " + getErrorRate(getVerificationFailures(), getTotalVerification()) + "% error"; | ||
|
||
return getToolWithEdition() + ": " + additionState + verificationState; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
|
||
import com.devonfw.tools.ide.os.OperatingSystem; | ||
import com.devonfw.tools.ide.os.SystemArchitecture; | ||
import com.devonfw.tools.ide.url.model.UrlErrorReport; | ||
import com.devonfw.tools.ide.url.model.UrlErrorState; | ||
import com.devonfw.tools.ide.url.model.file.UrlChecksum; | ||
import com.devonfw.tools.ide.url.model.file.UrlDownloadFile; | ||
import com.devonfw.tools.ide.url.model.file.UrlFile; | ||
|
@@ -70,6 +72,9 @@ public abstract class AbstractUrlUpdater extends AbstractProcessorWithTimeout im | |
|
||
private static final Logger logger = LoggerFactory.getLogger(AbstractUrlUpdater.class); | ||
|
||
protected UrlErrorState urlErrorState = UrlErrorReport.getErrorState(getToolWithEdition()); | ||
|
||
|
||
/** | ||
* @return the name of the {@link UrlTool tool} handled by this updater. | ||
*/ | ||
|
@@ -440,6 +445,9 @@ private void doUpdateStatusJson(boolean success, int statusCode, UrlVersion urlV | |
|
||
logger.info("For tool {} and version {} the download verification succeeded with status code {} for URL {}.", tool, | ||
version, code, url); | ||
|
||
urlErrorState.updateVerifications(true); | ||
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 need probably another place for this function. Currently, I have commented out |
||
|
||
} else { | ||
if (status != null) { | ||
if (errorStatus == null) { | ||
|
@@ -465,6 +473,8 @@ private void doUpdateStatusJson(boolean success, int statusCode, UrlVersion urlV | |
} | ||
logger.warn("For tool {} and version {} the download verification failed with status code {} for URL {}.", tool, | ||
version, code, url); | ||
|
||
urlErrorState.updateVerifications(false); | ||
} | ||
if (modified) { | ||
urlStatusFile.setStatusJson(statusJson); // hack to set modified (better solution welcome) | ||
|
@@ -517,7 +527,7 @@ public void update(UrlRepository urlRepository) { | |
|
||
UrlTool tool = urlRepository.getOrCreateChild(getTool()); | ||
UrlEdition edition = tool.getOrCreateChild(getEdition()); | ||
updateExistingVersions(edition); | ||
//updateExistingVersions(edition); | ||
Set<String> versions = getVersions(); | ||
String toolWithEdition = getToolWithEdition(); | ||
logger.info("For tool {} we found the following versions : {}", toolWithEdition, versions); | ||
|
@@ -534,8 +544,10 @@ public void update(UrlRepository urlRepository) { | |
urlVersion = edition.getOrCreateChild(version); | ||
addVersion(urlVersion); | ||
urlVersion.save(); | ||
urlErrorState.updateAdditions(true); | ||
} catch (Exception e) { | ||
logger.error("For tool {} we failed to add version {}.", toolWithEdition, version, e); | ||
urlErrorState.updateAdditions(false); | ||
} | ||
} | ||
} | ||
|
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.
If we have Java to collect all the
errorReport
, then why can't this directly print the report at the endinstead of writing all logs to disc and then dosed
magic filtering theerror report
out of the log that we have produced ourselves in Java in a structured way and print it viacat
?