Skip to content

Commit

Permalink
tests: Add a test to ensure we can access Loki API
Browse files Browse the repository at this point in the history
This test is to ensure we can access a specific Loki
instance through the Services.
  • Loading branch information
alexandre-allard committed Jan 31, 2022
1 parent 4a6822f commit ad487fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
4 changes: 4 additions & 0 deletions tests/post/features/logging.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ Feature: Logging stack is up and running
Given the Kubernetes API is available
And the Loki API is available
Then we can retrieve 'Watchdog' alert from Loki API

Scenario: We can access a specific Loki instance
Given the Kubernetes API is available
Then the Loki API is available through Service 'loki-0'
37 changes: 23 additions & 14 deletions tests/post/steps/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,8 @@ def test_logging_pipeline_is_working(host):


@given("the Loki API is available")
def check_loki_api(k8s_client):
def _check_loki_ready():
# NOTE: We use Kubernetes client instead of DynamicClient as it
# ease the "service proxy path"
client = kubernetes.client.CoreV1Api(api_client=k8s_client.client)
try:
response = client.connect_get_namespaced_service_proxy_with_path(
"loki:http-metrics", "metalk8s-logging", path="ready"
)
except Exception as exc: # pylint: disable=broad-except
assert False, str(exc)
assert response == "ready\n"

utils.retry(_check_loki_ready, times=10, wait=2, name="checking Loki API ready")
def given_check_loki_api(k8s_client):
check_loki_api(k8s_client, "loki")


@given("we have set up a logger pod", target_fixture="pod_creation_ts")
Expand Down Expand Up @@ -232,6 +220,11 @@ def _check_alert_exists():
)


@then("the Loki API is available through Service '{service}'")
def then_check_loki_api(k8s_client, service):
check_loki_api(k8s_client, service)


# }}}

# Helpers {{{
Expand Down Expand Up @@ -260,4 +253,20 @@ def query_loki_api(k8s_client, content, route="query"):
return response


def check_loki_api(k8s_client, service):
def _check_loki_ready():
# NOTE: We use Kubernetes client instead of DynamicClient as it
# ease the "service proxy path"
client = kubernetes.client.CoreV1Api(api_client=k8s_client.client)
try:
response = client.connect_get_namespaced_service_proxy_with_path(
f"{service}:http-metrics", "metalk8s-logging", path="ready"
)
except Exception as exc: # pylint: disable=broad-except
assert False, str(exc)
assert response == "ready\n"

utils.retry(_check_loki_ready, times=10, wait=2, name="checking Loki API ready")


# }}}

0 comments on commit ad487fa

Please sign in to comment.