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

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

Open
LarsMichelsen opened this issue Jul 16, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@LarsMichelsen
Copy link

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 LarsMichelsen added the bug Something isn't working label Jul 16, 2024
@LarsMichelsen LarsMichelsen changed the title Unit tests break in case Jaeger listens on ::1:4137 Unit tests break in case service (e.g Jaeger) listens on ::1:4137 Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant