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

Unable to access application context in discovery #2734

Open
trajano opened this issue Sep 26, 2022 · 2 comments
Open

Unable to access application context in discovery #2734

trajano opened this issue Sep 26, 2022 · 2 comments

Comments

@trajano
Copy link
Contributor

trajano commented Sep 26, 2022

Describe the bug
Though I fixed the documentation in #2733 I am still unable to use the rate limiter in Discovery. It appears that in the code you're assembling a new evaluation context containing only the metadata and not include the rest of the context so defining a keyresolver does not work inside discovery

In DiscoveryClientRouteDefinitionLocator specifically

	private DiscoveryClientRouteDefinitionLocator(String discoveryClientName, DiscoveryLocatorProperties properties) {
		this.properties = properties;
		if (StringUtils.hasText(properties.getRouteIdPrefix())) {
			routeIdPrefix = properties.getRouteIdPrefix();
		}
		else {
			routeIdPrefix = discoveryClientName + "_";
		}
               // context is built here
		evalCtxt = SimpleEvaluationContext.forReadOnlyDataBinding().withInstanceMethods().build();
	}

// and only gets the info from the service instance.

	String getValueFromExpr(SimpleEvaluationContext evalCtxt, SpelExpressionParser parser, ServiceInstance instance,
			Map.Entry<String, String> entry) {
		try {
			Expression valueExpr = parser.parseExpression(entry.getValue());
			return valueExpr.getValue(evalCtxt, instance, String.class);
		}
		catch (ParseException | EvaluationException e) {
			if (log.isDebugEnabled()) {
				log.debug("Unable to parse " + entry.getValue(), e);
			}
			throw e;
		}
	}

Sample
If possible, please provide a test case or sample application that reproduces
the problem. This makes it much easier for us to diagnose the problem and to verify that
we have fixed it.

@trajano
Copy link
Contributor Author

trajano commented Sep 26, 2022

I'm trying a workaround which is to create a custom filter factory like this

@Component
public class DiscoveryRequestRateLimiterGatewayFilterFactory
    extends RequestRateLimiterGatewayFilterFactory {

  public DiscoveryRequestRateLimiterGatewayFilterFactory(
      RateLimiter defaultRateLimiter,
      @Qualifier("tokenKeyResolver") KeyResolver defaultKeyResolver) {

    super(defaultRateLimiter, defaultKeyResolver);
  }
}

@spencergibb
Copy link
Member

This has been restricted for security. See c76b775

We could add something similar for DiscoveryClientRouteDefinitionLocator

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

No branches or pull requests

2 participants