Health Class¶
Health¶
- class es_wait.health.Health(client: Elasticsearch, pause: float = 1.5, timeout: float = 15.0, max_exceptions: int = 10, check_type: Literal['status', 'relocation', 'cluster_routing'] = 'status', indices: List[str] | str | None = None, check_for: HealthCheckDict | None = None)¶
Bases:
WaiterWait for health check result to be the expected state
Initializes the Health waiter.
do_health_report()is set manually toTruefor this class so the parent class can log the health report results in the event something goes wrong.- Parameters:
check_type – The type of health check to perform: One of: - ‘status’: Wait for the cluster status to be ‘green’. - ‘relocation’: Wait for no relocating shards in specified indices. - ‘cluster_routing’: Wait for no relocating shards across all indices (ignores ‘indices’).
indices – Index or list of indices to check (ignored for ‘cluster_routing’)
check_for – Custom conditions to check in the health response. Default values: - For ‘check_type’ = ‘status’, {‘status’: ‘green’} - For ‘check_type’ = ‘relocation’ or ‘cluster_routing’, {‘relocating_shards’: 0}. Providing a value here overrides defaults.
- add_exception(value: Exception) None¶
This method appends value the exceptions list.
- Parameters:
value (Exception) – An exception to add
- announce() None¶
This method is called when the Waiter class is initialized. It logs a level 1 debug message using
waitstr.
- check() bool¶
This function calls
cluster.health()and, based on the value returned byhealthchk_result, will returnTrueorFalse.For ‘cluster_routing’, ‘indices’ is ignored, and all indices (‘*’) are checked.
- Returns:
True if the condition in ‘check_for’ is met, False otherwise.
- Return type:
- check_type¶
The entity name
- client¶
An
Elasticsearchclient instance
- do_health_report¶
Only changes to True in certain circumstances
- property exception_count_msg: str¶
This property returns a messgage showing the current number of exceptions raised and the maximum number of exceptions allowed.
- Getter:
Returns ‘X exceptions raised out of Y allowed’
- Type:
- property exceptions: list¶
This property returns a list of exceptions raised during the wait.
- Getter:
Returns a list of exceptions raised
- Type:
- exceptions_raised¶
The number of exceptions raised
- property filter_path: str¶
Define the filter_path based on
check_forThe health check response has only root-level keys, so there is no need to worry about nested keys in either
check_foror in the filter_path.- Getter:
Returns the proper filter_path
- Type:
- max_exceptions¶
The maximum number of exceptions to allow
- pause¶
The delay between checks for completion
- timeout¶
The number of seconds before giving up. -1 means no timeout.
- too_many_exceptions() None¶
If the number of exceptions raised is greater than or equal to the maximum number of exceptions allowed, then a
ExceptionCountwill be raised.
- wait(frequency: int = 5) None¶
This method is where the actual waiting occurs. Depending on what frequency is set to, you should see non-DEBUG level logs no more than every frequency seconds.
If
timeouthas been reached withoutcheck()returning asTrue, then aTimeoutErrorwill be raised.If
check()returnsFalse, then the method will waitpauseseconds before callingcheck()again.Elapsed time will be logged every frequency seconds, when
check()isTrue, or whentimeoutis reached.If
do_health_reportisTrue, then callclient.health_report()and pass the results toutils.health_report().- Parameters:
frequency – The number of seconds between log reports on progress.