andrzej-mag

andrzej-mag

Meshx - service mesh library - coming soon - preview.

Hello everyone,
Preview of Meshx library providing service mesh support.
Selected Meshx features are demonstrated with asciinema recordings. Tmux terminals are executed on separate vms (h11, h12, h21, etc.), each vm is running Consul Agent locally.

E1. MeshxNode and MeshxConsul introduction.

asciicast
First we start iex with epmd disabled and using MeshxNode protocol distribution (see top left corner terminal for iex command). MeshxConsul is configured as service mesh adapter for MeshxNode and will start “node service” in background.
We turn nodes into distributed running Node.start/1 and Node.set_cookie/2.
By default, MeshxConsul will use Consul Connect built-in proxy as a sidecar proxy; you can see proxy stdout in terminals.
We test node connectivity with Node.connect/1 and Node.list/0. Next we execute few functions exported by MeshxConsul:

  • list/0 - list services started on the node,
  • list_upstream/1 - list (node) service upstreams,
  • info/1 - service config as registered with Consul,
  • MeshxConsul.Proxy.info/1 - (node) service sidecar proxy info.

Finally we run spawn() and :erpc.call() to confirm erlang distribution compatibility with Meshx.

E2. MeshxNode: HA Erlang distribution.

asciicast
We start one upstream client node :cli@h11 (right) and two node service providers :service@any on h12 and h21 hosts (left).
We Node.connect/1 :cli@h11 to :service@any “node service” and use :erpc.call/4 with :inet.gethostname/0 to know which node was connected by sidecar proxy round-robin: connected node service is running on h21 host.
After stopping :service@any on h21 with Node.stop/0 and running :erpc.call/4 again:

  1. Service down event is detected by service mesh for service on h21. Traffic is automatically redirected by sidecar proxy to remaining “service@any” healthy instance on h12 discoverable with Consul registry.
  2. Erlang executes handshake with new node, valid cookies are still required.
  3. We receive response from healthy “service@any” h12 instance.

E3. MeshxRpc introduction.

asciicast
We start two nodes. First node :s1 (left) will provide service “service1”, second node :c1 (right) will consume upstream service “service1”.
First, we attach built-in pretty-printing (dev)Logger to :telemetry events using MeshxRpc.Common.Telemetry.attach/2 on our “service1” provider node.
Then we run MeshxConsul.start/4 to start new service “service1” with Envoy configured as a sidecar proxy. Starting a service involves inter alia: template parsing (Mustache), registration (Consul), running sidecar proxy (Envoy) and running service TTL health check worker (GenServer).
Next we start RPC server “used/implemented” in Example2.Server module and bind it to address generated earlier by MeshxConsul.start/4.

We execute similar bootstrapping process for service consumer. Instead of starting service we connect to upstream “service1” using MeshxConsul.connect/3.
Finally we run few Example2.Client functions to demonstrate basic MeshxRpc API.

User controlled MeshxRpc settings: msg block size (see telemetry “blocks”), msg block checksums, configurable serialization (telemetry “ser”/“dser”), configurable request auditing up to the socket/connection level (conn_ref, node_ref, svc_ref, req_ref, hsk_ref).
Library is using custom binary protocol and connection pooling.

E4. MeshxRpc: LB and HA.

asciicast
We start upstream client node :c1@h11 (right) and two :s1@h12 and :s1@h13 nodes, which will provide “service1” service. Example2.Client RPC client started on :c1@h11 is configured with 20 pool workers.

On client node :c1@h11 we Task.async/1 spawn 20 instances of call_do_work/0 function:

def call_do_work(), do: MeshxRpc.Client.Pool.call(Example2.Client, :do_work, Node.self())

Spawned tasks are load balanced between available service providers by sidecar proxy (round-robin by default). After killing top left service node we repeat spawning call_do_work/0. Remaining part of animation probably doesn’t require explanation, one can see expected HA behavior.

Comments.

Hashicorp Consul features valuable in discussed here context: intentions, observability, gateways, ACL, encryption.
Meshx is written in Elixir. Everything except some minor syntactic sugar API parts specific to Elixir Kernel.use/2 should work with Erlang (not tested yet).
MeshxConsul is implementing Meshx.ServiceMesh adapter behavior requiring four callbacks. Future mesh adapter implementations using other service mesh applications are possible (Kuma, Istio, others?) and should be compatible with MeshxNode and MeshxRpc.

References.

Hashicorp Consul: home, docs, tutorials.
Envoy Proxy: home, docs.
HAProxy Connect Consul integration: github.
Meshx: TBA.

Where Next?

Popular in Libraries Top

hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
tompave
Hello there, I would like to share a feature toggles library (AKA feature flags) I’ve been working on. The main package is FunWithFlags...
New
seancribbs
Today I released a new dialyzer Mix task as the dialyzex package! At the time we started writing this task, the existing dialyzer integra...
New
nikokozak
Hello all, I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
asiniy
Hey there! I wrote a download elixir package which does exactly what its name about - an easy way to download files. I saw solutions ...
New
benlime
I created a new library GitHub - benvp/ex_cva: Class Variance Authority for Elixir which aims to make it very easy to define different va...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
ericlathrop
I built a silly site for Halloween that uses Phoenix Channels on the backend, and React on the frontend. I had many problems integrating ...
New
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

Sub Categories:

We're in Beta

About us Mission Statement