Skip to content

Commit 8cfbca2

Browse files
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 <[email protected]>
1 parent d6a59e4 commit 8cfbca2

File tree

6 files changed

+81
-5
lines changed

6 files changed

+81
-5
lines changed

Diff for: .github/workflows/generate_workflows.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
tox_ini_path = Path(__file__).parent.parent.parent.joinpath("tox.ini")
1010
workflows_directory_path = Path(__file__).parent
1111

12-
generate_test_workflow(tox_ini_path, workflows_directory_path, "ubuntu-latest")
12+
generate_test_workflow(
13+
tox_ini_path, workflows_directory_path, "ubuntu-latest", "windows-latest"
14+
)
1315
generate_lint_workflow(tox_ini_path, workflows_directory_path)
1416
generate_misc_workflow(tox_ini_path, workflows_directory_path)

Diff for: .github/workflows/generate_workflows_lib/src/generate_workflows_lib/__init__.py

+16
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ def get_test_job_datas(tox_envs: list, operating_systems: list) -> list:
5555
"py312": "3.12",
5656
}
5757

58+
# we enable windows testing only for packages with windows specific code paths
59+
per_tox_env_os_enablement = {
60+
"windows-latest": {
61+
"py312-test-instrumentation-botocore",
62+
"py312-test-instrumentation-system-metrics",
63+
},
64+
}
65+
5866
test_job_datas = []
5967

6068
for operating_system in operating_systems:
@@ -71,6 +79,14 @@ def get_test_job_datas(tox_envs: list, operating_systems: list) -> list:
7179
]
7280
tox_env = tox_test_env_match.string
7381

82+
# if we have an entry for the os add only jobs for tox env manually configured
83+
packages_manually_enabled = per_tox_env_os_enablement.get(
84+
operating_system
85+
)
86+
if packages_manually_enabled:
87+
if tox_env not in packages_manually_enabled:
88+
continue
89+
7490
test_requirements = groups["test_requirements"]
7591

7692
if test_requirements is None:

Diff for: .github/workflows/test_1.yml

+42
Original file line numberDiff line numberDiff line change
@@ -3903,3 +3903,45 @@ jobs:
39033903

39043904
- name: Run tests
39053905
run: tox -e pypy3-test-processor-baggage -- -ra
3906+
3907+
py312-test-instrumentation-botocore_windows-latest:
3908+
name: instrumentation-botocore 3.12 Windows
3909+
runs-on: windows-latest
3910+
steps:
3911+
- name: Checkout repo @ SHA - ${{ github.sha }}
3912+
uses: actions/checkout@v4
3913+
3914+
- name: Set up Python 3.12
3915+
uses: actions/setup-python@v5
3916+
with:
3917+
python-version: "3.12"
3918+
3919+
- name: Install tox
3920+
run: pip install tox
3921+
3922+
- name: Configure git to support long filenames
3923+
run: git config --system core.longpaths true
3924+
3925+
- name: Run tests
3926+
run: tox -e py312-test-instrumentation-botocore -- -ra
3927+
3928+
py312-test-instrumentation-system-metrics_windows-latest:
3929+
name: instrumentation-system-metrics 3.12 Windows
3930+
runs-on: windows-latest
3931+
steps:
3932+
- name: Checkout repo @ SHA - ${{ github.sha }}
3933+
uses: actions/checkout@v4
3934+
3935+
- name: Set up Python 3.12
3936+
uses: actions/setup-python@v5
3937+
with:
3938+
python-version: "3.12"
3939+
3940+
- name: Install tox
3941+
run: pip install tox
3942+
3943+
- name: Configure git to support long filenames
3944+
run: git config --system core.longpaths true
3945+
3946+
- name: Run tests
3947+
run: tox -e py312-test-instrumentation-system-metrics -- -ra

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3838
([#2940](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2940))
3939
- `opentelemetry-instrumentation-dbapi` sqlcommenter key values created from PostgreSQL, MySQL systems
4040
([#2897](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2897))
41+
- `opentelemetry-instrumentation-system-metrics`: don't report open file descriptors on Windows
42+
([#2946](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2946))
4143

4244
### Breaking changes
4345

Diff for: instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,10 @@ def _instrument(self, **kwargs):
397397
unit="switches",
398398
)
399399

400-
if "process.open_file_descriptor.count" in self._config:
400+
if (
401+
sys.platform != "win32"
402+
and "process.open_file_descriptor.count" in self._config
403+
):
401404
self._meter.create_observable_up_down_counter(
402405
name="process.open_file_descriptor.count",
403406
callbacks=[self._get_open_file_descriptors],

Diff for: instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
# pylint: disable=protected-access
1616

17+
import sys
1718
from collections import namedtuple
1819
from platform import python_implementation
1920
from unittest import mock, skipIf
@@ -118,21 +119,30 @@ def test_system_metrics_instrument(self):
118119
f"process.runtime.{self.implementation}.thread_count",
119120
f"process.runtime.{self.implementation}.context_switches",
120121
f"process.runtime.{self.implementation}.cpu.utilization",
121-
"process.open_file_descriptor.count",
122122
]
123123

124+
on_windows = sys.platform == "win32"
124125
if self.implementation == "pypy":
125-
self.assertEqual(len(metric_names), 21)
126+
self.assertEqual(len(metric_names), 20 if on_windows else 21)
126127
else:
127-
self.assertEqual(len(metric_names), 22)
128+
self.assertEqual(len(metric_names), 21 if on_windows else 22)
128129
observer_names.append(
129130
f"process.runtime.{self.implementation}.gc_count",
130131
)
132+
if not on_windows:
133+
observer_names.append(
134+
"process.open_file_descriptor.count",
135+
)
131136

132137
for observer in metric_names:
133138
self.assertIn(observer, observer_names)
134139
observer_names.remove(observer)
135140

141+
if on_windows:
142+
self.assertNotIn(
143+
"process.open_file_descriptor.count", observer_names
144+
)
145+
136146
def test_runtime_metrics_instrument(self):
137147
runtime_config = {
138148
"process.runtime.memory": ["rss", "vms"],
@@ -844,6 +854,7 @@ def test_runtime_cpu_percent(self, mock_process_cpu_percent):
844854
f"process.runtime.{self.implementation}.cpu.utilization", expected
845855
)
846856

857+
@skipIf(sys.platform == "win32", "No file descriptors on Windows")
847858
@mock.patch("psutil.Process.num_fds")
848859
def test_open_file_descriptor_count(self, mock_process_num_fds):
849860
mock_process_num_fds.configure_mock(**{"return_value": 3})

0 commit comments

Comments
 (0)