spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.85k stars 2.43k forks source link

eureka: improve single-server experience #4251

Open codefromthecrypt opened 5 months ago

codefromthecrypt commented 5 months ago

Is your feature request related to a problem? Please describe. Right now, to configure a eureka server, you need to add several properties to try to inform its client config is self-directed.

e.g.

eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
    registryFetchIntervalSeconds: 1

Even when you do that, the UI will show the same node as an unavailable replica. It looks like this:

unavailable-replicas    http://localhost:8761/eureka/,

The server shows up as a replica because the isThisMyUrl() host comparison is strict. For example, it doesn't check to see if the server is listening on all IPs, as usually the case unless spring's "server.address" property is set. So, it doesn't know that ultimately localhost:8761 must be the same instance as ${hostname}:8761 and marks it down. Note that this happens despite the registerWithEureka: false property as basically even if the "self replica" is dodged, it still believes it is one.

Describe the solution you'd like

I would like to set a property like dev/standalone mode and not have to set several properties and have log warnings or strange behavior in the UI.

Describe alternatives you've considered

One way is to see if upstream will make the isThisMyUrl soft, but I guess it can't at its layer of abstraction as it cannot know the underlying server framework like boot can.

Another is the current workaround, which is to set myUrl explicitly to the default value of the client. This is in addition to the several other properties needed for single server. However, this creates UI errors that are worse than the glitch of self being in the unavailable servers list.

eureka:
  server:
    # Match the default of eureka.client.serviceUrl.defaultZone, so that the UI
    # Doesn't list this node twice, as an unavailable replica.
    myUrl: http://localhost:8761/eureka/

logging:
  level:
    # don't warn that there are no replica nodes
    com.netflix.eureka.cluster.PeerEurekaNodes: 'ERROR'

Additional context

Problem:

Screenshot 2024-02-09 at 13 51 21

Workaround: myUrl: http://localhost:8761/eureka/

Screenshot 2024-02-09 at 13 50 28

UI Error with workaround unless you add enableSelfPreservation: false

Screenshot 2024-02-09 at 14 20 39

UI Error when you add enableSelfPreservation: false

Screenshot 2024-02-09 at 14 27 33

Log warning with workaround unless you set com.netflix.eureka.cluster.PeerEurekaNodes: 'ERROR'

2024-02-09T14:24:03.021+07:00  WARN 20337 --- [           main] c.n.eureka.cluster.PeerEurekaNodes       : The replica size seems to be empty. Check the route 53 DNS Registry