MeshxConsul.Proxy (MeshxConsul v0.1.0) View Source

Manages sidecar service proxy binary command.

Service mesh data plane is using system of connected proxies managed by control plane application for service communication. Module is managing starting, stopping and restarting proxies binary commands. Proxies should be automatically started running MeshxConsul.start/4 and stopped with MeshxConsul.stop/1.

Command running proxy binary for given service is passed as service template argument to MeshxConsul.start/4. Default proxy command will start Consul Connect proxy with error log-level and will use /bin/sh as shell:

[proxy: ["/bin/sh", "-c", "consul connect proxy -log-level err -sidecar-for {{id}}"]]

Command will be rendered using Mustache system, check MeshxConsul documentation for details.

Example proxy command starting Envoy Proxy:

[proxy: ["/bin/sh", "-c", "consul connect envoy -sidecar-for {{id}} -- -l error"]]

Note: Consul application version must be compatible with provided Envoy binary, see: Consul documentation.

Proxy binary command must be able to communicate with Consul: agent instance address and ACL token must be provided. Configuration may be provided as shell environment variable defined by :cli_env key in config.exs or directly using proxy command. Environment variable is preferred when passing secrets.

Link to this section Summary

Functions

Returns info about service_id service proxy worker.

Restarts proxy binary for service_id service.

Starts long-running proxy binary cmd for service_id service.

Stops service_id service proxy.

Link to this section Functions

Specs

info(service_id :: atom() | String.t()) :: %{
  cmd: String.t(),
  restarts: non_neg_integer()
}

Returns info about service_id service proxy worker.

Function result if successful is map with two keys:

  • :cmd - contains Mustache rendered command that was used to start proxy binary,
  • :restarts - equal to number of proxy restarts due to proxy command failure.

Exits if service_id worker is not running.

iex(1)> MeshxConsul.start("service1")
{:ok, "service1-h11", {:tcp, {127, 0, 0, 1}, 1024}}
iex(2)> MeshxConsul.Proxy.info("service1-h11")
%{
  cmd: ["/bin/sh", "-c",
    "consul connect proxy -log-level err -sidecar-for service1-h11"],
  restarts: 0
}

Specs

restart(service_id :: atom() | String.t()) :: :ok

Restarts proxy binary for service_id service.

iex(1)> MeshxConsul.start("service1")
{:ok, "service1-h11", {:tcp, {127, 0, 0, 1}, 1024}}
iex(2)> MeshxConsul.Proxy.restart("service1-h11")
:ok

Specs

start(service_id :: atom() | String.t(), cmd :: [String.t()]) ::
  DynamicSupervisor.on_start_child() | {:ok, nil}

Starts long-running proxy binary cmd for service_id service.

Specs

stop(service_id :: atom() | String.t()) :: :ok | {:error, :not_found}

Stops service_id service proxy.