opentelemetry-python icon indicating copy to clipboard operation
opentelemetry-python copied to clipboard

Unit tests break in case service (e.g Jaeger) listens on ::1:4137

Open LarsMichelsen opened this issue 7 months ago • 0 comments

Describe your environment

OS: Ubuntu 24.04 Python version: 3.12 SDK version: main API version: main

What happened?

Running unit tests suddenly failed for me, e.g. like this for some initially unclear reason:

========================================================== test session starts ===========================================================
platform linux -- Python 3.12.4, pytest-7.4.4, pluggy-1.5.0 -- /home/lm/git/opentelemetry-python/.tox/py312-test-opentelemetry-exporter-otlp-proto-grpc-0/bin/python
cachedir: .pytest_cache
rootdir: /home/lm/git/opentelemetry-python
configfile: pyproject.toml
collected 24 items / 22 deselected / 2 selected                                                                                          

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py::TestOTLPMetricExporter::test_shutdown 4317
None

------------------------------------------------------------- live log call --------------------------------------------------------------
ERROR    opentelemetry.exporter.otlp.proto.grpc.exporter:exporter.py:268 Failed to export metrics to localhost:4317, error code: StatusCode.UNIMPLEMENTED
FAILED

================================================================ FAILURES ================================================================
__________________________________________________ TestOTLPMetricExporter.test_shutdown __________________________________________________

self = <tests.test_otlp_metrics_exporter.TestOTLPMetricExporter testMethod=test_shutdown>

    def test_shutdown(self):
        add_MetricsServiceServicer_to_server(
            MetricsServiceServicerSUCCESS(), self.server
        )
>       self.assertEqual(
            self.exporter.export(self.metrics["sum_int"]),
            MetricExportResult.SUCCESS,
        )
E       AssertionError: <MetricExportResult.FAILURE: 1> != <MetricExportResult.SUCCESS: 0>

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_metrics_exporter.py:776: AssertionError
----------------------------------------------------------- Captured log call ------------------------------------------------------------
ERROR    opentelemetry.exporter.otlp.proto.grpc.exporter:exporter.py:268 Failed to export metrics to localhost:4317, error code: StatusCode.UNIMPLEMENTED
============================================================ warnings summary ============================================================

Steps to Reproduce

  1. Open some network service (Jaeger in my case) on ::4317
  2. Start the otlp grpc unit tests

Expected Result

The tests should be independent of what else is running on the OS. In case a network service is started and connected to, the exact same addresses for serving and connecting need to be used. In case a listening socket can not be opened, the test shall fail.

Actual Result

This pointed me towards the solution:

ERROR    opentelemetry.exporter.otlp.proto.grpc.exporter:exporter.py:268 Failed to export metrics to localhost:4317, error code: StatusCode.UNIMPLEMENTED

I had some Jaeger instance running on IPv6 ::1:4317:

> netstat -alnp | grep 4317
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 ::1:4317                :::*                    LISTEN      -      

Turning it of unbreaks the unit tests again.

Why is that? It looks like the reason is that some unit tests open a server on 127.0.0.1:4317 and then connect to localhost:4317. In case something is running on IPv6 4317 the tests connect to that port. In case it is not running, the tests connect to IPv4 4317. This behavior is based on the OS level config, I guess.

Additional context

No response

Would you like to implement a fix?

No

LarsMichelsen avatar Jul 16 '24 19:07 LarsMichelsen