Skip to content

Commit 270c9d2

Browse files
committed
speed up weaver tests
1 parent 3226b7e commit 270c9d2

File tree

4 files changed

+92
-17
lines changed

4 files changed

+92
-17
lines changed

.claude/settings.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(find /Users/lmolkova/repo/opentelemetry-python -name conftest.py -exec ls -la {} \\\\;)",
5+
"Bash(python -m pytest tests/opentelemetry-test-utils/tests/test_weaver_live_check.py -v)",
6+
"Bash(grep -E \"\\\\.yml$\")",
7+
"Bash(grep -n \"weaver\" /Users/lmolkova/repo/opentelemetry-python/.github/workflows/*.yml)",
8+
"Bash(grep -n \"download\\\\|install.*binary\\\\|wget\\\\|curl\" /Users/lmolkova/repo/opentelemetry-python/.github/workflows/*.yml)",
9+
"Bash(grep -r \"binary\\\\|download\\\\|wget\\\\|curl\\\\|install.*tool\" /Users/lmolkova/repo/opentelemetry-python/.github/workflows/*.yml)",
10+
"Bash(tox -e generate-workflows)",
11+
"Read(//usr/local/**)",
12+
"Bash(python .github/workflows/generate_workflows.py)",
13+
"Bash(chmod +x /tmp/git_seq_editor.sh)",
14+
"Bash(chmod +x /tmp/git_msg_editor.sh)",
15+
"Bash(GIT_SEQUENCE_EDITOR=\"/tmp/git_seq_editor.sh\" GIT_EDITOR=\"/tmp/git_msg_editor.sh\" git rebase -i main)",
16+
"WebFetch(domain:productionresultssa18.blob.core.windows.net)",
17+
"WebFetch(domain:productionresultssa1.blob.core.windows.net)",
18+
"Bash(xargs ls *)",
19+
"Bash(xargs -I {} sh -c 'echo \"=== {} ===\" && head -20 {}')",
20+
"Bash(xargs -I {} sh -c 'echo \"FILE: {}\" && cat {}')",
21+
"Bash(find /Users/lmolkova/repo/opentelemetry-python-contrib -name \"pyproject.toml\" -path \"*/instrumentation/*\" -exec grep -l \"markers\\\\|sys_platform\\\\|platform\" {} \\\\;)",
22+
"Bash(find /Users/lmolkova/repo/opentelemetry-python-contrib/util -type f -name \"pyproject.toml\" -exec sh -c 'echo \"=== {} ===\" && cat {}' \\\\;)",
23+
"Bash(python -m pytest tests/opentelemetry-test-utils/tests/test_weaver_live_check.py -x --no-header -q)",
24+
"Bash(python -m pytest tests/opentelemetry-test-utils/tests/test_weaver_live_check.py -x -q)",
25+
"Bash(python -m pytest tests/opentelemetry-test-utils/tests/test_weaver_live_check.py -x -q --no-header)",
26+
"Bash(sed -i '' 's/py312/py313/g' tox.ini)",
27+
"Bash(tox -e py313)",
28+
"Bash(mv dummy *)",
29+
"Bash(tox -e py313 -r)",
30+
"Bash(tox -e py312-test-opentelemetry-test-utils -r)",
31+
"Bash(gh issue *)",
32+
"Bash(gh search *)",
33+
"Bash(pip --version)",
34+
"Bash(tox --version)",
35+
"Bash(gh run *)",
36+
"Bash(tox -e py312-test-opentelemetry-test-utils)",
37+
"Bash(.tox/py312-test-opentelemetry-test-utils/bin/pytest tests/opentelemetry-test-utils/tests/test_weaver_live_check.py::TestSDKInitLiveCheck::test_end_no_violations -ra)",
38+
"Bash(.tox/py312-test-opentelemetry-test-utils/bin/python -c ' *)"
39+
]
40+
}
41+
}

tests/opentelemetry-test-utils/src/opentelemetry/test/weaver_live_check.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def test_my_telemetry(self):
252252

