Hi, I’m making this post to confirm whether my understanding is correct. I’m using Consul 1.16.1.
In my application, I actually have only one node which runs several functional services as Docker containers. These containers are registered to Consul by the Registrator service.
I’m writing another service that does this: When the system is booted up, poll Consul to get the health states of all the other functional services. When all the functional services become healthy, create a special file.
Right now, I’m calling /v1/health/checks/<service-name>
to get the health check states of each service in order to determine if the service is already healthy. However, it seems that the health state that’s returned by this endpoint is stale and it may return the health state from the previous run.
By reading Consul’s log, I noticed the log messages such as “Synced check”. It then occurred to me that Consul is deployed in a distributed structure. Even if it’s just one single node, there are still the two roles: server and agent. Then I found the post by Blake here which talks about the difference between the HTTP endpoint for the server and the HTTP endpoint for the agent. It seems that I have been using the endpoint that returns the information on the server instead of the agent, but it may take a bit time for the information to be synchronized from the agent to the server.
So am I correct that:
- It may take some nondeterministic period of time for the Consul local agent to synchronize the service/health check info to the Consul server, so before the information is synchronized, the info on the Consul server can be stale.
- If I want to get the updated health state of the functional services running on my node, I should probably call the HTTP endpoint for the agent which is
/v1/agent/health/service/<service-name>
. - Is the synchronization between the Consul server and the local agent(s) really nondeterministic? Is there a way to configure the synchronization? (I read somewhere that Consul uses gossip protocol to synchronize data so it’s not deterministic when that would happen, but I wonder if there is any way.)