airbnb / nerve

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

Add path encoding optimization #114

Closed anson627 closed 5 years ago

anson627 commented 5 years ago

Summary:

  1. encode zk child name with base64 encoding including ip, port, labels
  2. guard feature with flag use_path_encoding so default behavior doesn't change
  3. ensure backward compatibility: nerve with path encoding enabled works with old version of synapse safely
  4. use variable length decoding to make schema more flexible: a. prefix is optional encoded json b. suffix is optional sequence number
  5. make encoding more producer driven a. feature is enabled based on child name prefixed with protocol name base64_ b. json content is decided by data parsing, no fields picking

The counterpart synapse change: https://github.com/airbnb/synapse/pull/296

Test Plan:

test nerve config file:

{
  "instance_id": "macbook-pro",
  "listen_port": 1025,
  "services": {
    "mango-test_26009_secure": {
      "port": 3000,
      "check_interval": 2,
      "checks": [
        {
          "type": "tcp",
          "timeout": 1,
          "rise": 2,
          "fall": 2
        },
        {
          "type": "http",
          "uri": "/health",
          "timeout": 0.5,
          "rise": 2,
          "fall": 2,
          "host": "127.0.0.1",
          "port": 3000 
        }
      ],
      "zk_hosts": [
        "127.0.0.1:2181"
      ],
      "zk_path": "/mango-test/services",
      "host": "127.0.0.1",
      "labels": {
        "region": "us-east-1",
        "az": "us-east-1a"
      },
      "use_path_encoding": true
    }
  }
}
nerve --config nerve.json
I, [2019-07-02T18:33:45.876228 #2405]  INFO -- Nerve::Nerve: nerve: setting up!
I, [2019-07-02T18:33:45.878518 #2405]  INFO -- Module: nerve: configuring statsd on host 'localhost' port 8125
I, [2019-07-02T18:33:45.878547 #2405]  INFO -- Nerve::Nerve: nerve: starting main run loop
I, [2019-07-02T18:33:45.879281 #2405]  INFO -- Nerve::Nerve: nerve: loading config
I, [2019-07-02T18:33:45.879754 #2405]  INFO -- Module: nerve: configuring statsd on host 'localhost' port 8125
I, [2019-07-02T18:33:45.880121 #2405]  INFO -- Nerve::Nerve: nerve: launching new watchers: ["mango-test_26009_secure"]
I, [2019-07-02T18:33:45.928838 #2405]  INFO -- Nerve::ServiceWatcher: nerve: starting service watch mango-test_26009_secure
I, [2019-07-02T18:33:45.929018 #2405]  INFO -- Nerve::Reporter::Zookeeper: nerve: waiting to connect to zookeeper cluster 127.0.0.1:2181 hosts 127.0.0.1:2181
I, [2019-07-02T18:33:45.929046 #2405]  INFO -- Nerve::Reporter::Zookeeper: nerve: creating pooled connection to 127.0.0.1:2181
I, [2019-07-02T18:33:45.933940 #2405]  INFO -- Nerve::Reporter::Zookeeper: nerve: successfully created zk connection to 127.0.0.1:2181
I, [2019-07-02T18:33:45.934014 #2405]  INFO -- Nerve::Reporter::Zookeeper: nerve: retrieved zk connection to 127.0.0.1:2181
I, [2019-07-02T18:33:45.934834 #2405]  INFO -- Nerve::ServiceCheck::TcpServiceCheck: nerve: service check mango-test_26009_secure tcp-127.0.0.1:3000 initial check returned true
I, [2019-07-02T18:33:45.935975 #2405]  INFO -- Nerve::ServiceCheck::HttpServiceCheck: nerve: service check http-127.0.0.1:3000/health initial check returned true
I, [2019-07-02T18:33:45.937905 #2405]  INFO -- Nerve::ServiceWatcher: nerve: service mango-test_26009_secure is now up
zkCli ls /mango-test/services
Connecting to localhost:2181

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6MzAwMCwibGFiZWxzIjp7ImF6IjoidXMtZWFzdC0xYSJ9fQ==_0000000008]

compatibility test: mango-test (synapse 0.16.13)-> mango-production (nerve 0.9.0)

mango-production-enabled old synapse with new nerve

mango-test (synapse 0.17.0) -> mango-production (nerve 0.9.0)

Screen Shot 2019-07-03 at 5 30 42 PM

mango-test (synapse 0.17.0) -> mango-canary (nerve 0.8.8)

Screen Shot 2019-07-03 at 5 31 59 PM

Reviewers:

@allenlsy @austin-zhu @Jason-Jian @Ramyak