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

#126: Add Monitoring for IDE Urls Updater #584

Merged
merged 27 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
11ff6cd
Add implementation for Url Updater Report
alfeilex Sep 4, 2024
cac0c13
Remove UrlError Object that collects more information about failed ur…
alfeilex Sep 4, 2024
a59460c
Revert updater changes that were for testing purposes
alfeilex Sep 4, 2024
deab15a
Some refactoring
alfeilex Sep 4, 2024
a4449bb
Some refactoring
alfeilex Sep 4, 2024
b657471
Prevent NPE by init urlFinalReport attribute
alfeilex Sep 4, 2024
2dbde23
add @param to updateAll()
alfeilex Sep 4, 2024
7fe931c
add junit tests and some refactoring
alfeilex Sep 4, 2024
98ce6b6
Update update-urls.yml
alfeilex Sep 4, 2024
5257525
Update update-urls.yml
alfeilex Sep 4, 2024
7214414
Update update-urls.yml
alfeilex Sep 4, 2024
157bc92
Some refactor to output the report
alfeilex Sep 5, 2024
51b2772
Merge remote-tracking branch 'origin/error-report' into error-report
alfeilex Sep 5, 2024
d82063e
Some refactor to output the report
alfeilex Sep 5, 2024
db1b395
Update update-urls.yml
alfeilex Sep 5, 2024
f98dc3c
Some refactor to output the report
alfeilex Sep 5, 2024
e4d1202
Merge remote-tracking branch 'origin/error-report' into error-report
alfeilex Sep 5, 2024
55309d4
Revert update-urls.yml
alfeilex Sep 5, 2024
023225a
Merge branch 'main' into error-report
alfeilex Sep 5, 2024
caf45b6
Some refactor to output the report
alfeilex Sep 5, 2024
d2c8f06
Merge remote-tracking branch 'origin/error-report' into error-report
alfeilex Sep 5, 2024
1f31a46
Split test into smaller tests for better understaing
alfeilex Sep 5, 2024
6c3d605
Merge branch 'main' into error-report
alfeilex Sep 5, 2024
17d170d
Merge branch 'main' into error-report
hohwille Sep 6, 2024
5a96511
Update cli/src/main/java/com/devonfw/tools/ide/url/updater/AbstractPr…
hohwille Sep 6, 2024
b50fbd1
Update cli/src/main/java/com/devonfw/tools/ide/url/updater/AbstractPr…
hohwille Sep 6, 2024
2bba5ec
Merge branch 'main' into error-report
hohwille Sep 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions cli/src/main/java/com/devonfw/tools/ide/url/UpdateInitiator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.devonfw.tools.ide.url.model.report.UrlFinalReport;
import com.devonfw.tools.ide.url.updater.UpdateManager;

