Skip to content

Commit

Permalink
Merge pull request #780 from mdujava/opentelemetry_apicast_kind
Browse files Browse the repository at this point in the history
Add opentelemetry test for SystemApicast
  • Loading branch information
mkudlej authored Jan 24, 2024
2 parents 9af917e + e7ffd1c commit 4a2148b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 7 deletions.
6 changes: 6 additions & 0 deletions testsuite/gateways/apicast/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ def _update(apicast):
self.apicast.modify_and_apply(_update)
self.reload()

def disconnect_open_telemetry(self, *args):
"""
Current tests delete apicast after opentelemetry tests, cleanup of the
apicast itself will clean all configuration for opentelemetry as well
"""

def connect_open_telemetry(self, jaeger):
"""
Modifies the APIcast to send information to jaeger.
Expand Down
24 changes: 22 additions & 2 deletions testsuite/gateways/apicast/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

import backoff

from openshift import OpenShiftPythonException

from testsuite.capabilities import Capability
from testsuite.gateways.apicast import AbstractApicast
from testsuite.openshift.env import Properties
from testsuite.utils import randomize

if TYPE_CHECKING:
from typing import Optional
Expand Down Expand Up @@ -47,7 +50,16 @@ def reload(self):
def get_logs(self, since_time=None):
return self.deployment.get_logs(since_time=since_time)

def connect_open_telemetry(self, jaeger, open_telemetry_randomized_name):
def disconnect_open_telemetry(self, config_map_name):
"""
Remove volume attached for jaeger config
"""
del self.environ["OPENTELEMETRY"]
del self.environ["OPENTELEMETRY_CONFIG"]
self.deployment.remove_volume("jaeger-config-vol")
del self.openshift.config_maps[f"{config_map_name}.ini"]

def connect_open_telemetry(self, jaeger, open_telemetry_randomized_name=None):
"""
Modifies the APIcast to send information to jaeger.
Creates configmap and a volume, mounts the configmap into the volume
Expand All @@ -56,13 +68,21 @@ def connect_open_telemetry(self, jaeger, open_telemetry_randomized_name):
:param open_telemetry_randomized_name: randomized name used for the name of the configmap and for
the identifying name of the service in jaeger
"""
if not open_telemetry_randomized_name:
open_telemetry_randomized_name = randomize("open-telemetry-config")
config_map_name = f"{open_telemetry_randomized_name}.ini"
service_name = open_telemetry_randomized_name
self.openshift.config_maps.add(
config_map_name, jaeger.apicast_config_open_telemetry(config_map_name, service_name)
)

try:
self.deployment.remove_volume("jaeger-config-vol")
except OpenShiftPythonException:
pass
self.deployment.add_volume("jaeger-config-vol", "/tmp/jaeger/", configmap_name=config_map_name)
self.environ.set_many({"OPENTELEMETRY": "True", "OPENTRACING_CONFIG": f"/tmp/jaeger/{config_map_name}"})
self.environ.set_many({"OPENTELEMETRY": "True", "OPENTELEMETRY_CONFIG": f"/tmp/jaeger/{config_map_name}"})
return service_name

def _wait_for_apicasts(self):
"""Waits until changes to APIcast have been applied"""
Expand Down
4 changes: 3 additions & 1 deletion testsuite/tests/apicast/parameters/jaeger/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ def jaeger_service_name(staging_gateway, jaeger):
"""
Deploys apicast gateway configured with jaeger.
"""
return staging_gateway.connect_open_telemetry(jaeger)
name = staging_gateway.connect_open_telemetry(jaeger)
yield name
staging_gateway.disconnect_open_telemetry(name)
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,43 @@
import pytest

from packaging.version import Version # noqa # pylint: disable=unused-import
from testsuite import APICAST_OPERATOR_VERSION # noqa # pylint: disable=unused-import
from testsuite import TESTED_VERSION, APICAST_OPERATOR_VERSION # noqa # pylint: disable=unused-import
from testsuite.gateways.apicast.operator import OperatorApicast
from testsuite.gateways.apicast.system import SystemApicast
from testsuite.utils import randomize
from testsuite.capabilities import Capability

pytestmark = [pytest.mark.required_capabilities(Capability.JAEGER, Capability.CUSTOM_ENVIRONMENT)]


@pytest.mark.skipif("APICAST_OPERATOR_VERSION < Version('0.7.6')")
@pytest.mark.issue("https://issues.redhat.com/browse/THREESCALE-7735")
@pytest.mark.issue("https://issues.redhat.com/browse/THREESCALE-9539")
@pytest.fixture(
scope="module",
params=[
pytest.param(
SystemApicast,
id="system",
marks=[
pytest.mark.required_capabilities(Capability.STANDARD_GATEWAY),
pytest.mark.skipif("TESTED_VERSION < Version('2.14')"),
pytest.mark.issue("https://issues.redhat.com/browse/THREESCALE-7735"),
],
),
pytest.param(
OperatorApicast,
id="operator",
marks=[
pytest.mark.required_capabilities(Capability.OCP4),
pytest.mark.skipif("APICAST_OPERATOR_VERSION < Version('0.7.6')"),
pytest.mark.issue("https://issues.redhat.com/browse/THREESCALE-9539"),
],
),
],
)
def gateway_kind(request):
"""Gateway class to use for tests"""
return request.param


def test_open_telemetry_apicast_integration(api_client, jaeger, jaeger_service_name):
"""
Makes a request to a random endpoint
Expand Down

0 comments on commit 4a2148b

Please sign in to comment.