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

NH-67051 Add tests for instrumented_python_framework_versions helper #244

Merged
merged 13 commits into from
Dec 1, 2023
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ LIBOBOESERVERLESSX86 := "liboboe-1.0-lambda-x86_64.so"
OBOEVERSION := $(shell cat ./solarwinds_apm/extension/VERSION)

# specification of source of header and library files
ifdef STAGING_OBOE
OBOEREPO := "https://agent-binaries.global.st-ssp.solarwinds.com/apm/c-lib/${OBOEVERSION}"
else
OBOEREPO := "https://agent-binaries.cloud.solarwinds.com/apm/c-lib/${OBOEVERSION}"
endif
OBOEREPO := "https://agent-binaries.global.st-ssp.solarwinds.com/apm/c-lib/${OBOEVERSION}"

verify-oboe-version:
@echo -e "Downloading Oboe VERSION file from ${OBOEREPO}"
Expand Down
2 changes: 1 addition & 1 deletion solarwinds_apm/extension/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13.0.0
14.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# © 2023 SolarWinds Worldwide, LLC. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

import os

from solarwinds_apm import configurator

class TestConfiguratorAddAllInstrumentedFrameworkVersions:
def test_add_all_instr_versions_skip_disabled_instrumentors(
self,
mocker,
):
# Save any DISABLED env var for later
old_disabled = os.environ.get("OTEL_PYTHON_DISABLED_INSTRUMENTATIONS", None)
if old_disabled:
del os.environ["OTEL_PYTHON_DISABLED_INSTRUMENTATIONS"]

mocker.patch.dict(
os.environ,
{
"OTEL_PYTHON_DISABLED_INSTRUMENTATIONS": "urllib3"
}
)

# Mock entry point
mock_instrumentor_entry_point = mocker.Mock()
mock_instrumentor_entry_point.configure_mock(
**{
"name": "urllib3",
"dist": "foo",
}
)
mock_points = iter([mock_instrumentor_entry_point])
mock_iter_entry_points = mocker.patch(
"solarwinds_apm.configurator.iter_entry_points"
)
mock_iter_entry_points.configure_mock(
return_value=mock_points
)

# Test!
test_versions = configurator.SolarWindsConfigurator()._add_all_instrumented_python_framework_versions({"foo": "bar"})
assert test_versions["foo"] == "bar"
assert "Python.Urllib3.Version" not in test_versions

# Restore old DISABLED
if old_disabled:
os.environ["OTEL_PYTHON_DISABLED_INSTRUMENTATIONS"] = old_disabled

def test_add_all_instr_versions_skip_dependency_conflict(
self,
mocker,
):
mock_get_dist_dep_conflicts = mocker.patch(
Fixed Show fixed Hide fixed
"solarwinds_apm.configurator.get_dist_dependency_conflicts",
return_value="not-none"
)

# TODO

def test_add_all_instr_versions_skip_conflict_check_exception(
self,
mocker,
):
mock_get_dist_dep_conflicts = mocker.patch(
Fixed Show fixed Hide fixed
"solarwinds_apm.configurator.get_dist_dependency_conflicts",
side_effect=Exception("mock conflict")
)

# TODO

def test_add_all_instr_versions_skip_other_exception(
self,
mocker,
):
pass

def test_add_all_instr_versions_aiohttp_client(
self,
mocker,
):
pass

def test_add_all_instr_versions_grpc(
self,
mocker,
):
pass

def test_add_all_instr_versions_system_metrics(
self,
mocker,
):
pass

def test_add_all_instr_versions_tortoiseorm(
self,
mocker,
):
pass

def test_add_all_instr_versions_mysql(
self,
mocker,
):
pass

def test_add_all_instr_versions_urllib(
Fixed Show fixed Hide fixed
self,
mocker,
):
pass

def test_add_all_instr_versions_elasticsearch(
self,
mocker,
):
pass

def test_add_all_instr_versions_pyramid(
self,
mocker,
):
pass

def test_add_all_instr_versions_sqlite3(
self,
mocker,
):
pass

def test_add_all_instr_versions_tornado(
self,
mocker,
):
pass

def test_add_all_instr_versions_urllib(
self,
mocker,
):
# Mock sys module
mock_sys_module = mocker.Mock()
mock_sys_module.configure_mock(
**{
"__version__": "foo-version"
}
)
mock_sys = mocker.patch(
"solarwinds_apm.configurator.sys"
)
mock_sys.configure_mock(
**{
"modules": {
"urllib.request": mock_sys_module
}
}
)

# Mock entry point
mock_instrumentor_entry_point = mocker.Mock()
mock_instrumentor_entry_point.configure_mock(
**{
"name": "urllib",
"dist": "foo",
}
)
mock_points = iter([mock_instrumentor_entry_point])
mock_iter_entry_points = mocker.patch(
"solarwinds_apm.configurator.iter_entry_points"
)
mock_iter_entry_points.configure_mock(
return_value=mock_points
)

# Mock conflicts - none
mock_get_dist_dep_conflicts = mocker.patch(
Fixed Show fixed Hide fixed
"solarwinds_apm.configurator.get_dist_dependency_conflicts",
return_value=None,
)

# Test!
test_versions = configurator.SolarWindsConfigurator()._add_all_instrumented_python_framework_versions({"foo": "bar"})
assert test_versions["foo"] == "bar"
# TODO: should be capitalized Urllib
assert "Python.urllib.Version" in test_versions
assert test_versions["Python.urllib.Version"] == "foo-version"

def test_add_all_instr_versions_urllib3_nonspecial_case(
self,
mocker,
):
pass
Loading