GithubHelp home page GithubHelp logo

go-synapse's Introduction

Build Status

Synapse

Synapse is a Service discovery mechanism. It watch servers for services in a backend and report status in a router. This simplify service communication with backends and allow auto discovery & hot reconfiguration of the communication. This provide better services discovery and fault-tolerant communication between services

At BlaBlaCar, we use a synapse for each service node that want to communicate with another service and discover those backend nodes (> 2000). Nerve report node statuses to a Zookeeper and synapse watch it to update a local Hapoxy. All outgoing communication is going through this haproxy.

Airbnb

Go-Synapse is a go rewrite of Airbnb's Synapse with additional features.

Installation

Download the latest version on the release page.

Create a configuration file base on the doc or examples.

Run with ./synapse synapse-config.yml

Building

**** Just clone the repository and run ./gomake

Configuration

It's a YAML file. You can find examples here

Very minimal configuration file with only one service :

routers:
  - type: console
    eventsBufferDurationInMilli: 500
    services:
      - serverSort: random          # random, name, date
        watcher:
          type: zookeeper
          hosts: ['localhost:2181']
          path: /services/api/myapi
        serverOptions:              
          ...                       # depend on router type
        routerOptions:              
          ...                       # depend on router type

Root attributes:

logLevel: info
apiHost: 127.0.0.1
apiPort: 3454
routers:
    ...

Router config

Router console

Nothing special to configure for this router.

...
routers:
  - type: console
    services:
      - ...

Router haproxy

Router have haproxy specific attributes, but there is also services attributes

...
routers:
  - type: haproxy
    configPath: /tmp/hap.config
    reloadCommand: [./examples/haproxy_reload.sh]
    reloadTimeoutInMilli: 1000
    reloadMinIntervalInMilli: 500
    global:                                               # []string
      - stats   socket  /tmp/hap.socket level admin
    defaults:                                             # []string
    listen:                                               # map[string][]string
      stats:
         - mode http
         - bind 127.0.0.1:1936
         - stats enable

    services:
      - watcher:
          ...
        serverOptions: check inter 2s rise 3 fall 2
        routerOptions:
          frontend:
            - mode tcp
            - timeout client 31s
            - bind 127.0.0.1:5679
          backend:
            - mode tcp
            - timeout server 2m
            - timeout connect 45s

serverOptions support minimal templating:

serverOptions: cookie {{sha1String .Name}} check inter 2s rise 3 fall 2
serverOptions: cookie {{randString 10}} check inter 2s rise 3 fall 2
serverOptions: cookie {{.Name}} check inter 2s rise 3 fall 2

Router template

...
routers:
  - type: template
    destinationFile: /tmp/notexists/templated
    templateFile: ./examples/template.tmpl
    postTemplateCommand: [/bin/bash, -c, "echo 'ZZ' > /tmp/DDDD"]

    services:
      - watcher:
          ...

Services

routers:
  - type: ...

    services:
      - name: db-read
        watcher:
           ...
        serverCorrelation: # this will remove the first server declared in otherService from this service
          type: excludeServer
          otherServiceName: db-write
          scope: first

Watcher config

zookeeper watcher

routers:
  - type: ...

    services:
        - watcher:
            type: zookeeper
            hosts: [ 'localhost:2181', 'localhost:2182' ]
            path: /services/es/es_site_search
            timeoutInMilli: 2000

go-synapse's People

Contributors

n0rad avatar obiesmans avatar pborreli avatar sinfomicien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-synapse's Issues

Impement HapServerOptions cookie hash

We need a way to specify unique server options per host in a backend pool
Maybe with a template or an options that would create it.
ie:
The context is a backend in http mode with the cookie options to allow for a persistent connection -> HAP-doc for cookie
The rendered haproxy backend need to look like that.

#Random hash
    server rvp1 0.0.0.1:8080 cookie ccfda3 check inter 2000 rise 2 fall 5
    server rvp2 0.0.0.2:8080 cookie 542daf check inter 2000 rise 2 fall 5
    server rvp3 0.0.0.3:8080 cookie da35fd check inter 2000 rise 2 fall 5
    server rvp4 0.0.0.4:8080 cookie aed3e6 check inter 2000 rise 2 fall 5
#name
    server rvp1 0.0.0.1:8080 cookie rvp1 check inter 2000 rise 2 fall 5
    server rvp2 0.0.0.2:8080 cookie rvp2 check inter 2000 rise 2 fall 5
    server rvp3 0.0.0.3:8080 cookie rvp3 check inter 2000 rise 2 fall 5
    server rvp4 0.0.0.4:8080 cookie rvp4 check inter 2000 rise 2 fall 5
#Name generated Hash 
    server rvp1 0.0.0.1:8080 cookie 686cd833b4a1355d20644d287a0ecb31a2c842d1 check inter 2000 rise 2 fall 5
    server rvp2 0.0.0.2:8080 cookie 8954d3adc7c876ff818779f96418f70711aa2b1b check inter 2000 rise 2 fall 5
    server rvp3 0.0.0.3:8080 cookie 88faf1343a27c604746c1fcc4f23ccb39e9f622c check inter 2000 rise 2 fall 5
    server rvp4 0.0.0.4:8080 cookie 753a6bbed51939b3872022d8eb881186b11a6a4e check inter 2000 rise 2 fall 5

