marcosbarbero / spring-cloud-zuul-ratelimit

Rate limit auto-configure for Spring Cloud Netflix Zuul

Home Page:https://blog.marcosbarbero.com/spring-cloud-netflix-zuul-rate-limit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Public IP address in type origin instead private IP

CasperOm opened this issue · comments

Hi,

I have implemented ratelimit in spring cloud zuul but when i apply type as origin it takes private IP address of the client and gets save in the rate table. Is there any way to get the public IP address of the client ?

Thanks ! Quick response appreciated.

Hello @CasperOm, 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.

Hi @CasperOm, is your application running behind a proxy?

Hi @marcosbarbero No its not running behind any proxy. Only below 4 annotations are used in Zuul.

@EnableResourceServer
@EnableZuulProxy
@EnableEurekaClient
@SpringBootApplication

How's your deployment setup? Where's the application running? How is the request being performed? Is the client in a different network? Is there a load-balancer or any other thing between the client and the API Gateway?

Zuul is been running on my local with which i'm expecting the IP to come in is 127.0.0.1 but I'm not receiving this ip instead it coming as 0:0:0:0:0:0:0:1.
Both client and service are on same network. I'm hitting the zuul from the postman. There is no externally configured load-balancer between the client and the API Gateway.
And yes i'm also using eureka.

So, you are using Eureka to discover the gateway by name and perform the request, is that it?

Yes you are correct, but the ratelimiter is implemented in Zuul itself. When i tried debugging it i'm not able to get public IP.

This behavior is explained at Spring Cloud's documentation. I believe this may solve your issue.

Thanks for the suggestion, but it didnt worked. I used inetutils.preferredNetworks: 127.0 and also inetutils.useOnlySiteLocalInterfaces: true but still the same issue.

If you can share a sample repo reproducing the error, I can take a look.

Sure will share in some time.

@marcosbarbero Sorry for the delay in sharing the sample repo.
https://github.com/CasperOm/zuul-rate-limiter.git This is the repo which consists sample code for the issue mentioned above.

Run as spring boot application and i have used H2 database where you will be able to see the origin as 0:0:0:0:0:0:0:1 instead of 127.0.0.1. Please have a look in this and if we can find a solution for this it will be very helpful for me.

Thanks, If you are not able to access the repo let me know.

@CasperOm maybe the repo is private? I can't see it

@marcosbarbero Please check now if you can see it?

Now I can see it, will check on it later today.

Sure Thanks

@CasperOm unfortunately, there's something wrong with the sample project.

2021-01-19 10:47:16.699  WARN 8190 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
2021-01-19 10:47:16.700  INFO 8190 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-01-19 10:47:16.720  INFO 8190 --- [           main] utoConfigurationReportLoggingInitializer :

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2021-01-19 10:47:16.729 ERROR 8190 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.14.RELEASE.jar!/:4.3.14.RELEASE]

@marcosbarbero I tried again in my STS workspace, it is started successfully on port 8762. Could you please try doing mvn clean install and check.

I tried in every possible way, unfortunately, it simply just not run

@marcosbarbero Okay let me try implementing it other than JPA and share the updated code. Just wanted to confirm that you are getting JPA relation error only right? no other errors?

@marcosbarbero Could you pls try spring-zuul-rate-limiting project from this https://github.com/CasperOm/zuul-rate-limiter.git repo and try if you run this project in your STS.

@marcosbarbero Pls use this project. It doesn't have any H2 database. You can see ip which is assigned in response headers, Project name is spring-zuul-rate-limiting from https://github.com/CasperOm/zuul-rate-limiter.git
Reference : https://www.baeldung.com/spring-cloud-zuul-rate-limit

Unfortunately, this project doesn't run either.

spring-zuul-rate-limiting git:(main) ✗ mvn clean package
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.baeldung.spring.cloud:spring-zuul-rate-limiting:0.0.1-SNAPSHOT: Could not find artifact com.baeldung.spring.cloud:spring-cloud-zuul:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 10, column 13
 @
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project com.baeldung.spring.cloud:spring-zuul-rate-limiting:0.0.1-SNAPSHOT (/Users/marcosbarbero/dev/github/zuul-rate-limiter/spring-zuul-rate-limiting/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.baeldung.spring.cloud:spring-zuul-rate-limiting:0.0.1-SNAPSHOT: Could not find artifact com.baeldung.spring.cloud:spring-cloud-zuul:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 10, column 13 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 1 day