Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

blablacar/go-synapse

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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