Skip to content

Commit

Permalink
chore(otel): remove otel setup (move to bentoml#2980)
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
  • Loading branch information
aarnphm committed Sep 21, 2022
1 parent 42bf589 commit 735f2cb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 69 deletions.
3 changes: 2 additions & 1 deletion bentoml/testing/grpc/__init__.py
Expand Up @@ -155,6 +155,7 @@ async def create_channel(
@cached_contextmanager("{interceptors}")
def make_standalone_server(
interceptors: t.Sequence[aio.ServerInterceptor] | None = None,
host: str = "0.0.0.0",
) -> t.Generator[tuple[aio.Server, str], None, None]:
"""
Create a standalone aio.Server for testing.
Expand Down Expand Up @@ -203,7 +204,7 @@ def test_cases():
options=(("grpc.so_reuseport", 0),),
)
services_test.add_TestServiceServicer_to_server(TestServiceServicer(), server) # type: ignore (no async types)
server.add_insecure_port(f"[::]:{port}")
server.add_insecure_port(f"{host}:{port}")
print("Using port %d..." % port)
try:
yield server, "localhost:%d" % port
Expand Down
56 changes: 0 additions & 56 deletions tests/e2e/bento_server_grpc/tests/conftest.py
Expand Up @@ -6,19 +6,13 @@

import psutil
import pytest
from opentelemetry import trace as trace_api
from opentelemetry.sdk.trace import export
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.test.globals_test import reset_trace_globals
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter

from bentoml._internal.configuration.containers import BentoMLContainer

if TYPE_CHECKING:
from contextlib import ExitStack

from _pytest.nodes import Item as _PytestItem
from _pytest.config import Config

from bentoml._internal.server.metrics.prometheus import PrometheusClient

Expand All @@ -29,56 +23,6 @@ class FunctionItem(_PytestItem):
funcargs: dict[str, t.Any]


def create_tracer_provider(
**kwargs: t.Any,
) -> tuple[TracerProvider, InMemorySpanExporter]:
tracer_provider = TracerProvider(**kwargs)
memory_exporter = InMemorySpanExporter()
span_processor = export.SimpleSpanProcessor(memory_exporter)
tracer_provider.add_span_processor(span_processor)
return tracer_provider, memory_exporter


OTEL_MARKER = "otel"
SKIP_DEPLOYMENT = "skip_deployment_mode"


def pytest_configure(config: Config) -> None:
config.addinivalue_line(
"markers",
f"{OTEL_MARKER}: mark the test to use OpenTelemetry fixtures.",
)


def pytest_runtest_setup(item: FunctionItem):
marker = item.get_closest_marker(OTEL_MARKER)
if marker:
tracer_provider, memory_exporter = create_tracer_provider()
BentoMLContainer.tracer_provider.set(tracer_provider)
# This is done because set_tracer_provider cannot override the
# current tracer provider.
reset_trace_globals()
trace_api.set_tracer_provider(tracer_provider)
memory_exporter.clear()
# handling fixtures
fixturenames: list[str] = item.fixturenames
funcargs = item.funcargs
if "tracer_provider" in fixturenames:
fixturenames.remove("tracer_provider")
fixturenames.insert(0, "tracer_provider")
funcargs["tracer_provider"] = tracer_provider
if "memory_exporter" in fixturenames:
fixturenames.remove("memory_exporter")
fixturenames.insert(0, "memory_exporter")
funcargs["memory_exporter"] = memory_exporter


def pytest_runtest_teardown(item: FunctionItem, nextitem: FunctionItem | None):
if item.get_closest_marker(OTEL_MARKER):
reset_trace_globals()
BentoMLContainer.tracer_provider.reset()


@pytest.fixture(scope="module", name="metrics_client")
def fixture_metrics_client() -> PrometheusClient:
return BentoMLContainer.metrics_client.get()
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/bento_server_grpc/tests/test_meta.py
Expand Up @@ -17,20 +17,20 @@
@pytest.mark.asyncio
async def test_success_invocation_custom_servicer(host: str) -> None:
async with create_channel(host) as channel:
Check = channel.unary_unary(
HealthCheck = channel.unary_unary(
"/grpc.health.v1.Health/Check",
request_serializer=pb_health.HealthCheckRequest.SerializeToString, # type: ignore (no grpc_health type)
response_deserializer=pb_health.HealthCheckResponse.FromString, # type: ignore (no grpc_health type)
)
hc_resp = await t.cast(
health = await t.cast(
t.Awaitable[pb_health.HealthCheckResponse],
Check(
HealthCheck(
pb_health.HealthCheckRequest(
service="bentoml.testing.v1alpha1.TestService"
)
),
)
assert hc_resp.status == pb_health.HealthCheckResponse.SERVING # type: ignore ( no generated enum types)
assert health.status == pb_health.HealthCheckResponse.SERVING # type: ignore ( no generated enum types)
stub = services_test.TestServiceStub(channel) # type: ignore (no async types)
request = pb_test.ExecuteRequest(input="BentoML")
resp: pb_test.ExecuteResponse = await stub.Execute(request)
Expand Down
15 changes: 8 additions & 7 deletions tests/integration/conftest.py
@@ -1,5 +1,4 @@
from __future__ import annotations

import typing as t
import tempfile
from typing import TYPE_CHECKING

Expand All @@ -8,13 +7,15 @@
from bentoml._internal.models import ModelStore

if TYPE_CHECKING:
from _pytest.main import Session
from _pytest.nodes import Item
from _pytest.config import Config
from _pytest.config.argparsing import Parser


def pytest_addoption(parser: Parser) -> None:
def pytest_addoption(parser: "Parser") -> None:
parser.addoption(
"--runslow", action="store_true", default=False, help="run slow tests"
)
parser.addoption(
"--gpus", action="store_true", default=False, help="run gpus related tests"
)
Expand All @@ -26,7 +27,7 @@ def pytest_addoption(parser: Parser) -> None:
)


def pytest_collection_modifyitems(config: Config, items: list[Item]) -> None:
def pytest_collection_modifyitems(config: "Config", items: t.List["Item"]) -> None:
if config.getoption("--disable-tf-eager-execution"):
try:
from tensorflow.python.framework.ops import disable_eager_execution
Expand All @@ -46,8 +47,8 @@ def pytest_collection_modifyitems(config: Config, items: list[Item]) -> None:
item.add_marker(requires_eager_execution)


def pytest_sessionstart(session: Session): # pylint: disable=unused-argument
path = tempfile.mkdtemp("bentoml-pytest-unit")
def pytest_sessionstart(session):
path = tempfile.mkdtemp("bentoml-pytest")
from bentoml._internal.configuration.containers import BentoMLContainer

BentoMLContainer.model_store.set(ModelStore(path))
1 change: 0 additions & 1 deletion tests/unit/_internal/bento/test_bento.py
Expand Up @@ -332,7 +332,6 @@ def test_bento(dummy_model_store: ModelStore):
"src",
"env",
}
print(bento_fs.listdir("src"))
assert set(bento_fs.listdir("src")) == {
"simplebento.py",
"subdir",
Expand Down

0 comments on commit 735f2cb

Please sign in to comment.