Skip to content

Commit

Permalink
improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoika committed Jun 9, 2023
1 parent 9679d05 commit 580bc6a
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 45 deletions.
2 changes: 0 additions & 2 deletions imixs-archive-backup/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>

<org.imixs.workflow.version>6.0.1</org.imixs.workflow.version>
<org.imixs.melman.version>2.0.0</org.imixs.melman.version>
<org.imixs.jwt.version>1.0.3</org.imixs.jwt.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import java.io.Serializable;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
import java.util.SortedMap;
import java.util.logging.Logger;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.metrics.Counter;
import org.eclipse.microprofile.metrics.MetricID;
import org.eclipse.microprofile.metrics.MetricRegistry;
import org.eclipse.microprofile.metrics.annotation.RegistryType;
import org.imixs.archive.util.LogController;

import jakarta.enterprise.context.RequestScoped;
Expand Down Expand Up @@ -55,6 +61,10 @@ public class ExportController implements Serializable {
@ConfigProperty(name = ExportApi.WORKFLOW_SYNC_INTERVAL, defaultValue = "1000")
long interval;

@Inject
@RegistryType(type = MetricRegistry.Type.APPLICATION)
MetricRegistry metricRegistry;

@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(ExportController.class.getName());

Expand Down Expand Up @@ -131,4 +141,25 @@ public void stop() {
}
}

