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 new metrics #3446

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 13 additions & 12 deletions core/src/main/java/org/mapfish/print/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
import ch.qos.logback.core.util.StatusPrinter2;
import com.google.common.annotations.VisibleForTesting;
import com.sampullara.cli.Args;
import java.io.File;
Expand Down Expand Up @@ -58,7 +58,6 @@ private Main() {
* Main method.
*
* @param args the cli arguments
* @throws Exception
*/
public static void main(final String[] args) throws Exception {
runMain(args);
Expand All @@ -69,7 +68,6 @@ public static void main(final String[] args) throws Exception {
* Runs the print.
*
* @param args the cli arguments
* @throws Exception
*/
@VisibleForTesting
public static void runMain(final String[] args) throws Exception {
Expand Down Expand Up @@ -133,17 +131,20 @@ private static void configureLogs(final String verbose) {
case LOGLEVEL_INFO:
logfile = classLoader.getResource("shell-info-log.xml");
break;
case LOGLEVEL_DEFAULT:
logfile = classLoader.getResource("shell-default-log.xml");
break;
case LOGLEVEL_VERBOSE:
logfile = classLoader.getResource("shell-verbose-log.xml");
break;
case LOGLEVEL_DEFAULT:
default:
logfile = classLoader.getResource("shell-default-log.xml");
break;
}

LoggerContext loggerContext = getLoggerContext(logfile);
new StatusPrinter2().printInCaseOfErrorsOrWarnings(loggerContext);
}

private static LoggerContext getLoggerContext(final URL logfile) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

try {
Expand All @@ -156,15 +157,15 @@ private static void configureLogs(final String verbose) {
} catch (JoranException je) {
// StatusPrinter will handle this
}
StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
return loggerContext;
}

/**
* Instead of calling system.exit an exception will be thrown. This is useful for testing so a
* test won't shutdown jvm.
* Instead of calling System.exit() an exception will be thrown. This is useful for testing so a
* test won't shut down the jvm.
*
* @param exceptionOnFailure if true then an exception will be thrown instead of system.exit being
* called.
* @param exceptionOnFailure if true then an exception will be thrown instead of System.exit()
* being called.
*/
@VisibleForTesting
static void setExceptionOnFailure(final boolean exceptionOnFailure) {
Expand Down Expand Up @@ -197,7 +198,7 @@ private void run(final CliDefinition cli) throws Exception {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Request Data: \n{}", jsonSpec.getInternalObj().toString(2));
}
this.mapPrinter.print(new HashMap<String, String>(), jsonSpec, outFile);
this.mapPrinter.print(new HashMap<>(), jsonSpec, outFile);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final class JasperReportBuilder extends AbstractProcessor<JasperReportBui
@Autowired private WorkingDirectories workingDirectories;

/** Constructor. */
protected JasperReportBuilder() {
private JasperReportBuilder() {
super(Void.class);
}

Expand Down Expand Up @@ -96,17 +96,18 @@ private void doCompileAndMoveReport(final File buildFile, final File jasperFile)
final File tmpBuildFile =
File.createTempFile("temp_", JASPER_REPORT_COMPILED_FILE_EXT, buildFile.getParentFile());
final String timerName = getClass().getName() + ".compile." + jasperFile;
Timer.Context compileTimerContext = this.metricRegistry.timer(timerName).time();
try {
JasperCompileManager.compileReportToFile(
jasperFile.getAbsolutePath(), tmpBuildFile.getAbsolutePath());
} catch (JRValidationException e) {
LOGGER.error("The report '{}' isn't valid.", jasperFile.getAbsolutePath());
throw e;
} finally {
final long compileTime =
TimeUnit.MILLISECONDS.convert(compileTimerContext.stop(), TimeUnit.NANOSECONDS);
LOGGER.info("Report '{}' built in {}ms.", jasperFile.getAbsolutePath(), compileTime);
try (Timer.Context compileTimerContext = this.metricRegistry.timer(timerName).time()) {
try {
JasperCompileManager.compileReportToFile(
jasperFile.getAbsolutePath(), tmpBuildFile.getAbsolutePath());
} catch (JRValidationException e) {
LOGGER.error("The report '{}' isn't valid.", jasperFile.getAbsolutePath());
throw e;
} finally {
final long compileTime =
TimeUnit.MILLISECONDS.convert(compileTimerContext.stop(), TimeUnit.NANOSECONDS);
LOGGER.info("Report '{}' built in {}ms.", jasperFile.getAbsolutePath(), compileTime);
}
}
move(tmpBuildFile.toPath(), buildFile.toPath(), StandardCopyOption.ATOMIC_MOVE);
}
Expand Down
Loading
Loading