MeshxConsul.Ttl (MeshxConsul v0.1.0) View Source

Manages TTL health check workers used by mesh services.

Consul agent can use multiple kinds of checks, e.g. script checks, HTTP and TCP checks, gRPC and others.

MeshxConsul is using TTL (Time To Live) health checks for services started with MeshxConsul.start/4. Dedicated worker is used to periodically update service health check state over Consul agent HTTP interface.

Service health checks are defined using template argument of MeshxConsul.start/4. Default health check specification:

[
  ttl: %{
    id: "ttl:{{id}}",
    status: "passing",
    ttl: 5_000
  }
]

Health check keys:

  • :id - service id (value rendered using Mustache system),
  • :status - initial health check status,
  • :ttl - health check state update interval, milliseconds.

Health check state can be one of following: "passing", "warning" or "critical".

TTL checks are automatically started when running MeshxConsul.start/4 and stopped with MeshxConsul.stop/1. Users usually should not directly use start/2 and stop/1 functions defined in this module.

set_status/2 can be used to set service status depending on external conditions. One can for example use :os_mon :cpu_sup to monitor CPU utilization and update service status accordingly.

Example:

iex(1)> MeshxConsul.start("service1")
{:ok, "service1-h11", {:tcp, {127, 0, 0, 1}, 1024}}
iex(2)> MeshxConsul.Ttl.get_status("service1-h11")
"passing"
iex(3)> MeshxConsul.Ttl.set_status("service1-h11", "warning")
:ok
iex(4)> MeshxConsul.Ttl.get_status("service1-h11")
"warning"

Link to this section Summary

Functions

Gets TTL check worker status for service_id service.

Sets TTL check worker status for service_id service.

Starts TTL check worker for service_id service using ttl_opts.

Stops TTL check worker for service_id service.

Link to this section Functions

Specs

get_status(service_id :: atom() | String.t()) :: String.t()

Gets TTL check worker status for service_id service.

Link to this function

set_status(service_id, status)

View Source

Specs

set_status(service_id :: atom() | String.t(), status :: String.t()) :: :ok

Sets TTL check worker status for service_id service.

Link to this function

start(service_id, ttl_opts)

View Source

Specs

start(service_id :: atom() | String.t(), ttl_opts :: map()) ::
  DynamicSupervisor.on_start_child() | {:ok, nil}

Starts TTL check worker for service_id service using ttl_opts.

Specs

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

Stops TTL check worker for service_id service.