Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pod perf checks for multiple namespaces #2934

Merged
merged 8 commits into from
Aug 25, 2022
Prev Previous commit
Next Next commit
Add perf check for VirtualServers
vepatel committed Aug 22, 2022
commit db275c02a79e83b53a411f377c909b2ddb09f74a
125 changes: 104 additions & 21 deletions tests/suite/test_multiple_ns_perf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import time
from typing import Dict
import pytest
import yaml
import subprocess

from suite.resources_utils import (
create_namespace_with_name_from_yaml,
delete_namespace,
@@ -18,10 +17,20 @@
from suite.custom_resources_utils import (
get_pod_metrics,
)
watched_namespaces=""
from suite.yaml_utils import get_first_ingress_host_from_yaml
from suite.vs_vsr_resources_utils import create_virtual_server
from settings import TEST_DATA

watched_namespaces = ""

def collect_metrics(request, namespace, metric_dict) -> Dict:
""" Get pod metrics and write them to a json"""

metrics = get_pod_metrics(request, namespace)
metric_dict[f"{request.node.name}+{time.time()}"] = metrics
write_to_json(f"pod-metrics-{get_test_file_name(request.node.fspath)}.json", metric_dict)

return metrics

@pytest.fixture(scope="class")
def ingress_ns_setup(
request,
@@ -33,57 +42,131 @@ def ingress_ns_setup(
:param request: pytest fixture
:param kube_apis: client apis
"""

manifest = f"{TEST_DATA}/smoke/standard/smoke-ingress.yaml"
ns_count = int(request.config.getoption("--ns-count"))
multi_ns=""
multi_ns = ""
for i in range(1, ns_count + 1):
watched_namespace = create_namespace_with_name_from_yaml(
kube_apis.v1, f"ns-{i}", f"{TEST_DATA}/common/ns.yaml"
)
multi_ns = multi_ns+f"{watched_namespace},"
multi_ns = multi_ns + f"{watched_namespace},"
create_example_app(kube_apis, "simple", watched_namespace)
secret_name = create_secret_from_yaml(
kube_apis.v1, watched_namespace, f"{TEST_DATA}/smoke/smoke-secret.yaml"
)
with open(manifest) as f:
doc = yaml.safe_load(f)
doc["metadata"]["name"] = f"smoke-ingress-{i}"
doc["spec"]["rules"][0]["host"] = f"smoke-{i}.example.com"
create_ingress(kube_apis.networking_v1, watched_namespace, doc)
global watched_namespaces
doc = yaml.safe_load(f)
doc["metadata"]["name"] = f"smoke-ingress-{i}"
doc["spec"]["rules"][0]["host"] = f"smoke-{i}.example.com"
create_ingress(kube_apis.networking_v1, watched_namespace, doc)
global watched_namespaces
watched_namespaces = multi_ns[:-1]
for i in range(1, ns_count + 1):
wait_until_all_pods_are_ready(kube_apis.v1, f"ns-{i}")

def fin():
for i in range(1, ns_count + 1):
delete_namespace(kube_apis.v1, f"ns-{i}")

request.addfinalizer(fin)


@pytest.mark.multi_ns
class TestMultipleSimpleIngress:
"""Test to output CPU/Memory perf metrics for pods with multiple namespaces"""
"""Test to output CPU/Memory perf metrics for pods with multiple namespaces (Ingresses)"""

def test_ingress_multi_ns(
self,
request,
kube_apis,
cli_arguments,
ingress_ns_setup,
ingress_controller_prerequisites,
):
):
metric_dict = {}
namespace = ingress_controller_prerequisites.namespace
extra_args = ["-enable-custom-resources=false", f"-watch-namespace={watched_namespaces}"]
name = create_ingress_controller(kube_apis.v1, kube_apis.apps_v1_api, cli_arguments, namespace, extra_args)
metrics = get_pod_metrics(request,namespace)
metric_dict[f"{request.node.name}+{time.time()}"] = metrics
write_to_json(
f"pod-metrics-{get_test_file_name(request.node.fspath)}.json",
metric_dict
name = create_ingress_controller(
kube_apis.v1, kube_apis.apps_v1_api, cli_arguments, namespace, extra_args
)
metrics = collect_metrics(request, namespace, metric_dict)
delete_ingress_controller(
kube_apis.apps_v1_api, name, cli_arguments["deployment-type"], namespace
)
delete_ingress_controller(kube_apis.apps_v1_api, name, cli_arguments['deployment-type'], namespace)

assert metrics


##############################################################################################################


@pytest.fixture(scope="class")
def vs_ns_setup(
request,
kube_apis,
crds,
) -> None:
"""
Create and deploy namespaces, apps and ingresses
:param request: pytest fixture
:param kube_apis: client apis
:param crds: deploy Custom resource definitions
"""

manifest = f"{TEST_DATA}/virtual-server/standard/virtual-server.yaml"
ns_count = int(request.config.getoption("--ns-count"))
multi_ns = ""
for i in range(1, ns_count + 1):
watched_namespace = create_namespace_with_name_from_yaml(
kube_apis.v1, f"ns-{i}", f"{TEST_DATA}/common/ns.yaml"
)
multi_ns = multi_ns + f"{watched_namespace},"
create_example_app(kube_apis, "simple", watched_namespace)
with open(manifest) as f:
doc = yaml.safe_load(f)
doc["metadata"]["name"] = f"virtual-server-{i}"
doc["spec"]["host"] = f"virtual-server-{i}.example.com"
create_virtual_server(kube_apis.custom_objects, doc, watched_namespace)
global watched_namespaces
watched_namespaces = multi_ns[:-1]
for i in range(1, ns_count + 1):
wait_until_all_pods_are_ready(kube_apis.v1, f"ns-{i}")

def fin():
for i in range(1, ns_count + 1):
delete_namespace(kube_apis.v1, f"ns-{i}")

request.addfinalizer(fin)


@pytest.mark.multi_ns_vs
class TestMultipleVS:
"""Test to output CPU/Memory perf metrics for pods with multiple namespaces (VirtualServers)"""

def test_vs_multi_ns(
self,
request,
kube_apis,
cli_arguments,
vs_ns_setup,
ingress_controller_prerequisites,
):
metric_dict = {}
namespace = ingress_controller_prerequisites.namespace
extra_args = ["-enable-custom-resources=True", f"-watch-namespace={watched_namespaces}"]
name = create_ingress_controller(
kube_apis.v1,
kube_apis.apps_v1_api,
cli_arguments,
namespace,
extra_args,
)
metrics = collect_metrics(request, namespace, metric_dict)
delete_ingress_controller(
kube_apis.apps_v1_api, name, cli_arguments["deployment-type"], namespace
)

assert metrics