Eureka Server - Client setup - UnknownHostException - Could not get Swagegr definition from API - spring-boot

I am having simple setup - eureka server and 'event-catalog' as eureka client. Both hosted in AWS.
eureka server loads up the service on home page:
EVENT-CATALOG n/a (1) (1) UP (1) - cff2a33fcf77:event-catalog:8550
However while accessing swagger-ui.html getting below errors on cloudwatch console :
2021-09-07 21:08:28.318 ERROR 42 --- [ scheduling-1] c.e.s.e.c.s.ServiceDescriptionUpdater : Error while getting service definition for service : event-catalog Error : I/O error on GET request for "http://cff2a33fcf77:8550/v2/api-docs": cff2a33fcf77; nested exception is java.net.UnknownHostException: cff2a33fcf77
ERROR 42 --- [ scheduling-1] c.e.s.e.c.s.ServiceDescriptionUpdater : Skipping service id : event-catalog Error : Could not get Swagegr definition from API
My design and code is aligned with https://dzone.com/articles/centralized-documentation-in-microservice-spring-b
My eureka server configuration as below:
#SpringBootApplication
#EnableEurekaServer
#EnableSwagger2
#EnableScheduling
public class EurekaserverApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaserverApplication.class, args);
}
}
client (event-catalog) configuration as below
Annotated application class with '#EnableEurekaClient'
and application.yml config file has below configuration:
---
spring:
config.activate.on-profile: dev
eureka:
instance:
appname: event-catalog
client:
enabled: true
register-with-eureka: true
#fetch-registry: false
service-url:
defaultZone: https://dev.eureka-service.rd.xxx.io/eureka/
Above whole setup works well when running locally. However after deploying to AWS it is giving above mentioned errors 'unknown host'. Wondering where it is getting 'cff2a33fcf77' and why not simply dev.event-catalog.rd.xxx.io/?
Please suggest what I am missing here. I am implementing discovery server first time and have spent so much time already to get it working. Please adivce.

Figured out. I observed that spring cloud service instance was not resolving host correctly. It was taking AWS ecs task container id for the host.
Manipulated code to resolve host.

Related

Health check properties for springboot application in PCF

I have configured the below health check properties in my spring boot application(using actuator) and returning "UP" when locally tested using the below endpoint
server:
servlet:
context-path: /account/v1
port: 8443
management:
endpoints:
web:
path-mapping:
health: /health
Check locally using "http://localhost:8443/account/v1/actuator/health and returning
{"status":"UP"}"
In PCF I updated the Health check type as "http" and Endpoint as "/actuator/health".
When I pushed my app I am getting the below error
2020-09-02T12:43:15.92+0530 [HEALTH/0] ERR Failed to make HTTP request to '/actuator/health' on port 8080: connection refused
2020-09-02T12:43:15.92+0530 [CELL/0] ERR Failed after 1m0.632s: readiness health check never passed.
Please help on this.(Is my port or endpoint wrong)

Eureka Client: Eureka Registry server address alternative to 'localhost'