/**
* This method returns the current event processing counter
*
* @return
*/
public long getCounterByName(String name) {

// find counter by name
SortedMap<MetricID, Counter> allCounters = metricRegistry.getCounters();

for (Map.Entry<MetricID, Counter> entry : allCounters.entrySet()) {

MetricID metricID = entry.getKey();
if (metricID.getName().endsWith(name)) {
return entry.getValue().getCount();
}
}
logger.warning("Metric Counter : " + name + " not found!");
return 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import java.util.logging.Logger;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.metrics.MetricRegistry;
import org.eclipse.microprofile.metrics.annotation.Counted;
import org.eclipse.microprofile.metrics.annotation.RegistryType;
import org.imixs.archive.util.FTPConnector;
import org.imixs.archive.util.LogController;
import org.imixs.archive.util.RestClientHelper;
Expand All @@ -52,8 +54,8 @@

/**
* The ExportService exports the workflow data from a Imixs-Workflow instance
* into a FTP storage. The service class runs a TimerService based on the given
* scheduler configuration.
* into a FTP storage. The service class runs a non-persistent TimerService
* based on the given scheduler configuration.
* <p>
* The service automatically starts during deployment.
* <p>
Expand Down Expand Up @@ -122,6 +124,10 @@ public class ExportService {
@Inject
ExportStatusHandler exportStatusHandler;

@Inject
@RegistryType(type = MetricRegistry.Type.APPLICATION)
MetricRegistry metricRegistry;

@PostConstruct
public void init() {
// init timer....
Expand Down Expand Up @@ -158,27 +164,24 @@ public void onTimeout(jakarta.ejb.Timer _timer) {
int total = 0;
int success = 0;
int errors = 0;

logger.info("onTimeout...");

exportStatusHandler.setTimer(_timer);

// init rest clients....
DocumentClient documentClient = restClientHelper.getDocumentClient();
EventLogClient eventLogClient = restClientHelper.getEventLogClient(documentClient);
if (documentClient == null || eventLogClient == null) {
logController.warning(ExportApi.TOPIC_EXPORT,
"Unable to connect to workflow instance endpoint - please verify configuration!");
try {
stopScheduler();
} catch (ExportException e) {
try {
// init rest clients....
DocumentClient documentClient = restClientHelper.getDocumentClient();
EventLogClient eventLogClient = restClientHelper.getEventLogClient(documentClient);
if (documentClient == null || eventLogClient == null) {
logController.warning(ExportApi.TOPIC_EXPORT,
"Unable to connect to workflow instance endpoint - please verify configuration!");
try {
stopScheduler();
} catch (ExportException e) {
}
metricRegistry.counter("errors").inc();
return;
}
return;
}

exportStatusHandler.setStatus(ExportStatusHandler.STATUS_RUNNING);
exportStatusHandler.setStatus(ExportStatusHandler.STATUS_RUNNING);

try {
logger.finest("......release dead locks....");
// release dead locks...
releaseDeadLocks(eventLogClient);
Expand Down Expand Up @@ -224,15 +227,8 @@ public void onTimeout(jakarta.ejb.Timer _timer) {
exportStatusHandler.setStatus(ExportStatusHandler.STATUS_SCHEDULED);

} catch (InvalidAccessException | EJBException | RestAPIException e) {
// In case of a exception during processing the event log
// the timer service will automatically restarted. This is important
// to resolve restarts of the workflow engine.
logController.warning(ExportApi.TOPIC_EXPORT, "processsing EventLog failed: " + e.getMessage());
try {
restartScheduler();
} catch (ExportException e1) {
logController.warning(ExportApi.TOPIC_EXPORT, "Failed to restart export scheduler: " + e.getMessage());
}
logController.severe(ExportApi.TOPIC_EXPORT, "processing EventLog failed: " + e.getMessage());
metricRegistry.counter("org_imixs_archive_export_errors").inc();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package org.imixs.archive.export;

import java.util.Date;
import java.util.logging.Logger;

import jakarta.ejb.Singleton;
import jakarta.ejb.Timer;
Expand All @@ -42,6 +43,8 @@ public class ExportStatusHandler {
public static final String STATUS_SCHEDULED = "SCHEDULED";
public static final String STATUS_CANCELED = "CANCELED";

private static Logger logger = Logger.getLogger(ExportStatusHandler.class.getName());

private String status = "";
private Timer timer = null;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.imixs.archive.export;

import java.util.Map;
import java.util.SortedMap;

import org.eclipse.microprofile.metrics.Counter;
import org.eclipse.microprofile.metrics.MetricID;
import org.eclipse.microprofile.metrics.MetricRegistry;
import org.eclipse.microprofile.metrics.annotation.Counted;
import org.eclipse.microprofile.metrics.annotation.RegistryType;
Expand Down Expand Up @@ -41,8 +45,21 @@ public String ping() {
public String count() {
System.out.println("Test P1");

Counter http200Count = metricRegistry.counter("http200Count");
System.out.println("Test P2");
SortedMap<MetricID, Counter> allCounters = metricRegistry.getCounters();

for (Map.Entry<MetricID, Counter> entry : allCounters.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue());

MetricID meti = entry.getKey();

Counter ding = entry.getValue();
System.out.println(" coutner wert=" + ding.getCount() + " metric name " + meti.getName());

}

// pingCount = metricRegistry.getCounter("exportPing");

System.out.println("Test Ping count=");

// SortedMap<MetricID, Counter> counters = metricRegistry.getCounters();
// Counter counter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class LogController implements Serializable {

public static final int LOG_INFO = 1;
public static final int LOG_WARNING = 2;
public static final int LOG_ERROR = 3;

private static Logger logger = Logger.getLogger(LogController.class.getName());
String pattern = " HH:mm:ss.SSSZ";
Expand Down Expand Up @@ -57,6 +58,10 @@ public void warning(String context, String message) {
add(context, LOG_WARNING, message);
}

public void severe(String context, String message) {
add(context, LOG_ERROR, message);
}

/**
* Logs a new message to the message log
*
Expand All @@ -75,7 +80,10 @@ private void add(String topic, int type, String message) {
}

String entry = simpleDateFormat.format(new Date()) + " ";
if (type == LOG_WARNING) {
if (type == LOG_ERROR) {
entry = entry + "[ERROR] ";
logger.severe(message);
} else if (type == LOG_WARNING) {
entry = entry + "[WARNING] ";
logger.warning(message);
} else {
Expand All @@ -91,8 +99,4 @@ public List<String> getLogEntries(String context) {
return logTopics.get(context);
}

// public void setLogEntries(List<String> logEntries) {
// this.logEntries = logEntries;
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.imixs.melman.EventLogClient;
import org.imixs.melman.FormAuthenticator;
import org.imixs.melman.JWTAuthenticator;
import org.imixs.melman.RestAPIException;
import org.imixs.melman.WorkflowClient;

import jakarta.enterprise.context.RequestScoped;
Expand Down Expand Up @@ -53,8 +54,9 @@ public class RestClientHelper implements Serializable {
* This method creates a new WorkflowClient instance.
*
* @return
* @throws RestAPIException
*/
public DocumentClient getDocumentClient() {
public DocumentClient getDocumentClient() throws RestAPIException {

DocumentClient documentClient = null;
if (instanceEndpoint.isPresent()) {
Expand Down
12 changes: 5 additions & 7 deletions imixs-archive-exporter/src/main/webapp/index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<section class="" style="">
<div class="card" style="grid-column-start: span 12;min-height: 0px;">
<h1 style="line-height: 0;">
<span class="typcn typcn-cloud-storage-outline"></span> Imixs Export
<span class="typcn typcn-cloud-storage-outline"></span> Imixs Export Service
</h1>
</div>
</section>
Expand Down Expand Up @@ -96,22 +96,20 @@
<div class="card" style="grid-column-start: span 7;">

<h1 class="lead">
14 Events
#{exportController.getCounterByName('eventProcessed')} Events
</h1>
<p class="lead">
Imixs-Office-Workflow is a production ready Business Process
Management Suite. It's easy to use.</p>
Number of processed export events since last start.</p>



</div>
<div class="card" style="grid-column-start: span 5;">
<h1 class="lead">
0 Errors
<span style="#{(exportController.getCounterByName('errors')>0)?'color: #e84848;':''}">#{exportController.getCounterByName('errors')} Errors</span>
</h1>
<p class="lead">
Imixs-Office-Workflow is a production ready Business Process
Management Suite. It's easy to use.</p>
Number of processed export errors since last start.</p>

</div>
</section>
Expand Down

0 comments on commit 580bc6a

Please sign in to comment.