airnbnb-synapse implementation - implemented by @djnos
ps:
pod-lb -> varnish

shutdown wait receive new watcher during stop

panic: sync: WaitGroup is reused before previous Wait has returned

goroutine 150 [running]:
panic(0x83ce60, 0xc42037c000)
        /usr/lib/go/src/runtime/panic.go:500 +0x1a1
sync.(*WaitGroup).Wait(0xc420360790)
        /usr/lib/go/src/sync/waitgroup.go:133 +0xfe
github.com/blablacar/go-synapse/synapse.(*WatcherZookeeper).Watch(0xc4202c3180, 0xc4203ca060, 0xc420368110, 0xc4203ca000, 0xc420285550)
        /home/n0rad/Work/go/src/github.com/blablacar/go-synapse/synapse/watcher_zookeeper.go:63 +0x1b1
created by github.com/blablacar/go-synapse/synapse.(*RouterCommon).RunCommon
        /home/n0rad/Work/go/src/github.com/blablacar/go-synapse/synapse/router.go:57 +0x143

Api control weight

Allow the api to be able to dynamically set the weight of the current service.

start prometheus metrics at 0

At start a metric is not present.

if there where update failures and service is restarted, the metric will not be present and prometheus will consider as the previous value.

Retry on hap-reload

When hap is reloading , it send a signal to the old process to stop listening.
If the reload fails or timeout , hap cease to listen altogether.

We might need to implement a retry for such situation.

Show error when first HAP reload is done instead of panicking

##All-in-title

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x6751da]

goroutine 112 [running]:
panic(0x8828e0, 0xc4200120a0)
    /usr/lib/go/src/runtime/panic.go:500 +0x1a1
github.com/blablacar/go-synapse/vendor/github.com/n0rad/go-erlog.(*ErlogWriterAppender).logError(0xc420190620, 0xc420192230, 0xc420264380, 0xb32440, 0x0)
    /home/n0rad/Work/go/src/github.com/blablacar/go-synapse/vendor/github.com/n0rad/go-erlog/formatter.go:139 +0xaa
github.com/blablacar/go-synapse/vendor/github.com/n0rad/go-erlog.(*ErlogWriterAppender).logError(0xc420190620, 0xc420192230, 0xc420264380, 0xb32440, 0xc4201fea80)
    /home/n0rad/Work/go/src/github.com/blablacar/go-synapse/vendor/github.com/n0rad/go-erlog/formatter.go:185 +0x75b
github.com/blablacar/go-synapse/vendor/github.com/n0rad/go-erlog.(*ErlogWriterAppender).Fire(0xc420190620, 0xc420264380)
    /home/n0rad/Work/go/src/github.com/blablacar/go-synapse/vendor/github.com/n0rad/go-erlog/formatter.go:125 +0x8ec
github.com/blablacar/go-synapse/vendor/github.com/n0rad/go-erlog.(*ErlogLogger).log(0xc420190640, 0xc420264380)
    /home/n0rad/Work/go/src/github.com/blablacar/go-synapse/vendor/github.com/n0rad/go-erlog/logger.go:48 +0x5e
github.com/blablacar/go-synapse/vendor/github.com/n0rad/go-erlog.(*ErlogLogger).LogEntry(0xc420190640, 0xc4201fa540)
    /home/n0rad/Work/go/src/github.com/blablacar/go-synapse/vendor/github.com/n0rad/go-erlog/logger.go:141 +0xc4
github.com/blablacar/go-synapse/vendor/github.com/n0rad/go-erlog/logs.(*Entry).Error(0xc4201fa540, 0x913add, 0x23)
    /home/n0rad/Work/go/src/github.com/blablacar/go-synapse/vendor/github.com/n0rad/go-erlog/logs/entry.go:101 +0x5f
github.com/blablacar/go-synapse/synapse.(*RouterCommon).handleReport(0xc4200b7cc0, 0xc42000e400, 0x3, 0x4, 0xb3a440, 0xc4200b7cc0)
    /home/n0rad/Work/go/src/github.com/blablacar/go-synapse/synapse/router.go:139 +0x708
github.com/blablacar/go-synapse/synapse.(*RouterCommon).eventsProcessor.func1()
    /home/n0rad/Work/go/src/github.com/blablacar/go-synapse/synapse/router.go:83 +0x331
created by time.goFunc
    /usr/lib/go/src/time/sleep.go:154 +0x44

obiesmans work too much

After a long period of more than one year... I started to receive alerts about this repo i follow. All notifs from the same working guy, @obiesmans.

We need to force him to stop working so much... Otherwise our own developments will soon ignored, because available only far away in the git history.

At least we have to force him to squash. We didn't succeed to stop @n0rad from generating so many commits, we need to be more agressive this time, or the same story will happen again.

May God save our souls from being ignored in the git history.

By the way, @obiesmans nothing personal, only my ego don't want to be ignored. ๐Ÿ˜— ๐Ÿ’‹

Support multi-dc

being able to use a different watcher tree as backup of current tree to fallback to another DC when there is no service node anymore in current DC

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.