Skip to content

Commit

Permalink
Get configuration from system properties or env variables instead of …
Browse files Browse the repository at this point in the history
….properties file.
  • Loading branch information
rubenvp8510 authored and John Sanda committed Sep 15, 2017
1 parent 53c0a8a commit 3885f90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

package org.hawkular.metrics.api.jaxrs.log.time;

import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletContext;

import io.undertow.servlet.ServletExtension;
Expand All @@ -30,37 +27,38 @@ public class TimerLoggerServletExtension implements ServletExtension {

private RequestTimeLogger requestTimeLogger;

private static final String PROPERTY_FILE = "/WEB-INF/time-logger-filter.properties";
private static final String THRESHOLD_PROPERTY_KEY = "hawkular.metrics.request.logging.time.threshold";
private static final String THRESHOLD_ENV_VAR = "REQUEST_LOGGING_TIME_THRESHOLD";

// Threshold units are in ms, 10sec is the default here.
private static final long DEFAULT_THRESHOLD_VALUE = 10000;

@Override
public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) {

long timeThreshold = 0;
long timeThreshold = DEFAULT_THRESHOLD_VALUE;

String thresholdValue;

InputStream is = servletContext.getResourceAsStream(PROPERTY_FILE);
thresholdValue = System.getProperty(THRESHOLD_PROPERTY_KEY);

if (is != null) {
if ( thresholdValue == null){
thresholdValue = System.getenv(THRESHOLD_ENV_VAR);
}

if ( thresholdValue != null && !thresholdValue.isEmpty()) {
try {
String timeThresholdString;
Properties props = new Properties();
props.load(is);
timeThresholdString = props.getProperty("logging-time-threshold");
if (timeThresholdString != null && !timeThresholdString.isEmpty()) {
timeThreshold = Long.parseLong(timeThresholdString);
}
timeThreshold = Long.parseLong(thresholdValue);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

final long cTimeThreshold = timeThreshold;

if (timeThreshold > 0) {
deploymentInfo.addInitialHandlerChainWrapper(containerHandler -> {
requestTimeLogger = new RequestTimeLogger(containerHandler, cTimeThreshold);
return requestTimeLogger;
});
}
deploymentInfo.addInitialHandlerChainWrapper(containerHandler -> {
requestTimeLogger = new RequestTimeLogger(containerHandler, cTimeThreshold);
return requestTimeLogger;
});
}
}

This file was deleted.

0 comments on commit 3885f90

Please sign in to comment.