Netflix / eureka

AWS Service registry for resilient mid-tier load balancing and failover.
Apache License 2.0
12.37k stars 3.74k forks source link

Eureka REST operations #1407

Open sarmancoder opened 3 years ago

sarmancoder commented 3 years ago

Hi all, how it's going?

I am on the development of a monitoring services status based on spring. I developed a scheduled method so with getServices retrieves all the services are in the network, and look if som service is missing

The problem is that when I run a service that is registered in Eureka, and when I retrieve all the services I don't see the service I runned before, but if I enter the to de dashboard and next time I run getServices (from EurekaDiscoveryClient) I get the service I runned before

Thanks in advance

sarmancoder commented 3 years ago

The code I use to monitor the services is that

@Scheduled(fixedDelay = 900000)
public List<String> listServices() throws TelegramApiException {
List<String> servicesActive = client.discoveryClient.getServices();

for (String service : services) {
    if (!servicesActive.contains(service)) {
        System.out.println("El servicio " + service + " esta caido");
        SendMessage message = new SendMessage();
        message.setChatId("-12343123446");
        message.setText("El servicio " + service + " esta caido");
        bot.execute(message);
    }
}

return servicesActive;
}
troshko111 commented 3 years ago

I'm not sure how we can help, getServices() is not a method from Eureka, if this is a SBN thing I suggest asking there. But honestly the use case and the problem is unclear anyway, if you could provide a minimal example with expected vs actual data I could at least point you in the right direction.

sarmancoder commented 3 years ago

The problem is:

  1. I run a spring server that is integrated with eureka (at this point eureka should have registered the service)
  2. I call getServices method from discoveryClient, this method returns a list of all services that eureka registered, but I don't get the service I runned (and I should)
  3. I enter the dashboard and i see my service in the dashboard listed
  4. I call another time getServices and appears my service listed

I am trying to use eureka so I can be sure all the services are running, for this, I use the getservices method Theoretically I should see in the step 2 my service I recent runned, but I see nothing, only after entering in the dashboard, next, in the getServices output I see my service listed

This problem can be fixed with the rest operations (I think) but I get a 404 when I make a request to /eureka/v2/apps, therefore I asked this here, I don't know why I am getting 404 code

Any help please?

troshko111 commented 3 years ago

You may not be getting all the expected services because of a race?

Regarding the RESTful endpoint, it's GET /eureka/v2/apps by default, so that's correct, I can't say why you're getting a 404 without knowing how you setup your server.

EffNox commented 3 years ago

Insert this in your main class (Eureka Server):

public @Bean FilterRegistrationBean<?> corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("http://localhost:4200");
    config.addAllowedMethod("*");
    config.addAllowedHeader("Accept");
    source.registerCorsConfiguration("/**", config);
    FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<Filter>(new CorsFilter(source));
    bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
    return bean;
}

Full example: https://github.com/EffNox/spring_eureka-rest-operations-angular

dmakvh commented 2 years ago

You may not be getting all the expected services because of a race?

Regarding the RESTful endpoint, it's GET /eureka/v2/apps by default, so that's correct, I can't say why you're getting a 404 without knowing how you setup your server.

On previous versions of eureka (probably somewhere around 2019) v2 does not exist - the path only works without it ... GET /eureka/apps in this case .. i dont know why this API-breaking change (thats a big no-no!) was implemented but ... there you go.