GithubHelp home page GithubHelp logo

Comments (9)

github-actions avatar github-actions commented on June 1, 2024

Hello @denapucaco, thanks for getting in touch, we will get back to you asap! If you have issues in the 1.x.x.RELEASE line we recommend you to update to the latest version, unfortunately this line is not supported anymore.

from spring-cloud-zuul-ratelimit.

marcosbarbero avatar marcosbarbero commented on June 1, 2024

The configuration you added to the description looks odd to me. Are you using it exactly the way you described? I'm talking about the full configuration not just the url_pattern

from spring-cloud-zuul-ratelimit.

denapucaco avatar denapucaco commented on June 1, 2024

@marcosbarbero Thanks for your reply.

Below is the zuul config for service we are trying to add rate limiting. Please let me know if I am missing anything for url-pattern.

zuul:
  routes:
    audit-api:
      path: /gw/audit/**
      serviceId: audit-api-ms
      stripPrefix: true
      retryable: true
  ratelimit:
    enabled: true
    repository: JPA
    policy-list:                # Zuul rate limit policy list
      audit-api:                # custom policy name
        - limit: 2              # request number limit per refresh interval window
          refresh-interval: 60  # in seconds
          type:
           - user
           - url_pattern=/api/v1.0.0/audit/*

audit-api-ms:
  ribbon:
    listOfServers: ${SERVER_LIST_AUDIT}
    ServerListRefreshInterval: 3600000

When I just use the url without value then rate table has below rows after I try few endpoints, so it rate limiting is working for all the urls if no url or url_pattern is mentioned in type. But we want it for just few urls

mi-gateway:audit-api:lossmgr:/api/v1.0.0/audit/statuscode/IPG -1 57011 2021-08-16 16:03:57
mi-gateway:audit-api:lossmgr:/api/v1.0.0/audit/statuscode/COM -1 57419 2021-08-16 16:04:06
mi-gateway:audit-api:lossmgr:/api/v1.0.0/audit/statuscode/WAT -1 30756 2021-08-16 16:03:22

Thanks you

from spring-cloud-zuul-ratelimit.

marcosbarbero avatar marcosbarbero commented on June 1, 2024

I see, I'm not on my computer now but I suspect the serviceId being different than the uri is causing the problem.

Can you try to use audit-api-ms on the policy-list?

If it works then we have a bug 😬

from spring-cloud-zuul-ratelimit.

denapucaco avatar denapucaco commented on June 1, 2024

Sure, I'll try and get back to you.

Thanks
Prashant

from spring-cloud-zuul-ratelimit.

denapucaco avatar denapucaco commented on June 1, 2024

@marcosbarbero As per your suggestion tried with audit-api-ms in the policy-list. This didn't solve the issue.

I tried to debug the code to understand what could be causing the issue with url_pattern and found that -

com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.filters.AbstractRateLimitFilter Class ; policy method

        policies = properties.getPolicies(routeId).stream()
                .filter(policy -> applyPolicy(request, route, policy))
                .collect(Collectors.toList());

When used the url_pattern the above code returns the empty list. I think because of this rate limiting is not working with url_pattern

I tried with url again and this time I could make it work with below config

  ratelimit:
    enabled: true
    repository: JPA
    policy-list:                # Zuul rate limit policy list
      audit-api:                # custom policy name
        - limit: 2              # request number limit per refresh interval window
          refresh-interval: 60  # in seconds
          type:
           - user
           - url=/api/v1.0.0/audit/statuscode/INP
        - limit: 1              # request number limit per refresh interval window
          refresh-interval: 60  # in seconds
          type:
           - user
           - url=/api/v1.0.0/audit/statuscode/COM
        - limit: 3              # request number limit per refresh interval window
          refresh-interval: 60  # in seconds
          type:
           - user
           - url=/api/v1.0.0/audit/statuscode/WAT

This created below rows in rate table. The URL is added twice in the rate_key. Is this a normal behavior?

mi-gateway:audit-api:lossmmgr:/api/v1.0.0/audit/statuscode/INP:/api/v1.0.0/audit/statuscode/INP -1 48423 2021-08-17 16:51:25
mi-gateway:audit-api:lossmmgr:/api/v1.0.0/audit/statuscode/COM:/api/v1.0.0/audit/statuscode/COM -1 43007 2021-08-17 16:51:42
mi-gateway:audit-api:lossmmgr:/api/v1.0.0/audit/statuscode/WAT:/api/v1.0.0/audit/statuscode/WAT -1 55993 2021-08-17 16:54:41

For now we want to use rate limiting with few URLs but we would like to make the url_pattern work. If you have any suggestions please let me know

Thanks,
Prashant

from spring-cloud-zuul-ratelimit.

marcosbarbero avatar marcosbarbero commented on June 1, 2024

Thanks for the detailed response.

Can you try using ** instead of *?

from spring-cloud-zuul-ratelimit.

denapucaco avatar denapucaco commented on June 1, 2024

I think I have tried it already but will try it one more time tomorrow and will update you.

from spring-cloud-zuul-ratelimit.

denapucaco avatar denapucaco commented on June 1, 2024

@marcosbarbero Thank you for your help, I am able to make it work with url_pattern

I had to debug the code to understand the issue.

The request.getRequestURI() in the apply method of URL_PATTERN in RateLimitType class contains the URI with the path /gw/audit/. Since we are using the stripPrefix: true I was not adding this path in the url_pattern. ( url worked fine without this path )

Along with the path addition had to use ** as the AntPathMatcher uses them. I have added the config that worked for me below.

    /**
     * Rate limit policy considering an URL Pattern
     */
    URL_PATTERN {
        @Override
        public boolean apply(HttpServletRequest request, Route route, RateLimitUtils rateLimitUtils, String matcher) {
            return new AntPathMatcher().match(matcher.toLowerCase(), request.getRequestURI().toLowerCase());
        }

Working Config

zuul:
  routes:
    audit-api:
      path: /gw/audit/**
      serviceId: audit-api-ms
      stripPrefix: true
      retryable: true
  ratelimit:
    enabled: true
    repository: JPA
    policy-list:                # Zuul rate limit policy list
      audit-api:                # custom policy name
        - limit: 2              # request number limit per refresh interval window
          refresh-interval: 60  # in seconds
          type:
           - user
           - url_pattern=/gw/audit/api/v1.0.0/audit/**
           - http_method=get

from spring-cloud-zuul-ratelimit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.