mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-31 22:23:12 +08:00
opentelemetry-instrumentation-system-metrics: don't report open file descriptors on windows (#2946)
* opentelemetry-instrumentation-system-metrics: don't report files descriptors on windows * Run manually added tox env tests on windows too * Add jobs for botocore and system-metrics on windows * Skip open file descriptor test on windows --------- Co-authored-by: Tammy Baylis <96076570+tammy-baylis-swi@users.noreply.github.com>
This commit is contained in:

committed by
GitHub

parent
d6a59e4bdf
commit
8cfbca2293
4
.github/workflows/generate_workflows.py
vendored
4
.github/workflows/generate_workflows.py
vendored
@ -9,6 +9,8 @@ from generate_workflows_lib import (
|
||||
tox_ini_path = Path(__file__).parent.parent.parent.joinpath("tox.ini")
|
||||
workflows_directory_path = Path(__file__).parent
|
||||
|
||||
generate_test_workflow(tox_ini_path, workflows_directory_path, "ubuntu-latest")
|
||||
generate_test_workflow(
|
||||
tox_ini_path, workflows_directory_path, "ubuntu-latest", "windows-latest"
|
||||
)
|
||||
generate_lint_workflow(tox_ini_path, workflows_directory_path)
|
||||
generate_misc_workflow(tox_ini_path, workflows_directory_path)
|
||||
|
@ -55,6 +55,14 @@ def get_test_job_datas(tox_envs: list, operating_systems: list) -> list:
|
||||
"py312": "3.12",
|
||||
}
|
||||
|
||||
# we enable windows testing only for packages with windows specific code paths
|
||||
per_tox_env_os_enablement = {
|
||||
"windows-latest": {
|
||||
"py312-test-instrumentation-botocore",
|
||||
"py312-test-instrumentation-system-metrics",
|
||||
},
|
||||
}
|
||||
|
||||
test_job_datas = []
|
||||
|
||||
for operating_system in operating_systems:
|
||||
@ -71,6 +79,14 @@ def get_test_job_datas(tox_envs: list, operating_systems: list) -> list:
|
||||
]
|
||||
tox_env = tox_test_env_match.string
|
||||
|
||||
# if we have an entry for the os add only jobs for tox env manually configured
|
||||
packages_manually_enabled = per_tox_env_os_enablement.get(
|
||||
operating_system
|
||||
)
|
||||
if packages_manually_enabled:
|
||||
if tox_env not in packages_manually_enabled:
|
||||
continue
|
||||
|
||||
test_requirements = groups["test_requirements"]
|
||||
|
||||
if test_requirements is None:
|
||||
|
42
.github/workflows/test_1.yml
vendored
42
.github/workflows/test_1.yml
vendored
@ -3903,3 +3903,45 @@ jobs:
|
||||
|
||||
- name: Run tests
|
||||
run: tox -e pypy3-test-processor-baggage -- -ra
|
||||
|
||||
py312-test-instrumentation-botocore_windows-latest:
|
||||
name: instrumentation-botocore 3.12 Windows
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Checkout repo @ SHA - ${{ github.sha }}
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python 3.12
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install tox
|
||||
run: pip install tox
|
||||
|
||||
- name: Configure git to support long filenames
|
||||
run: git config --system core.longpaths true
|
||||
|
||||
- name: Run tests
|
||||
run: tox -e py312-test-instrumentation-botocore -- -ra
|
||||
|
||||
py312-test-instrumentation-system-metrics_windows-latest:
|
||||
name: instrumentation-system-metrics 3.12 Windows
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Checkout repo @ SHA - ${{ github.sha }}
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python 3.12
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install tox
|
||||
run: pip install tox
|
||||
|
||||
- name: Configure git to support long filenames
|
||||
run: git config --system core.longpaths true
|
||||
|
||||
- name: Run tests
|
||||
run: tox -e py312-test-instrumentation-system-metrics -- -ra
|
||||
|
@ -38,6 +38,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
([#2940](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2940))
|
||||
- `opentelemetry-instrumentation-dbapi` sqlcommenter key values created from PostgreSQL, MySQL systems
|
||||
([#2897](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2897))
|
||||
- `opentelemetry-instrumentation-system-metrics`: don't report open file descriptors on Windows
|
||||
([#2946](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2946))
|
||||
|
||||
### Breaking changes
|
||||
|
||||
|
@ -397,7 +397,10 @@ class SystemMetricsInstrumentor(BaseInstrumentor):
|
||||
unit="switches",
|
||||
)
|
||||
|
||||
if "process.open_file_descriptor.count" in self._config:
|
||||
if (
|
||||
sys.platform != "win32"
|
||||
and "process.open_file_descriptor.count" in self._config
|
||||
):
|
||||
self._meter.create_observable_up_down_counter(
|
||||
name="process.open_file_descriptor.count",
|
||||
callbacks=[self._get_open_file_descriptors],
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
# pylint: disable=protected-access
|
||||
|
||||
import sys
|
||||
from collections import namedtuple
|
||||
from platform import python_implementation
|
||||
from unittest import mock, skipIf
|
||||
@ -118,21 +119,30 @@ class TestSystemMetrics(TestBase):
|
||||
f"process.runtime.{self.implementation}.thread_count",
|
||||
f"process.runtime.{self.implementation}.context_switches",
|
||||
f"process.runtime.{self.implementation}.cpu.utilization",
|
||||
"process.open_file_descriptor.count",
|
||||
]
|
||||
|
||||
on_windows = sys.platform == "win32"
|
||||
if self.implementation == "pypy":
|
||||
self.assertEqual(len(metric_names), 21)
|
||||
self.assertEqual(len(metric_names), 20 if on_windows else 21)
|
||||
else:
|
||||
self.assertEqual(len(metric_names), 22)
|
||||
self.assertEqual(len(metric_names), 21 if on_windows else 22)
|
||||
observer_names.append(
|
||||
f"process.runtime.{self.implementation}.gc_count",
|
||||
)
|
||||
if not on_windows:
|
||||
observer_names.append(
|
||||
"process.open_file_descriptor.count",
|
||||
)
|
||||
|
||||
for observer in metric_names:
|
||||
self.assertIn(observer, observer_names)
|
||||
observer_names.remove(observer)
|
||||
|
||||
if on_windows:
|
||||
self.assertNotIn(
|
||||
"process.open_file_descriptor.count", observer_names
|
||||
)
|
||||
|
||||
def test_runtime_metrics_instrument(self):
|
||||
runtime_config = {
|
||||
"process.runtime.memory": ["rss", "vms"],
|
||||
@ -844,6 +854,7 @@ class TestSystemMetrics(TestBase):
|
||||
f"process.runtime.{self.implementation}.cpu.utilization", expected
|
||||
)
|
||||
|
||||
@skipIf(sys.platform == "win32", "No file descriptors on Windows")
|
||||
@mock.patch("psutil.Process.num_fds")
|
||||
def test_open_file_descriptor_count(self, mock_process_num_fds):
|
||||
mock_process_num_fds.configure_mock(**{"return_value": 3})
|
||||
|
Reference in New Issue
Block a user