Skip to content

Commit

Permalink
Remove functional tests for opentelemetry instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lubosmj committed Oct 31, 2024
1 parent c5509f5 commit b4b3e39
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 365 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ if [ "$TEST" = "azure" ]; then
command: "azurite-blob --blobHost 0.0.0.0"' vars/main.yaml
sed -i -e '$a azure_test: true\
pulp_scenario_settings: {"api_root_rewrite_header": "X-API-Root", "domain_enabled": true, "rest_framework__default_permission_classes": ["pulpcore.plugin.access_policy.DefaultAccessPolicy"]}\
pulp_scenario_env: {"otel_bsp_max_export_batch_size": 1, "otel_bsp_max_queue_size": 1, "otel_exporter_otlp_endpoint": "http://localhost:4318", "otel_exporter_otlp_protocol": "http/protobuf", "otel_metric_export_interval": 800, "pulp_otel_enabled": "true"}\
pulp_scenario_env: {}\
' vars/main.yaml
fi

Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/scripts/pre_before_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ if [ "$TEST" = "azure" ]; then
cmd_stdin_prefix bash -c "cat > /etc/nginx/pulp/api_root_rewrite.conf" < pulpcore/tests/functional/assets/api_root_rewrite.conf
cmd_prefix bash -c "s6-rc -d change nginx"
cmd_prefix bash -c "s6-rc -u change nginx"
cmd_stdin_prefix bash -c "cat > /var/lib/pulp/scripts/otel_server.py" < pulpcore/tests/functional/assets/otel_server.py
cmd_user_prefix nohup python3 /var/lib/pulp/scripts/otel_server.py &
fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ dist
pip-wheel-metadata/
.pytest_cache

__pycache__/

# Built documentation
docs/_build
docs/_diagrams
Expand Down
91 changes: 0 additions & 91 deletions pulp_file/tests/functional/api/test_telemetry_collection.py

This file was deleted.

62 changes: 0 additions & 62 deletions pulpcore/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,68 +210,6 @@ def make_url(self, path):
return f"{protocol_handler}{self.host}:{self.port}{path}"


@pytest.fixture(scope="session")
def received_otel_span():
"""A fixture for checking the presence of specific spans on the otel collector server.
Ensure the collector server is up and running before executing tests with this fixture. To do
so, please, run the server as follows: python3 pulpcore/tests/functional/assets/otel_server.py
"""

def _received_otel_span(data, retries=3):
if os.environ.get("PULP_OTEL_ENABLED") != "true":
# pretend everything is working as expected if tests are run from
# a non-configured runner
return True

async def _send_request():
async with aiohttp.ClientSession(raise_for_status=False) as session:
otel_server_url = os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT")
async with session.post(f"{otel_server_url}/test", json=data) as response:
return response.status

while retries:
status = asyncio.run(_send_request())
if status == 200:
return True
sleep(2)
retries -= 1
return False

return _received_otel_span


@pytest.fixture(scope="session")
def received_otel_metrics():
"""A fixture for checking the presence of specific metrics on the otel collector server.
Ensure the collector server is up and running before executing tests with this fixture. To do
so, please, run the server as follows: python3 pulpcore/tests/functional/assets/otel_server.py
"""

def _received_otel_metric(data, retries=3):
if os.environ.get("PULP_OTEL_ENABLED") != "true":
# pretend everything is working as expected if tests are run from
# a non-configured runner
return True

async def _send_request():
async with aiohttp.ClientSession(raise_for_status=False) as session:
otel_server_url = os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT")
async with session.post(f"{otel_server_url}/metrics_test", json=data) as response:
return response.status

while retries:
status = asyncio.run(_send_request())
if status == 200:
return True
sleep(2)
retries -= 1
return False

return _received_otel_metric


@pytest.fixture
def test_path():
return os.getenv("PYTEST_CURRENT_TEST").split()[0]
Expand Down
29 changes: 2 additions & 27 deletions pulpcore/tests/functional/api/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,40 +59,24 @@


@pytest.mark.parallel
def test_get_authenticated(test_path, pulpcore_bindings, received_otel_span):
def test_get_authenticated(test_path, pulpcore_bindings):
"""GET the status path with valid credentials.
Verify the response with :meth:`verify_get_response`.
"""
response = pulpcore_bindings.StatusApi.status_read()
verify_get_response(response.to_dict(), STATUS)
assert received_otel_span(
{
"http.method": "GET",
"http.target": "/pulp/api/v3/status/",
"http.status_code": 200,
"http.user_agent": test_path,
}
)


@pytest.mark.parallel
def test_get_unauthenticated(test_path, pulpcore_bindings, anonymous_user, received_otel_span):
def test_get_unauthenticated(test_path, pulpcore_bindings, anonymous_user):
"""GET the status path with no credentials.
Verify the response with :meth:`verify_get_response`.
"""
with anonymous_user:
response = pulpcore_bindings.StatusApi.status_read()
verify_get_response(response.to_dict(), STATUS)
assert received_otel_span(
{
"http.method": "GET",
"http.target": "/pulp/api/v3/status/",
"http.status_code": 200,
"http.user_agent": test_path,
}
)


@pytest.mark.parallel
Expand All @@ -101,7 +85,6 @@ def test_post_authenticated(
pulp_api_v3_path,
pulp_api_v3_url,
pulpcore_bindings,
received_otel_span,
):
"""POST the status path with valid credentials.
Expand All @@ -117,14 +100,6 @@ def test_post_authenticated(
pulpcore_bindings.client.request("POST", status_url, headers={"User-Agent": test_path})

assert e.value.status == 405
assert received_otel_span(
{
"http.method": "POST",
"http.target": f"{pulp_api_v3_path}status/",
"http.status_code": 405,
"http.user_agent": test_path,
}
)


@pytest.mark.parallel
Expand Down
24 changes: 1 addition & 23 deletions pulpcore/tests/functional/api/test_tasking.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,7 @@ def test_task_version_prevent_pickup(dispatch_task, pulpcore_bindings):
pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"})


def test_emmiting_unblocked_task_telemetry(
dispatch_task, pulpcore_bindings, pulp_settings, received_otel_metrics
):
if os.getenv("PULP_OTEL_ENABLED").lower() != "true":
pytest.skip("Need PULP_OTEL_ENABLED to run this test.")

def test_emmiting_unblocked_task_telemetry(dispatch_task, pulpcore_bindings, pulp_settings):
# Checking online workers ready to get a task
workers_online = pulpcore_bindings.WorkersApi.list(online="true").count

Expand All @@ -356,23 +351,6 @@ def test_emmiting_unblocked_task_telemetry(
task = pulpcore_bindings.TasksApi.read(task_href)
assert task.state == "waiting"

# And trigger the metrics
assert received_otel_metrics(
{
"name": "tasks_unblocked_queue",
"description": "Number of unblocked tasks waiting in the queue.",
"unit": "tasks",
}
)

assert received_otel_metrics(
{
"name": "tasks_longest_unblocked_time",
"description": "The age of the longest waiting task.",
"unit": "seconds",
}
)

[
pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"})
for task_href in resident_task_hrefs
Expand Down
Loading

0 comments on commit b4b3e39

Please sign in to comment.