/**
Expand All @@ -18,8 +19,8 @@ public class UpdateInitiator {
private static final Logger logger = LoggerFactory.getLogger(UpdateInitiator.class.getName());

/**
* @param args the command-line arguments. arg[0] points to the {@code ide-urls} repository. arg[1] defines a timeout for GitHub actions in Duration string
* format.
* @param args the command-line arguments. arg[0] points to the {@code ide-urls} repository. arg[1] defines a timeout for GitHub actions in Duration
* string format.
*/
public static void main(String[] args) {

Expand Down Expand Up @@ -52,7 +53,11 @@ public static void main(String[] args) {
System.exit(1);
}

UpdateManager updateManager = new UpdateManager(repoPath, expirationTime);
UrlFinalReport urlFinalReport = new UrlFinalReport();

UpdateManager updateManager = new UpdateManager(repoPath, urlFinalReport, expirationTime);
updateManager.updateAll();

logger.info(urlFinalReport.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.devonfw.tools.ide.url.model.report;

import java.util.ArrayList;
import java.util.List;

/**
* Service to collect {@link UrlUpdaterReport} and finalize these after url updates have been completed.
*/
public class UrlFinalReport {

private ArrayList<UrlUpdaterReport> urlUpdaterReports = new ArrayList<UrlUpdaterReport>();

public List<UrlUpdaterReport> getUrlUpdaterReports() {
return this.urlUpdaterReports;
}

public void addUrlUpdaterReport(UrlUpdaterReport urlUpdaterReport) {

this.urlUpdaterReports.add(urlUpdaterReport);
}

/**
* @return «tool»/«edition»: versions added: 5 failed, 7 succeeded, 13 total, 38,4% error - versions verified: 0 failed, 0 succeeded, 0 total, 0% error
*/
@Override
public String toString() {
StringBuilder result = new StringBuilder("\nSTART OF FINAL URL UPDATER REPORT\n");
for (UrlUpdaterReport report : this.urlUpdaterReports) {
result.append(report.getTool()).append("/").append(report.getEdition()).append(" versions added: ").append(report.getAddVersionFailure())
.append(" failed, ").append(report.getAddVersionSuccess()).append(" succeeded, ").append(report.getTotalAdditions()).append(" total, ")
.append(String.format("%.2f", report.getErrorRateAdditions())).append("% error - versions verified: ").append(report.getVerificationFailure())
.append(" failed, ").append(report.getVerificationSuccess()).append(" succeeded, ").append(report.getTotalVerificitations()).append(" total, ")
.append(String.format("%.2f", report.getErrorRateVerificiations())).append("% error").append("\n");
}
result.append("END OF FINAL URL UPDATER REPORT\n");
return result.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.devonfw.tools.ide.url.model.report;

/**
* An instance of this class represent the result of updating a tool with specific url updater. It counts the number of successful and failed versions and
* verifications.
*/
public class UrlUpdaterReport {

private String tool;

private String edition;

protected int addVersionSuccess = 0;

protected int addVersionFailure = 0;

protected int verificationSuccess = 0;

protected int verificationFailure = 0;

/**
* The constructor.
*
* @param tool the name of the tool {@link #getTool() tool name}
* @param edition the name of edition of the tool {@link #getEdition()} can be the same as the tool name if no editions exist.
*/
public UrlUpdaterReport(String tool, String edition) {

this.tool = tool;
this.edition = edition;
}

public String getTool() {

return tool;
}

public void setTool(String tool) {

this.tool = tool;
}

public String getEdition() {

return edition;
}

public void setEdition(String edition) {

this.edition = edition;
}

public int getAddVersionSuccess() {

return addVersionSuccess;
}

public void incrementAddVersionSuccess() {

this.addVersionSuccess++;
}

public int getAddVersionFailure() {

return addVersionFailure;
}

public void incrementAddVersionFailure() {

this.addVersionFailure++;
}

public int getVerificationSuccess() {

return verificationSuccess;
}

public void incrementVerificationSuccess() {

this.verificationSuccess++;
}

public int getVerificationFailure() {

return verificationFailure;
}

public void incrementVerificationFailure() {

this.verificationFailure++;
}

public int getTotalAdditions() {

return this.addVersionFailure + this.addVersionSuccess;
}

public double getErrorRateAdditions() {

if (this.addVersionFailure > 0 && this.addVersionSuccess > 0) {

return ((double) this.addVersionFailure / getTotalAdditions()) * 100;
} else {

return 0;
}
}

public int getTotalVerificitations() {

return this.verificationFailure + this.verificationSuccess;
}

public double getErrorRateVerificiations() {

if (this.verificationSuccess > 0 && this.verificationFailure > 0) {
return ((double) this.verificationFailure / getTotalVerificitations()) * 100;
} else {

return 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.devonfw.tools.ide.url.model.report.UrlFinalReport;
import com.devonfw.tools.ide.url.model.report.UrlUpdaterReport;

/**
* Abstract base class for a processor that has a timeout and should cancel if the timeout is expired.
*/
Expand All @@ -15,6 +18,12 @@ public abstract class AbstractProcessorWithTimeout {
/** The {@link Instant} expiration time for the GitHub actions url-update job */
private Instant expirationTime;

/** The {@link UrlFinalReport} final report of url updates for monitoring */
private UrlFinalReport urlFinalReport;

/** The {@link UrlUpdaterReport} report instance to track data for the {@link UrlFinalReport} */
private UrlUpdaterReport urlUpdaterReport;

/**
* @param expirationTime to set for the GitHub actions url-update job
*/
Expand All @@ -31,6 +40,41 @@ public Instant getExpirationTime() {
return this.expirationTime;
}

/**
* @param urlFinalReport to collect {@link UrlUpdaterReport} instances for final output of reports. The init happens in UpdateInitiator.class.
*/
public void setUrlFinalReport(UrlFinalReport urlFinalReport) {

this.urlFinalReport = urlFinalReport;
}

/**
* @return the {@link UrlFinalReport} representing the final report
*/
public UrlFinalReport getUrlFinalReport() {

if (this.urlFinalReport == null) {
this.urlFinalReport = new UrlFinalReport();
}
return this.urlFinalReport;
}

/**
* @param urlUpdaterReport to collect information during url updating process
*/
public void setUrlUpdaterReport(UrlUpdaterReport urlUpdaterReport) {

this.urlUpdaterReport = urlUpdaterReport;
}

/**
* @return the {@link UrlUpdaterReport} representing the report instance to collect failures successes
*/
public UrlUpdaterReport getUrlUpdaterReport() {

return urlUpdaterReport;
}

/**
* Checks if the timeout was expired.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.devonfw.tools.ide.url.model.folder.UrlRepository;
import com.devonfw.tools.ide.url.model.folder.UrlTool;
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
import com.devonfw.tools.ide.url.model.report.UrlUpdaterReport;
import com.devonfw.tools.ide.util.DateTimeUtil;
import com.devonfw.tools.ide.util.HexUtil;

Expand Down Expand Up @@ -524,6 +525,7 @@ private void doUpdateStatusJson(boolean success, int statusCode, String edition,

logger.info("For tool {} and version {} the download verification succeeded with status code {} for URL {}.", tool,
version, code, url);
getUrlUpdaterReport().incrementVerificationSuccess();
} else {
if (status != null) {
if (errorStatus == null) {
Expand All @@ -549,6 +551,7 @@ private void doUpdateStatusJson(boolean success, int statusCode, String edition,
}
logger.warn("For tool {} and version {} the download verification failed with status code {} for URL {}.", tool,
version, code, url);
getUrlUpdaterReport().incrementVerificationFailure();
}
if (modified) {
urlStatusFile.setStatusJson(statusJson); // hack to set modified (better solution welcome)
Expand Down Expand Up @@ -602,6 +605,7 @@ public void update(UrlRepository urlRepository) {
UrlTool tool = urlRepository.getOrCreateChild(getTool());
for (String edition : getEditions()) {
UrlEdition urlEdition = tool.getOrCreateChild(edition);
setUrlUpdaterReport(new UrlUpdaterReport(tool.getName(), urlEdition.getName()));
updateExistingVersions(urlEdition);
Set<String> versions = getVersions();
String toolWithEdition = getToolWithEdition(edition);
Expand All @@ -619,11 +623,15 @@ public void update(UrlRepository urlRepository) {
urlVersion = urlEdition.getOrCreateChild(version);
addVersion(urlVersion);
urlVersion.save();
getUrlUpdaterReport().incrementAddVersionSuccess();
logger.info("For tool {} we add version {}.", toolWithEdition, version);
} catch (Exception e) {
logger.error("For tool {} we failed to add version {}.", toolWithEdition, version, e);
getUrlUpdaterReport().incrementAddVersionFailure();
}
}
}
getUrlFinalReport().addUrlUpdaterReport(getUrlUpdaterReport());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.devonfw.tools.ide.url.model.folder.UrlRepository;
import com.devonfw.tools.ide.url.model.folder.UrlTool;
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
import com.devonfw.tools.ide.url.model.report.UrlUpdaterReport;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

Expand Down Expand Up @@ -42,10 +43,12 @@ public void update(UrlRepository urlRepository) {
J jsonObj = getJsonObjectFromResponse(response, edition);
if (jsonObj != null) {
UrlEdition urlEdition = tool.getOrCreateChild(edition);
setUrlUpdaterReport(new UrlUpdaterReport(tool.getName(), urlEdition.getName()));
updateExistingVersions(urlEdition);
collectVersionsWithDownloadsFromJson(jsonObj, urlEdition);
}
}
getUrlFinalReport().addUrlUpdaterReport(getUrlUpdaterReport());
} catch (Exception e) {
throw new IllegalStateException("Error while getting versions from JSON API " + doGetVersionUrl(), e);
}
Expand Down
Loading
Loading