defmodule Entropy do @moduledoc """ The public interface for the Entropy system. This module serves as the primary entry point for controlling the chaos daemon and querying its operational status. It abstracts the underlying GenServer calls to the `Entropy.State` namespace. ## Purpose * **Status Reporting:** Query the liveness and safety state of the system. * **Runtime Control:** Trigger configuration reloads without restarting the node. """ alias Entropy.Config alias Entropy.State.CircuitBreaker alias Entropy.State.Scheduler @doc """ Determines if the Entropy supervision tree is active. Returns `true` if the `Entropy.Supervisor` process exists and is alive, otherwise `false`. """ @spec is_alive?() :: boolean() def is_alive? do case Process.whereis(Entropy.Supervisor) do nil -> false pid when is_pid(pid) -> Process.alive?(pid) end end @doc """ Determines if the system environment permits fault injection. Queries the `CircuitBreaker` to verify that system metrics (CPU, Memory) are within defined safety thresholds. Returns `true` only if the circuit breaker reports a safe state. """ @spec is_ready?() :: boolean() def is_ready? do case CircuitBreaker.get_safety_report() do {:ok, _metrics} -> true {:unsafe, _metrics} -> false end end @doc """ Reloads runtime configuration parameters. Fetches the latest values from `Entropy.Config` and pushes updates to: 1. **Scheduler:** Updates the injection frequency (`injection_interval_ms`). 2. **CircuitBreaker:** Updates safety thresholds (`max_cpu_util_percent`, `max_memory_util_percent`). This function allows tuning the aggression of the tool without a restart. """ @spec reload_config() :: :ok def reload_config do injection_interval_ms = Config.injection_interval_ms() max_cpu_util_percent = Config.max_cpu_util_percent() max_memory_util_percent = Config.max_memory_util_percent() fault_strategy_weights = Config.fault_strategy_weights() Scheduler.set_injection_interval(injection_interval_ms) Scheduler.set_fault_strategy_weights(fault_strategy_weights) CircuitBreaker.set_thresholds( max_cpu_util_percent, max_memory_util_percent ) :ok end end