use of org.wikidata.query.rdf.blazegraph.filters.FilterConfiguration in project wikidata-query-rdf by wikimedia.
the class SystemOverloadFilter method init.
@Override
public void init(FilterConfig filterConfig) throws ServletException {
super.init(filterConfig);
try {
operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
} catch (IllegalArgumentException e) {
operatingSystemMXBean = null;
logger.error("Could not load {}.", OperatingSystemMXBean.class.getSimpleName(), e);
}
FilterConfiguration config = new FilterConfiguration(filterConfig, WDQS_CONFIG_PREFIX);
systemLoadLowLimit = config.loadDoubleParam("system-load-low-limit", -1.0);
systemLoadHighLimit = config.loadDoubleParam("system-load-high-limit", -1.0);
if (systemLoadLowLimit > systemLoadHighLimit) {
throw new ServletException("system-load-low-limit should be lower than system-load-high-limit");
}
enableFilterIfHeader = config.loadStringParam("enable-if-header");
}
use of org.wikidata.query.rdf.blazegraph.filters.FilterConfiguration in project wikidata-query-rdf by wikimedia.
the class ThrottlingFilter method init.
/**
* Initialise the filter.
*
* The following parameters are available (see
* {@link org.isomorphism.util.TokenBucket} for the details on bucket
* configuration, see implementation for the default values):
* <ul>
* <li>{@code request-duration-threshold-in-millis}: requests longer
* than this threshold will start the tracking for this user</li>
*
* <li>{@code time-bucket-capacity-in-seconds},
* {@code time-bucket-refill-amount-in-seconds},
* {@code time-bucket-refill-period-in-minutes}: configuration of the
* bucket tracking request durations</li>
*
* <li>{@code error-bucket-capacity},
* {@code error-bucket-refill-amount},
* {@code error-bucket-refill-period-in-minutes}: configuration of the
* bucket tracking errors</li>
*
* <li>{@code throttle-bucket-capacity},
* {@code throttle-bucket-refill-amount},
* {@code throttle-bucket-refill-period-in-minutes}: configuration of
* the bucket tracking throttling</li>
*
* <li>{@code ban-duration-in-minutes}: how long should a user be
* banned when a ban is triggered</li>
*
* <li>{@code max-state-size}: how many users to track</li>
* <li>{@code state-expiration-in-minutes}: tracking of a user expires
* after this duration</li>
*
* <li>{@code enable-throttling-if-header}: enable the throttling on
* the requests which have this header set</li>
* <li>{@code enable-ban-if-header}: enable the banning on the requests
* which have this header set</li>
* <li>{@code always-throttle-param}: always throttle requests where
* this parameter is set (useful for testing)</li>
* <li>{@code always-ban-param}: always ban requests where this
* parameter is set (useful for testing)</li>
*
* <li>{@code enabled}: entirely disable this filter if set to
* false</li>
* </ul>
*
* See {@link FilterConfiguration#loadStringParam(String)} for
* the details of where the configuration is loaded from.
*
* @param filterConfig {@inheritDoc}
*/
@Override
public void init(FilterConfig filterConfig) throws ServletException {
super.init(filterConfig);
ThrottlingFilterConfig config = new ThrottlingFilterConfig(new FilterConfiguration(filterConfig, FilterConfiguration.WDQS_CONFIG_PREFIX));
this.enabled = config.isFilterEnabled();
this.userAgentIpBucketing = new UserAgentIpAddressBucketing();
this.regexBucketing = new RegexpBucketing(loadRegexPatterns(config.getRegexPatternsFile()), r -> r.getParameter("query"));
this.agentBucketing = new RegexpBucketing(loadRegexPatterns(config.getAgentPatternsFile()), r -> r.getHeader("User-Agent"));
stateStore = CacheBuilder.newBuilder().maximumSize(config.getMaxStateSize()).expireAfterAccess(config.getStateExpiration().toMillis(), MILLISECONDS).build();
Callable<ThrottlingState> stateInitializer = createThrottlingState(config.getTimeBucketCapacity(), config.getTimeBucketRefillAmount(), config.getTimeBucketRefillPeriod(), config.getErrorBucketCapacity(), config.getErrorBucketRefillAmount(), config.getErrorBucketRefillPeriod(), config.getThrottleBucketCapacity(), config.getThrottleBucketRefillAmount(), config.getThrottleBucketRefillPeriod(), config.getBanDuration());
timeAndErrorsThrottler = new TimeAndErrorsThrottler<>(config.getRequestDurationThreshold(), stateInitializer, stateStore, config.getEnableThrottlingIfHeader(), config.getAlwaysThrottleParam(), Clock.systemUTC());
banThrottler = new BanThrottler<>(stateInitializer, stateStore, config.getEnableBanIfHeader(), config.getAlwaysBanParam(), Clock.systemUTC());
}
Aggregations