253253
def __init__(
254254
self,
255+
registry: str | None = None,
255256
schema_version: str | None = None,
256257
policies_dir: str | None = None,
257258
inactivity_timeout: int = 30,
@@ -285,13 +286,14 @@ def __init__(
285286
if policies_dir:
286287
command += ["--advice-policies", os.path.abspath(policies_dir)]
287288

288-
if schema_version is None:
289-
schema_version = list(Schemas)[-1].value.rsplit("/", 1)[-1]
289+
if registry is None:
290+
if schema_version is None:
291+
schema_version = list(Schemas)[-1].value.rsplit("/", 1)[-1]
292+
registry = f"https://github.com/open-telemetry/semantic-conventions/archive/refs/tags/v{schema_version}.tar.gz[model]"
293+
elif os.path.isdir(registry):
294+
registry = os.path.abspath(registry)
290295

291-
command += [
292-
"--registry",
293-
f"https://github.com/open-telemetry/semantic-conventions/archive/refs/tags/v{schema_version}.tar.gz[model]",
294-
]
296+
command += ["--registry", registry]
295297

296298
self._command = command
297299
logger.debug("Weaver command: %s", command)
@@ -304,15 +306,15 @@ def __exit__(self, exc_type: Any, *_: Any) -> None:
304306
self._stopped = True
305307
self.close()
306308

307-
def start(self, timeout: int = 60) -> "WeaverLiveCheck":
309+
def start(self) -> "WeaverLiveCheck":
308310
logger.debug("Starting WeaverLiveCheck process...")
309311
self._process = subprocess.Popen( # pylint: disable=consider-using-with
310312
self._command,
311313
stdout=subprocess.PIPE,
312314
stderr=subprocess.PIPE,
313315
)
314316
try:
315-
self._wait_for_ready(timeout=timeout)
317+
self._wait_for_ready()
316318
self._ready = True
317319
except Exception as exc: # pylint: disable=broad-except
318320
logs = self._read_weaver_logs()
@@ -322,22 +324,22 @@ def start(self, timeout: int = 60) -> "WeaverLiveCheck":
322324
raise
323325
return self
324326

325-
def _wait_for_ready(self, timeout: int = 60) -> None:
327+
def _wait_for_ready(self) -> None:
326328
retry = Retry(
327-
total=timeout,
329+
total=10,
328330
backoff_factor=1,
329331
backoff_max=1,
330332
# Any non-2xx response from /health means weaver isn't ready yet.
331333
status_forcelist=list(range(300, 600)),
334+
raise_on_status=True,
332335
allowed_methods=["GET"],
333336
)
334337
session = Session()
335338
session.mount("http://", HTTPAdapter(max_retries=retry))
336339
try:
337-
response = session.get(
340+
session.get(
338341
f"http://localhost:{self._admin_port}/health", timeout=5
339342
)
340-
response.raise_for_status()
341343
except Exception as exc: # pylint: disable=broad-except
342344
if self._process is not None and self._process.poll() is not None:
343345
raise RuntimeError(

tests/opentelemetry-test-utils/tests/test_weaver_live_check.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
_HAS_GRPC = False
4242

4343
_TESTDATA_DIR = os.path.join(os.path.dirname(__file__), "testdata")
44+
_REGISTRY_DIR = os.path.join(_TESTDATA_DIR, "registry")
4445

4546

4647
def _make_provider(otlp_endpoint: str) -> TracerProvider:
@@ -62,7 +63,7 @@ def _make_provider(otlp_endpoint: str) -> TracerProvider:
6263
class TestSDKInitLiveCheck(unittest.TestCase):
6364
def test_end_and_check_no_violations(self):
6465
"""end_and_check() returns a LiveCheckReport with no violations on conformant telemetry."""
65-
with WeaverLiveCheck() as weaver:
66+
with WeaverLiveCheck(registry=_REGISTRY_DIR) as weaver:
6667
provider = _make_provider(weaver.otlp_endpoint)
6768
with provider.get_tracer("test-tracer").start_as_current_span(
6869
"test-span"
@@ -76,7 +77,9 @@ def test_end_and_check_no_violations(self):
7677

7778
def test_end_and_check_raises_on_violations(self):
7879
"""end_and_check() raises LiveCheckError with the report attached."""
79-
with WeaverLiveCheck(policies_dir=_TESTDATA_DIR) as weaver:
80+
with WeaverLiveCheck(
81+
registry=_REGISTRY_DIR, policies_dir=_TESTDATA_DIR
82+
) as weaver:
8083
provider = _make_provider(weaver.otlp_endpoint)
8184
with provider.get_tracer("test-tracer").start_as_current_span(
8285
"test-span"
@@ -105,7 +108,7 @@ def test_end_and_check_raises_on_violations(self):
105108

106109
def test_end_no_violations(self):
107110
"""end() returns a LiveCheckReport with no violations on conformant telemetry."""
108-
with WeaverLiveCheck() as weaver:
111+
with WeaverLiveCheck(registry=_REGISTRY_DIR) as weaver:
109112
provider = _make_provider(weaver.otlp_endpoint)
110113
with provider.get_tracer("test-tracer").start_as_current_span(
111114
"test-span"
@@ -123,7 +126,9 @@ def test_end_no_violations(self):
123126

124127
def test_end_with_violations(self):
125128
"""end() returns a LiveCheckReport with violations without raising."""
126-
with WeaverLiveCheck(policies_dir=_TESTDATA_DIR) as weaver:
129+
with WeaverLiveCheck(
130+
registry=_REGISTRY_DIR, policies_dir=_TESTDATA_DIR
131+
) as weaver:
127132
provider = _make_provider(weaver.otlp_endpoint)
128133
with provider.get_tracer("test-tracer").start_as_current_span(
129134
"test-span"
@@ -150,7 +155,7 @@ def test_end_with_violations(self):
150155

151156
def test_report_span_statistics(self):
152157
"""The full report exposes span counts and individual span samples."""
153-
with WeaverLiveCheck() as weaver:
158+
with WeaverLiveCheck(registry=_REGISTRY_DIR) as weaver:
154159
provider = _make_provider(weaver.otlp_endpoint)
155160
with provider.get_tracer("test-tracer").start_as_current_span(
156161
"test-span"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# this is a test registry, used to save up time on weaver loading semconv from GH repo
2+
# and preventing flaky tests resulting from unpredictable network/performance in CI
3+
groups:
4+
- id: registry.test
5+
type: attribute_group
6+
brief: Minimal registry for WeaverLiveCheck self-tests.
7+
attributes:
8+
- id: service.name
9+
type: string
10+
brief: The name of the service.
11+
stability: stable
12+
examples: ["test-service"]
13+
- id: telemetry.sdk.language
14+
type: string
15+
brief: The language of the telemetry SDK.
16+
stability: stable
17+
examples: ["python"]
18+
- id: telemetry.sdk.name
19+
type: string
20+
brief: The name of the telemetry SDK.
21+
stability: stable
22+
examples: ["opentelemetry"]
23+
- id: telemetry.sdk.version
24+
type: string
25+
brief: The version string of the telemetry SDK.
26+
stability: stable
27+
examples: ["1.0.0"]

0 commit comments

Comments
 (0)