Logic for building and processing check results.
Summary
Functions
Builds a result map from a check definition and a check result tuple.
Builds a result from an exception.
Builds a result for a timeout situation.
Determines the overall health status from a summary.
Calculates a summary from a list of results.
Converts a raw check result tuple to a status and message.
Functions
@spec build(Botica.Types.check_def(), Botica.Types.status(), String.t()) :: Botica.Types.result()
Builds a result map from a check definition and a check result tuple.
Examples
iex> check = %{id: :test, name: "Test", fix_command: "fix it"}
iex> Botica.Check.Result.build(check, :ok, "everything fine")
%{id: :test, name: "Test", status: :ok, message: "everything fine", fix_command: "fix it"}
@spec from_exception(Botica.Types.check_def(), Exception.t()) :: Botica.Types.result()
Builds a result from an exception.
Examples
iex> check = %{id: :boom, name: "Boom", fix_command: nil}
iex> result = Botica.Check.Result.from_exception(check, %RuntimeError{message: "oops"})
iex> result.status
:error
iex> result.message
"exception: oops"
@spec from_timeout(Botica.Types.check_def(), non_neg_integer()) :: Botica.Types.result()
Builds a result for a timeout situation.
Examples
iex> check = %{id: :slow, name: "Slow", fix_command: nil}
iex> result = Botica.Check.Result.from_timeout(check, 5000)
iex> result.status
:error
iex> result.message
"timeout: check exceeded 5000ms"
@spec health_status(Botica.Types.summary()) :: :ok | :degraded | :fail
Determines the overall health status from a summary.
Examples
iex> Botica.Check.Result.health_status(%{error: 0, warning: 0})
:ok
iex> Botica.Check.Result.health_status(%{error: 0, warning: 1})
:degraded
iex> Botica.Check.Result.health_status(%{error: 1, warning: 0})
:fail
@spec summarize([Botica.Types.result()]) :: Botica.Types.summary()
Calculates a summary from a list of results.
Examples
iex> results = [
...> %{status: :ok},
...> %{status: :ok},
...> %{status: :warning},
...> %{status: :error}
...> ]
iex> Botica.Check.Result.summarize(results)
%{ok: 2, warning: 1, error: 1, total: 4, passed?: false}
@spec to_status(Botica.Types.check_result()) :: {Botica.Types.status(), String.t()}
Converts a raw check result tuple to a status and message.
Examples
iex> Botica.Check.Result.to_status({:ok, "good"})
{:ok, "good"}
iex> Botica.Check.Result.to_status({:warning, "low memory"})
{:warning, "low memory"}
iex> Botica.Check.Result.to_status({:error, "connection failed"})
{:error, "connection failed"}