kobolog / gorb

IPVS on steroids – REST API, heartbeats, service discovery and more
GNU Lesser General Public License v3.0
809 stars 83 forks source link

Integration with libkv to store data persistently #39

Closed albamc closed 7 years ago

albamc commented 7 years ago

What I did

Currently, gorb stores L4 data only in memory, so all data is initialized when gorb is restarted. This PR saves the service / backend information generated by gorb to external kvstore (ex. Consul, etcd, zookeeper, boltdb) by using libkv and periodically reads this data and synchronizes it with gorb so that L4 data is retained even if gorb is restarted. I think that merge this PR can solve the following issues.

33 #30

How I did

How to test it

# execute gorb with options (assume use consul and it's address is 10.114.177.139:8500)
albamc@albamc-laptop:~/dev/github/albamc/gorb$ sudo ./gorb -f -i wlp1s0 -store consul://10.114.177.139:8500 -store-sync-time 3
INFO[0000] starting GORB Daemon v0.2                    
INFO[0000] initializing IPVS context                    
INFO[0000] Registered the REST service to Consul.       
ERRO[0000] error while get services: Key not found in store 
INFO[0000] setting up HTTP server on :4672              
ERRO[0003] error while get services: Key not found in store 
ERRO[0006] error while get services: Key not found in store 
# create service
  - If you use the gorb api, it also updates the data in kvstore.
  - Or edit kvstore directly
...
# restart gorb (cleanup IPVS before start)
albamc@albamc-laptop:~/dev/github/albamc/gorb$ sudo ipvsadm -C
albamc@albamc-laptop:~/dev/github/albamc/gorb$ sudo ./gorb -f -i wlp1s0 -store consul://10.114.177.139:8500 -store-sync-time 3
INFO[0000] starting GORB Daemon v0.2                    
INFO[0000] initializing IPVS context                    
INFO[0000] Registered the REST service to Consul.       
INFO[0000] creating virtual service [11.0.0.2-80-TCP] on 11.0.0.2:80 
INFO[0000] creating backend [11.0.0.5-80-TCP] on 11.0.0.5:80 for virtual service [11.0.0.2-80-TCP] 
INFO[0000] starting pulse for [11.0.0.2-80-TCP/11.0.0.5-80-TCP] 
INFO[0000] creating backend [11.0.0.3-80-TCP] on 11.0.0.3:80 for virtual service [11.0.0.2-80-TCP] 
INFO[0000] starting pulse for [11.0.0.2-80-TCP/11.0.0.3-80-TCP] 
INFO[0000] creating backend [11.0.0.4-80-TCP] on 11.0.0.4:80 for virtual service [11.0.0.2-80-TCP] 
INFO[0000] starting pulse for [11.0.0.2-80-TCP/11.0.0.4-80-TCP] 
INFO[0000] setting up HTTP server on :4672              
# check IPVS data is restored
albamc@albamc-laptop:~/dev/github/albamc/gorb$ sudo ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  11.0.0.2:http rr
  -> 11.0.0.3:http                Tunnel  100    0          0         
  -> 11.0.0.4:http                Tunnel  100    0          0         
  -> 11.0.0.5:http                Tunnel  100    0          0         

What to do

Added Options

albamc@albamc-laptop:~/dev/github/albamc/gorb$ ./gorb --help
Usage of ./gorb:
...
  -store string
        store url for sync data
  -store-backend-path string
        store backend path (default "backends")
  -store-service-path string
        store service path (default "services")
  -store-sync-time int
        sync-time for store (default 60)
...

Happy new year~

codecov-io commented 7 years ago

Current coverage is 96.93% (diff: 100%)

Merging #39 into master will not change coverage

@@             master        #39   diff @@
==========================================
  Files            13         13          
  Lines           196        196          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits            190        190          
  Misses            4          4          
  Partials          2          2          

Powered by Codecov. Last update 290a2a8...a72ac64

kobolog commented 7 years ago

Happy new year! I'll get back to it as soon as I'm back to civilzation, which is tomorrow!

kobolog commented 7 years ago

Hey, just added a few comments – could you also please rebase this PR so I could merge it?

kobolog commented 7 years ago

You also need to add libkv to glide deps list.

kobolog commented 7 years ago

Hey - sorry, I meant just adding dependencies to the glide.yaml file, not actually vendoring them =) The test script will automatically glide up to download everything when needed.

[EDIT]: actually, I take that back - forgot that we landed the standalone repo PR recently.

albamc commented 7 years ago

@kobolog I did rebase. In local environment, build is find but in travis, build fails even if I modify glide configs. If I add a vendor, it'll be fine but I do not know what you want to do. What should I to do before merge ?

kobolog commented 7 years ago

Hey, yeah - I added an edit to my previous comment about not vendoring stuff stating that I take it back, sorry about that. According to Travis, this is the symptom:

core/store.go:11:2: cannot find package "github.com/docker/libkv" in any of:
    /home/travis/gopath/src/github.com/kobolog/gorb/vendor/github.com/docker/libkv (vendor tree)
    /home/travis/.gimme/versions/go1.7.linux.amd64/src/github.com/docker/libkv (from $GOROOT)
    /home/travis/gopath/src/github.com/docker/libkv (from $GOPATH)

So I yeah your inital move to vendor the dependencies was the right one – let's vendor the dependencies required for this PR and then I'll merge this PR.

albamc commented 7 years ago

@kobolog I added the source for the build to the vendor. It was a little hard to git rebase for me :( I am sorry that the commit message is not written well in the rebase process.

kobolog commented 7 years ago

Great, thank you! I'm going to merge it now.

albamc commented 7 years ago

@kobolog Thanks~