elastic.krkn_elastic module

class elastic.krkn_elastic.KrknElastic(safe_logger: SafeLogger, elastic_url: str, elastic_port: int = 443, verify_certs: bool = False, username: str | None = None, password: str | None = None)

Bases: object

__init__(safe_logger: SafeLogger, elastic_url: str, elastic_port: int = 443, verify_certs: bool = False, username: str | None = None, password: str | None = None)
es = None
push_alert(alert: ElasticAlert, index: str) int

Pushes an ElasticAlert object to elastic

Parameters:
  • alert – the populated ElasticAlert object

  • index – the index where the ElasticAlert Object is pushed

Returns:

the time needed to save if succeeded -1 if failed

push_metric(metric: ElasticMetric, index: str) int

Pushes an ElasticMetric object to elastic

Parameters:
  • metric – the populated ElasticMetric object

  • index – the index where the ElasticMetric Object is pushed

Returns:

the time needed to save if succeeded -1 if failed

push_telemetry(telemetry: ChaosRunTelemetry, index: str)
search_alert(run_uuid: str, index: str) list[ElasticAlert]

Searches ElasticAlerts by run_uuid :param run_uuid: the Krkn run id to search :param index: the index where the ElasticAlert

should have been saved

Returns:

the list of objects retrieved (Empty if nothing has been found)

search_metric(run_uuid: str, index: str) list[ElasticMetric]

Searches ElasticMetric by run_uuid :param run_uuid: the Krkn run id to search :param index: the index where the ElasticAlert

should have been saved

Returns:

the list of objects retrieved (Empty if nothing has been found)

search_telemetry(run_uuid: str, index: str)

Searches ElasticChaosRunTelemetry by run_uuid :param run_uuid: the Krkn run id to search :param index: the index where the ElasticChaosRunTelemetry

should have been saved

Returns:

the list of objects retrieved (Empty if nothing has been found)

upload_data_to_elasticsearch(item: dict, index: str = '') int

uploads captured data in item dictionary to Elasticsearch

Parameters:
  • item – the data to post to elastic search

  • index – the elastic search index pattern to post to

Returns:

the time taken to post the result, will be 0 if index and es are blank

upload_metrics_to_elasticsearch(run_uuid: str, raw_data: list[dict[str, str | int | float]], index: str) int

Saves raw data returned from the Krkn prometheus client to elastic search as a ElasticMetric object raw data will be a mixed types dictionary in the format {“name”:”str”, “values”:[(10, ‘3.14’), (11,’3.15’)…..]

Parameters:
  • run_uuid – the krkn run id

  • raw_data – the mixed type dictionary (will be validated checking the attributes types )

  • index – the elasticsearch index where the object will be stored

Returns:

the time needed to save if succeeded -1 if failed