Eureka-server(MediaStoreEurekaServer): bootstrap.properties
spring.application.name=MediaStoreEurekaServer
server.port=9091
eureka.client.serviceUrl.defaultZone=http://localhost:9091/eureka}
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
Eureka-client(Config-Server): bootstrap.properties
spring.application.name=Config-Server
server.port=9093
user.home=${HOME}
spring.cloud.config.server.native.search-locations=file://${user.home}/IdeaProjects/MediaStore/centralProperties
spring.profiles.active=native
eureka.client.serviceUrl.defaultZone=http://localhost:9091/eureka
With above 2 properties (services running on same machine), Config-Server is able to register with MediaStoreEurekaServer eureka registry server when using http://localhost:9091/eureka.
I don't want to use localhost. When I use http://MediaStoreEurekaServer:9091/eureka , Config-Server is not able to register.
Can we use something other than localhost for eureka client to find the eureka server like service or instance name? when services are running on same host
Edit 1:
This is what eureka client spring logs give when in eureka client properties file i set
eureka.client.serviceUrl.defaultZone=http://MediaStoreEurekaServer:9091/eureka
Error:
2020-05-22 20:01:02.137 ERROR 22846 --- [nfoReplicator-0] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://MediaStoreEurekaServer:9091/eureka/}
com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException: MediaStoreEurekaServer```

Zuul Forwarding error - Trying to connect to a different(unknown) ip

I have configured zuul proxy and eureka naming server for my spring boot application. Zuul proxy run on port 8765 and eureka runs on port 8761.
Also two other microservices, user-service and message-service run on port 8081 and 8082.
Also I have used swagger for the zuul proxy service where i can find all microservices api in one place.
Swagger configuration in Zuul proxy service
#Component
#Primary
#EnableAutoConfiguration
public class Controller implements SwaggerResourcesProvider{
#Override
public List<SwaggerResource> get() {
List<SwaggerResource> resources= new ArrayList<>();
SwaggerResource user = new SwaggerResource();
user.setName("USER-SERVICE");
user.setLocation("/api/user/v2/api-docs");
user.setSwaggerVersion("2.0");
resources.add(user);
SwaggerResource message = new SwaggerResource();
message.setName("MESSAGE-SERVICE");
message.setLocation("/api/message/v2/api-docs");
message.setSwaggerVersion("2.0");
resources.add(message);
return resources;
}
}
application.yml of Zuul proxy
server:
port: 8765
eureka:
client:
serviceUrl:
defaultZone: http://eureka-naming-server:8761/eureka/
instance:
prefer-ip-address: true
metadataMap:
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
zuul:
prefix: /api
sensitive-headers: Cookie,Set-Cookie
routes:
user-service:
path: /user/**
service-id: USER-SERVICE
message-service:
path: /message/**
service-id: MESSAGE-SERVICE
Also i have used docker-compose file to up the docker microservices with default subnet (169.254.3.0/24).
ip address of user-service is 169.254.3.6
ip address of message-service is 169.254.3.10
Here is the issue
When I call these services via zuul proxy swgger ui, often i am getting 500 error. That for the first time i hit the specific url it throws 500 error.
but after few attempt i get the response.
Zuul log which indicate problem
com.netflix.zuul.exception.ZuulException: Forwarding error
...
Caused by: com.netflix.client.ClientException: null
...
Caused by: java.lang.RuntimeException: org.apache.http.conn.ConnectTimeoutException: Connect to 172.22.97.14:8081 [/172.22.97.14] failed: connect timed out
...
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to 172.22.97.14:8081 [/172.22.97.14] failed: connect timed out
...
Caused by: java.net.SocketTimeoutException: connect timed out
I have no idea about 172.22.97.14:8081, why is not try to connect 172.22.97.14:8081 instead of connect to 169.254.3.6:8081
Can someone help me to understand what is happening in here..
Any help would be grateful !
[Edit]
zuul proxy container ip is 169.254.3.10
This problem occured on my project when I was using the same Zuulserver for developing microservices on localhost and DEV environment (when I started microservis on localhost it connected to zullserver on DEV env.). Then when I tried to call some operation through zuulserver it tried to connect to microservis not on DEV env. but on my machine.
I suspect the same problem on your side and IP on which you are developing your application is 172.22.97.14:8081.

Zuul Forwarding error - Internal Server error 500

This is what I am trying to achieve but getting Zuul forwarding error.
Zuul GitHub
UserRegistration Microservice - which will call another Microservice. Also, it has some other APIs'. GitHub Link
UserSearchDelete: above UserRegistration microservice will call this service. GitHub Link
Eureka Server: GitHub Link
If I run the services in Springboot STS at localhost then eveything is working fine.
But if I dockarise all the services and run different containers then I am getting Zuul forrwarding error.
Refer the application.yml files in the Github repos. All the services are getting registered with Eureka.
Could please help? Is it a bug or I am doing something wrong?
GitHub issue reference: https://github.com/spring-cloud/spring-cloud-netflix/issues/3408
Getting the below errors:
"cause": {
"cause": null,
"stackTrace": [
{....
"nStatusCode": 500,
"errorCause": "GENERAL",
"message": "Forwarding error",
"localizedMessage": "Forwarding error",
"suppressed": []
}```
Verify that your Zuul paths are setup properly.
If running on a Docker network, each docker deployment must be connected to the same docker network using the --net myCommonNet tag in the run command. Note that you will have to create this network first. Then you can reference the container hosts on their names.
If you are using kubernetes as your deployment environment, you can access the different microservices using the service name. Then you configure your Zuul's properties.yml as:
zuul:
routes:
myService:
path: /myService/**
url: http://myService.default.svc.cluster.local:8086

server.port in command line not working with spring cloud config server and eureka server

I am studying spring could. What I have now is a spring cloud config server and eureka server.
Code for Config Server
#SpringBootApplication
#EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
application.properties
spring.application.name=config-server
spring.cloud.config.server.git.uri=https://github.com/vincentwah/spring-cloud-config-repository/
server.port=7001
Code for Eureka server
#SpringBootApplication
#EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
bootstrap.properties
spring.application.name=eureka-server
spring.cloud.config.uri=http://localhost:7001/
The config for eureka-server is https://github.com/vincentwah/spring-cloud-config-repository/blob/master/eureka-server.properties
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
server.port=1111
When I start eureka server, I'd like to change the port, so I run below command
java -jar target/eureka-server-0.0.1-SNAPSHOT.jar --server.port=1234
However, the server is still started with port 1111
2017-01-03 14:04:11.324 INFO 6352 --- [ Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP
2017-01-03 14:04:11.339 INFO 6352 --- [ Thread-10] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
2017-01-03 14:04:11.492 INFO 6352 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 1111 (http)
2017-01-03 14:04:11.493 INFO 6352 --- [ main] c.n.e.EurekaDiscoveryClientConfiguration : Updating port to 1111
2017-01-03 14:04:11.500 INFO 6352 --- [ main] com.example.EurekaServerApplication : Started EurekaServerApplication in 27.532 seconds (JVM running for 29.515)
I think I am not doing wrong with --server.port in command line. Does anybody encounter same issue?
Spring Cloud Config, by default, overrides local configuration. It is meant to be the source of truth. You could use profiles so the port is not defined with a particular profile. You could also disable the config client if it's not really needed (in tests for example).
There are also options to allow overrides.
The property sources that are added to you application by the
bootstrap context are often "remote" (e.g. from a Config Server), and
by default they cannot be overridden locally, except on the command
line. If you want to allow your applications to override the remote
properties with their own System properties or config files, the
remote property source has to grant it permission by setting
spring.cloud.config.allowOverride=true (it doesn’t work to set this
locally). Once that flag is set there are some finer grained settings
to control the location of the remote properties in relation to System
properties and the application’s local configuration:
spring.cloud.config.overrideNone=true to override with any local
property source, and
spring.cloud.config.overrideSystemProperties=false if only System
properties and env vars should override the remote settings, but not
the local config files.
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
server.port=1111
spring.cloud.config.allowOverride=true
spring.cloud.config.overrideNone=true
spring.cloud.config.overrideSystemProperties=false
This is working.

Resources