Skip to content

Limani Core

chaos.lib.limani.limani

Abstract base class for Limani logbook and telemetry database drivers.

Limani

Bases: ABC

Abstract base class for Limani implementations.

Notes

Limanis are responsible for connecting to, setting, getting and disconnecting From databases or other data sources.

They are meant to give an endpoint-agnostic interface to the Logbook system.

The Logbook should require a Limani to be used as its data source.

The Limanis should be easily pluggable, so that different data sources can be used. Also, the only abstract methods should be required to be implemented by the subclasses.

The only abstract methods required are connect, disconnect, set, get, export, init_db.

__init__(config)

Initializes the Limani with the given configuration.

Parameters:

Name Type Description Default
config dict

A dictionary containing configuration parameters.

required

connect() abstractmethod

Connects to the data source.

Returns:

Name Type Description
Any Any

A connection object or similar depending on the subclass implementation.

create_run(run_id, run_id_human, start_time, hailer_info, needed_secrets) abstractmethod

Creates a new run entry in the database.

Parameters:

Name Type Description Default
run_id str

The ID of the run.

required
run_id_human str

The human-readable ID of the run.

required
start_time float

The start time of the run.

required
hailer_info dict

The hailer information of the run.

required

Returns:

Name Type Description
str str

The ID of the created run.

disconnect() abstractmethod

Disconnects from the data source.

end_run_update(run_id, end_time, status, summary) abstractmethod

Updates a run at the end with final status, time, and summary.

Parameters:

Name Type Description Default
run_id str

The ID of the run to update.

required
end_time float

The end time of the run.

required
status str

The final status of the run.

required
summary dict

The summary of the run.

required

get_facts_for_timespan(run_id, start_time, end_time) abstractmethod

Gets all facts for a given run within a specific time span.

Parameters:

Name Type Description Default
run_id str

The ID of the run to get facts for.

required
start_time float

The start time of the time span.

required
end_time float

The end time of the time span.

required

Returns:

Type Description
list[dict[str, str | int | float]]

list[dict]: A list of fact logs within the specified time span.

get_or_create_host(run_id, host_name) abstractmethod

Gets or creates a host in the data source.

Parameters:

Name Type Description Default
run_id str

The ID of the host the host belongs to.

required
host_name str

The name of the host to get or create.

required

Returns:

Name Type Description
int int

The ID of the host.

Notes

Should be idempotent.

get_run_data(run_id) abstractmethod

Gets all data for a given run.

Parameters:

Name Type Description Default
run_id str

The ID of the run to get data for.

required

Returns:

Name Type Description
dict dict[str, Any]

A dictionary containing all data for the run.

get_run_summary_stats(run_id) abstractmethod

Gets summary statistics for a given run.

Parameters:

Name Type Description Default
run_id str

The ID of the run to get summary statistics for.

required

Returns:

Name Type Description
dict dict[str, int | float | str]

A dictionary containing summary statistics for the run.

init_db() abstractmethod

Initializes the data source.

Notes

This should create any necessary tables or structures in the data source. This should only create if not exists.

insert_fact_log(run_id, timestamp, log_level, context, command) abstractmethod

Inserts a fact log into the data source.

Parameters:

Name Type Description Default
run_id str

The ID of the run the fact log belongs to.

required
timestamp float

The timestamp of the fact log.

required
log_level str

The log level of the fact log.

required
context str

The context of the fact log.

required
command str

The command of the fact log.

required

insert_operation(run_id, host_id, op_hash, name, changed, success, duration, timestamp, logs, diff, arguments, retry_stats, command_n_facts) abstractmethod

Inserts an operation into the data source.

Parameters:

Name Type Description Default
run_id str

The ID of the run the operation belongs to.

required
host_id int

The ID of the host the operation belongs to.

required
op_hash str

The hash of the operation.

required
name str

The name of the operation.

required
changed bool

Whether the operation changed anything.

required
success bool

Whether the operation was successful.

required
duration float

The duration of the operation.

required
timestamp float

The timestamp of the operation.

required
logs dict

The logs of the operation.

required
diff str

The diff of the operation.

required
arguments dict

The arguments of the operation.

required
retry_stats dict

The retry stats of the operation.

required
command_n_facts list

The command and facts associated with the operation.

required

insert_snapshot(run_id, host_id, stage, timestamp, metrics) abstractmethod

Inserts a resource snapshot into the data source.

Parameters:

Name Type Description Default
run_id str

The ID of the run the snapshot belongs to.

required
host_id int

The ID of the host the snapshot belongs to.

required
stage str

The stage of the snapshot.

required
timestamp float

The timestamp of the snapshot.

required
metrics dict

The metrics of the snapshot.

required

start_update_run(run_id, status) abstractmethod

Updates the status of a run in the data source.

Parameters:

Name Type Description Default
run_id str

The ID of the run to update.

required
status str

The new status of the run.

required