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

Unable to set RequestRateLimiter as default filters via configuration properties #310

Closed
zhaoyibo opened this Issue May 9, 2018 · 8 comments

Comments

Projects
None yet
5 participants
@zhaoyibo

zhaoyibo commented May 9, 2018

in Finchley.RC1, I found that I can't configure defaultFilters with RequestRateLimiter like this

default-filters:
- name: RequestRateLimiter
  args:
    burstCapacity: 2
    replenishRate: 2
    keyResolver: '#{@userKeyResolver}'

because AbstractRateLimiter#onApplicationEvent would not put the routeId and routeConfig to the config map.

	@Override
	public void onApplicationEvent(FilterArgsEvent event) {
		Map<String, Object> args = event.getArgs();

		// only defaultFilters is ok, others will return
		if (args.isEmpty() || !hasRelevantKey(args)) {
			return;
		}

		String routeId = event.getRouteId();
		C routeConfig = newConfig();
		ConfigurationUtils.bind(routeConfig, args,
				configurationPropertyName, configurationPropertyName, validator);
		getConfig().put(routeId, routeConfig);
	}
	private boolean hasRelevantKey(Map<String, Object> args) {
		return args.keySet().stream()
				.anyMatch(key -> key.startsWith(configurationPropertyName + "."));
	}

if only add RequestRateLimiter to defaultFilters, only the defaultFilters contains the key configurationPropertyName, others don't have the key so they are not in config map.

but RedisRateLimiter#isAllowed can't get the routeConfig through the specified routeId so we will get an exception.

	public Mono<Response> isAllowed(String routeId, String id) {
		if (!this.initialized.get()) {
			throw new IllegalStateException("RedisRateLimiter is not initialized");
		}
                 // the routeConfig can only be obtained when the routeId is "defaultFilters"
		Config routeConfig = getConfig().get(routeId);

		if (routeConfig == null) {
			if (defaultConfig == null) {
				throw new IllegalArgumentException("No Configuration found for route " + routeId);
			}
			routeConfig = defaultConfig;
		}
        
		// ...
	}

exception

java.lang.IllegalArgumentException: No Configuration found for route service_customer
	at org.springframework.cloud.gateway.filter.ratelimit.RedisRateLimiter.isAllowed(RedisRateLimiter.java:93) ~[spring-cloud-gateway-core-2.0.0.RC1.jar:2.0.0.RC1]

is it a bug or the designer deliberately did so?

@starslau

This comment has been minimized.

starslau commented May 15, 2018

I also encountered this problem, how did you solve it later?

@SoftwareKing

This comment has been minimized.

SoftwareKing commented May 16, 2018

@zhaoyibo 方便加你微信交流一下吗?我微信是Software_King

@zhaoyibo

This comment has been minimized.

zhaoyibo commented May 17, 2018

@spencergibb Yes, I have read this configuration. But this configuration is for the specified route, this can work. However, what I said is that the default-filters are not for the specified route.

@spencergibb

This comment has been minimized.

Member

spencergibb commented May 17, 2018

It's the same, just under the default routes

@zhaoyibo

This comment has been minimized.

zhaoyibo commented May 17, 2018

@spencergibb But it doesn't work, cannot find configuration for route.

@spencergibb

This comment has been minimized.

Member

spencergibb commented May 17, 2018

I see.

@keets2012

This comment has been minimized.

keets2012 commented May 19, 2018

@spencergibb have the problem been solved ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment