airbnb / nerve

A service registration daemon that performs health checks; companion to airbnb/synapse
MIT License
942 stars 151 forks source link

Add option to Zookeeper reporter to periodically "touch" node #126

Closed panchr closed 4 years ago

panchr commented 4 years ago

Summary

This essentially implements a heartbeat mechanism for persistent nodes, in order to keep the node's mtime up-to-date.

Todo

Testing

For manual testing, I am verifying that:

  1. The node appears in Zookeeper.
  2. The node disappears automatically when Nerve is killed.
  3. In TTL mode, the node is repeatedly "touched." This is detected with the node's mtime (last modified time). Without TTL mode, the mtime should remain the same as the ctime.

Existing behavior (ephemeral)

- [x] no `mtime` updates

ctime: 2020-03-19 13:02:56 -0400 mtime: 2020-03-19 13:02:56 -0400


#### Existing behavior (persistent): node is registered and automatically removed
- [x] node is registered
```bash
+ zookeepercli -servers localhost:2181 -c ls /mango-test/services
base64_72_eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0=_
- [x] no `mtime` updates

ctime: 2020-03-19 13:06:04 -0400 mtime: 2020-03-19 13:06:04 -0400


#### New behavior (ephemeral): node is registered but never touched
- [x] node is registered
```bash
+ zookeepercli -servers localhost:2181 -c ls /mango-test/services
base64_72_eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0=_0000000000
- [x] no `mtime` updates

ctime: 2020-03-19 13:06:51 -0400 mtime: 2020-03-19 13:06:51 -0400


#### New behavior (persistent): node is registered and `mtime` is updated periodically
- [x] node is registered
```bash
+ zookeepercli -servers localhost:2181 -c ls /mango-test/services
base64_72_eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0=_
- [x] `mtime` updates

check 1

ctime: 2020-03-19 13:59:16 -0400 mtime: 2020-03-19 13:59:21 -0400

check 2

ctime: 2020-03-19 13:59:16 -0400 mtime: 2020-03-19 13:59:31 -0400

check 3:

ctime: 2020-03-19 13:59:16 -0400 mtime: 2020-03-19 13:59:41 -0400


*Nerve log*:

I, [2020-03-19T13:59:16.273885 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: background thread starting I, [2020-03-19T13:59:16.275529 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: wrote new ZK node of type persistent at /mango-test/services/base64_72eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0= I, [2020-03-19T13:59:16.275620 #57404] INFO -- Nerve::ServiceWatcher: nerve: service mango-test_26009_secure is now up I, [2020-03-19T13:59:21.296584 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/base64_72eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0= I, [2020-03-19T13:59:31.328048 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/base64_72eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0= I, [2020-03-19T13:59:41.367232 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/base64_72eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0=


#### New behavior (persistent): `mtime` is updated periodically when node already exists
- [x] node is not re-created
*Nerve log*

I, [2020-03-19T15:43:07.923040 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: tried to write node but exists, setting data instead


```bash
+ zookeepercli -servers localhost:2181 -c ls /mango-test/services
0001.mango-test_
- [x] `mtime` updates

check 1

ctime: 2020-03-19 15:43:07 -0400 mtime: 2020-03-19 15:43:12 -0400

check 2

ctime: 2020-03-19 15:43:07 -0400 mtime: 2020-03-19 15:43:23 -0400

check 3

ctime: 2020-03-19 15:43:07 -0400 mtime: 2020-03-19 15:43:33 -0400


*Nerve log*:

I, [2020-03-19T15:43:12.949821 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test I, [2020-03-19T15:43:23.013111 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test I, [2020-03-19T15:43:33.066686 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test I, [2020-03-19T15:43:43.119609 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test I, [2020-03-19T15:43:53.178126 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test_



## Reviewers
@austin-zhu @bsherrod 
cc: @anson627