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

cannot auto discovery microservice #3914

Open
HelloDhero opened this issue Dec 9, 2024 · 15 comments
Open

cannot auto discovery microservice #3914

HelloDhero opened this issue Dec 9, 2024 · 15 comments

Comments

@HelloDhero
Copy link

HelloDhero commented Dec 9, 2024

env:
spring boot admin: 3.4.1
consul: v1.16.2(one node)

step 1: start spring-boot-admin
step 2: start other microservice

result : Not every time a newly launched service can be discovered

reason: method discoveryClient.getInstances can not read latest data

@HelloDhero
Copy link
Author

The following code work ok ! just add sleep
Thread.sleep(Duration.ofSeconds(5));
discoveryClient.getServices().stream()
.filter(serviceId -> !"consul".equalsIgnoreCase(serviceId))
.forEach(id -> discoveryClient.getInstances(id)
.forEach(serviceInstance -> LOGGER.error(serviceInstance.getInstanceId())));

@erikpetzold
Copy link
Member

Do you have @EnableScheduling Annotation on your Admin Server? This is required for searching new services.

@HelloDhero
Copy link
Author

yes, There is no difference

@HelloDhero
Copy link
Author

the problem is 'discoveryClient.getInstances(id)' cannot read the latest data from consul

@erikpetzold
Copy link
Member

You need to add some more details to help us understand the context of your messages.

First you wrote, that some code snippet is working. Where is is working? Where did you add this? Where did you execute the code?

Then you added another snippet (that is part of the first one) and say it does not work. This contradicts your first message. Also here: what do you mean with "cannot read"? Is there some network issue? Does cosul not have the data? Is the response not readable? Does Consul not provide the correct data? Do you get some error message in the logs?

In your initial message you said "Not every time", so does it mean it is working somthimes? Maybe you just hav to wait a bit longer or decrease some interval? In what circumstances does it work?

Can you provide some sample project showing your problem?

@HelloDhero
Copy link
Author

InstanceDiscoveryListener.discover can be call when service register,
WechatIMG1149

above is the code to register to bootAdmin , line 126 can get the service but line 128 can not get instances

if your add a custom @eventlistener to deal HeartbeatEvent like discover method and add sleep in the method , getInstances work ok

@HelloDhero
Copy link
Author

Not every time mean below
step 1、start A service , bootAdmin not discovery
stop 2、start B service , bootAdmin can discovery A , but B cannot

@SteKoe
Copy link
Contributor

SteKoe commented Dec 12, 2024

I have tried to reproduce the issue, too, without any luck. As soon as the servies appear in consule UI, the state is reflected in Spring Boot Admin. Please check if the services are registered at consul, do they appear in the UI at the registration side? As my colleague said, we need a project to reproduce the issue in order to help you.

@HelloDhero
Copy link
Author

logging.config: ${logging.config}
server.port: 7777
spring:
    profiles.active: ${profilesActive}
    application.name: ${spring.application.name}
    boot.admin:
        discovery.ignored-services: consul
        ui:
            title: 应用列表
            login-icon: assets/img/icon-spring-boot-admin.svg
            brand: <img src="${spring.boot.admin.ui.login-icon}"><span>${spring.boot.admin.ui.title}</span>
            available-languages: en,zh-CN
            view-settings:
                - name: applications
                  enabled: false
                - name: about
                  enabled: false
    security.user:
        name: ${bootAdminUsername}
        password: ${bootAdminPassword}
    cloud.consul:
        host: ${consul.host}
        discovery:
            heartbeat.enabled: true
            metadata:
                user-name: ${bootAdminUsername}
                user-password: ${bootAdminPassword}
            prefer-ip-address: ${preferIpAddress}
            query-passing: true
management:
    endpoints.web.exposure.include: '*'
    endpoint.health.show-details: always
    endpoint.env.show-values: always
    endpoint.configprops.show-values: always
    prometheus.metrics.export.pushgateway:
        enabled: false
        push-rate: 10s
        shutdown-operation: post
        job: ${spring.profiles.active}_${spring.application.name}
        grouping-key:
            instance: ${spring.cloud.client.ip-address}:${server.port}

@HelloDhero
Copy link
Author

There is no other code left

@HelloDhero
Copy link
Author

#3556 Maybe it's also with me

@erikpetzold
Copy link
Member

To me this sounds like Consul does not provide the instances on time.

  • Spring Boot Admin is triggered which is correct
  • and is trying to get the instances from Consul which is correct
  • but then consul is not providing the instances
    • is then providing them with some delay (sleep)
    • or later (when next service is registered)

In your code the @scheduled annotation is still missing.

@erikpetzold
Copy link
Member

because it enables a scheduler which checks the discovery server on a regular basis

@HelloDhero
Copy link
Author

HelloDhero commented Dec 13, 2024

What is the purpose of adding '@EnabledScheduling'?
I haven't noticed anything scheduler need enables

@HelloDhero
Copy link
Author

HelloDhero commented Dec 13, 2024

image I think the problem happened here [ConsulDiscoveryClient Line 70], I think you already understand what I mean

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

3 participants