-
Notifications
You must be signed in to change notification settings - Fork 29
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
undefined method `[]' for #<Consul::Async::ConsulTemplateNodes:0x000055744a631640> #74
Comments
Looking at more logs, I'm also seeing a few:
I assume it's the same issue. |
Hello @jeromegn, Well, there is a reason (which sucks) for this behavior. If you list nodes using In such case, the value read by consul-templaterb would be nil, which does not contains This can be reproduced trivially with this ERB code: <%
node('a_nodes_that_does_not_exists')['Services']
%> This sucks a bit, I agree, in theory, we should have an helper to check this. How to avoid this?There is no way the root cause could be prevented easily because the operations inside the clusters would be hard to get in a "transactional way". However, it is possible to do the following: <%=
res = node('a_nodes_that_does_not_exists')
unless res.result.is_a?(Hash)
{} # alternative, return nil if you want to decide between node without service and node that does not exists
else
res['Services']
end
%> if you want to use this in many places, you can also have a function to do that: <%
def get_services_for_node(node_name)
res = node(node_name)
return res['Services'] if res.result.is_a?(Hash)
{} # services is actually an Hash
end
%>
<%=
get_services_for_node("a_node_that_does_not_exists")
%> Other ConsiderationsTo be fair, we did not used that much this function on our clusters as it gives poor performance with many nodes since you have to interact with every node (and this creates lots of calls). I also found that actually, there is a little bug on init time where node() -> is initialized with Regards |
Provide new helpers for node() result Also fix default valud to be an Hash, not an array
Our nodes are never deregistered really, they never change. Unless a short restart might cause this? We very rarely restart them, but I'm seeing this across the board from time to time. Could it also be caused by a transient network issue? |
Yes, restart of a node might explain it maybe, but not a network transient issue (Consul is supposed to be protected against that) |
Is there a better way to get all services (with all their data)? Using |
Perhaps we should've named all our services with the same name (or the same few names) and used the |
We I used to work at Criteo, that's what we did: we had 4000+ services, with around 260k+ instances, we did list all services to have an aggregated view of all services (this is exactly what is done in https://github.com/criteo/consul-templaterb/blob/master/samples/consul-ui/consul_services.json.erb). The big bonus is that you also have the status of all the services at the same time |
Added new utility methods to fix #74
Thank you @kamaradclimber for merging this! Do you think you might be able to do a release as well? |
FWIW: we're going to be slowly transitioning to non-unique service names and this should help a lot with Consul issues we've been having (including this one). |
We're seeing sporadic
in our logs.
This is coming from a
node(node_id)["Services"]
call.We're currently on consul-templaterb version 1.29.0, running consul 1.9.1.
Since this works 99% of the time, I'm not sure where the issue is coming from. Perhaps it hasn't resolved to the consul response yet?
The text was updated successfully, but these errors were encountered: