Skip to content

Commit

Permalink
tests: Add a scenario for alert history feature
Browse files Browse the repository at this point in the history
This scenario checks that we can retrieve the
cluster alerts from the Loki API.

Refs: #3180
  • Loading branch information
alexandre-allard committed Mar 9, 2021
1 parent 7692268 commit cf2a791
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/post/features/logging.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ Feature: Logging stack is up and running
And the Loki API is available
And we have set up a logger pod
Then we can retrieve logs from logger pod in Loki API

Scenario: Retrieve cluster alerts from Loki
Given the Kubernetes API is available
And the Loki API is available
Then we can retrieve cluster alerts from Loki API
24 changes: 23 additions & 1 deletion tests/post/steps/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def query_log_from_loki(k8s_client, context):


@then("we can retrieve logs from logger pod in Loki API")
def retrieve_pod_logs_from_loki(k8s_client, nodename, pod_creation_ts):
def retrieve_pod_logs_from_loki(k8s_client, pod_creation_ts):
query = {
"query": '{pod="logger"}',
"start": pod_creation_ts,
Expand All @@ -185,6 +185,28 @@ def _check_log_line_exists():
)


@then("we can retrieve cluster alerts from Loki API")
def retrieve_cluster_alerts_from_loki(k8s_client):
query = {
"query": '{app="metalk8s-alert-logger"}',
}

def _check_log_line_exists():
response = query_loki_api(k8s_client, query, route="query_range")
try:
result_data = response[0]["data"]["result"][0]["values"]
except (IndexError, KeyError):
result_data = []
assert result_data, "No cluster alerts found in Loki"

utils.retry(
_check_log_line_exists,
times=40,
wait=5,
name="check that cluster alerts are logged in Loki",
)


# }}}

# Helpers {{{
Expand Down

0 comments on commit cf2a791

Please sign in to comment.