How watches get removed/deactivated

325 views
Skip to first unread message

靳禹

unread,
Apr 9, 2015, 5:20:49 AM4/9/15
to consu...@googlegroups.com
Hi all, 

I am just wondering if I have a service with a watch on it, and then I remove/deregister the service from Consul what would happen to the watch? As last time I asked, the authors said they do not have API to list all active watches of a given node. Per my understanding, watch without a handler will cause the watch run exactly once and output to stdout. With handler from console will keep the process running until the watch command gets killed. So basically it is saying if I want to dynamically configure, meaning add/remove/modify watches, I have to genreate/replace/remove watch json files in the conf directory of Consul, would that be the best practice as of now when use Consul watches?

Thanks in advance.

Michael Fischer

unread,
Apr 9, 2015, 12:25:13 PM4/9/15
to 靳禹, consu...@googlegroups.com
Suppose we did cancel all watchers of a given object whenever there are no more instances of that object in the cluster.  

How would we reliably distinguish between an intentional and unintentional complete removal of the object?

Thanks,

--Michael

--
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consul-tool...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Armon Dadgar

unread,
Apr 9, 2015, 1:37:23 PM4/9/15
to 靳禹, consu...@googlegroups.com
Hey,

I may be a bit confused here, but watchers are not tightly coupled to the services. You can have a long-running watcher,
even as a service is registered and deregistered. If you are trying to do something more programmatic, watchers are just
a convenient abstraction on top of blocking queries. For API driven use they maybe simpler than trying to add/remove
JSON based watch configuration.

Best Regards,
Armon Dadgar

靳禹 Jin

unread,
Apr 9, 2015, 10:07:55 PM4/9/15
to Armon Dadgar, consu...@googlegroups.com
Yes Armon, my concern is that if I run a watcher towards a non-exists service, will Consul be able to find there is no target to run watches against and therefore ignore the pertinent watches? It is more about performance consideration here. And for me, the watchers should be tightly coupled to services... What I am doing in my work now is to generate two json file at a time, one for service definition and checks, and one for a watcher upon the service. So when I remove the service from system, I can remove the watch definition all along to clean up everything.

Watchers to me is the convenient way to run things automatically instead of running cron jobs alike tasks to query APIs periodically.

I did not quiet understand the last sentence you stated here, could you please give an example or a link to an example maybe? From the documentation, I figured either one can add a json file to add a watch in consul or one should run the agent watch command and let that command run in background for long-running.

Cheers,
Jin

Armon Dadgar

unread,
Apr 13, 2015, 1:31:28 PM4/13/15
to 靳禹 Jin, consu...@googlegroups.com
Hey Jin,

It is not an issue to run a watched against an non-existing service. The watcher will just wait until the service does exist.
A watcher can also handle if a service loses all its instances (this is the same thing effectively).

If the watcher mechanism is convenient for you, then that might be the best approach. What I meant in the last
sentence is that you can write a bit of code using blocking queries (https://consul.io/docs/agent/http.html) which may
be simpler for your use case (I don’t have the context to know). Watchers are using that mechanism underneath the
covers.

Best Regards,
Armon Dadgar

靳禹 Jin

unread,
Apr 13, 2015, 9:21:17 PM4/13/15
to Armon Dadgar, consu...@googlegroups.com
Hi Armon,

Nice to hear from you, "What I meant in the last sentence is that you can write a bit of code ..." that's what I thought too, just to make sure :p In fact I am using both approaches at the moment, I have watchers to report logs/stats over the time to ElasticSearch meanwhile there are home-made queries for on-demand requests :D Great piece of work for Consul. Hopefully someday I could contribute some code to this nice software. "The watcher will just wait until the service does exist" this feature clearly sweeps out my concerns :D

Reply all
Reply to author
Forward
0 new messages