turcsanyip commented on a change in pull request #4972:
URL: https://github.com/apache/nifi/pull/4972#discussion_r608197228
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java
##########
@@ -703,32 +705,48 @@ private static void addDenialOfServiceFilters(String
path, WebAppContext webAppC
}
}
- private static int determineMaxWebRequestsPerSecond(NiFiProperties props) {
+ private static int determineMaxWebRequestsPerSecond(final NiFiProperties
props) {
int defaultMaxRequestsPerSecond =
Integer.parseInt(NiFiProperties.DEFAULT_WEB_MAX_REQUESTS_PER_SECOND);
int configuredMaxRequestsPerSecond = 0;
try {
configuredMaxRequestsPerSecond =
Integer.parseInt(props.getMaxWebRequestsPerSecond());
} catch (final NumberFormatException e) {
- logger.warn("Exception parsing property " +
NiFiProperties.WEB_MAX_REQUESTS_PER_SECOND + "; using default value: " +
defaultMaxRequestsPerSecond);
+ logger.warn("Exception parsing property [{}]; using default value:
[{}]", NiFiProperties.WEB_MAX_REQUESTS_PER_SECOND, defaultMaxRequestsPerSecond);
}
return configuredMaxRequestsPerSecond > 0 ?
configuredMaxRequestsPerSecond : defaultMaxRequestsPerSecond;
}
+ private static long determineRequestTimeoutInMilliseconds(final
NiFiProperties props) {
+ long defaultRequestTimeout =
Math.round(FormatUtils.getPreciseTimeDuration(NiFiProperties.DEFAULT_WEB_REQUEST_TIMEOUT,
TimeUnit.MILLISECONDS));
+ long configuredRequestTimeout = 0L;
+ try {
+ configuredRequestTimeout =
Math.round(FormatUtils.getPreciseTimeDuration(props.getWebRequestTimeout(),
TimeUnit.MILLISECONDS));
+ } catch (final NumberFormatException e) {
+ logger.warn("Exception parsing property [{}]; using default value:
[{}]", NiFiProperties.WEB_REQUEST_TIMEOUT, defaultRequestTimeout);
+ }
+
+ return configuredRequestTimeout > 0 ? configuredRequestTimeout :
defaultRequestTimeout;
+ }
+
/**
* Adds the {@link org.eclipse.jetty.servlets.DoSFilter} to the specified
context and path. Limits incoming web requests to {@code
maxWebRequestsPerSecond} per second.
*
* @param path the path to apply this filter
* @param webAppContext the context to apply this filter
* @param maxWebRequestsPerSecond the maximum number of allowed requests
per second
*/
- private static void addWebRequestRateLimitingFilter(String path,
WebAppContext webAppContext, int maxWebRequestsPerSecond) {
+ private static void addWebRequestRateLimitingFilter(String path,
WebAppContext webAppContext, int maxWebRequestsPerSecond, long
requestTimeoutInMilliseconds, final String ipWhitelist) {
Review comment:
@thenatog Thanks for extending the configuration capabilities of
`DoSFilter`.
Could you please update the method's javadoc as well?
Furthermore, as this method configures not only the request rate but also
the timeout now, I would consider to rename it to `addWebRequestLimitingFilter`
or something similar.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]