Skip to content

Commit

Permalink
chore: add backward layer
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 Nov 24, 2022
1 parent a77ba28 commit 3d3af62
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 107 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Expand Up @@ -236,6 +236,7 @@ exclude = '''
| src/bentoml/grpc/v1
| tests/proto
| grpc-client/thirdparty
| grpc-client/bentoml
)/
| src/bentoml/_version.py
)
Expand Down
8 changes: 1 addition & 7 deletions src/bentoml/_internal/configuration/__init__.py
Expand Up @@ -13,18 +13,12 @@
from ..._version import __version__
from ..._version import __version_tuple__
except ImportError:
<<<<<<< HEAD
# Since we aren't VCS _version.py, which is generated by setuptools_scm
# BentoML uses setuptools_scm 'post-release' for version scheme
from setuptools_scm import get_version

__version__ = get_version(version_scheme="post-release")
__version_tuple__ = (0, 0, 0, "dirty")
=======
# broken installation.
__version__ = "unknown"
__version_tuple__ = (0, 0, 0, "unknown")
>>>>>>> efb2b979 (revert: unrelated change)


# Note this file is loaded prior to logging being configured, thus logger is only
Expand Down Expand Up @@ -164,7 +158,7 @@ def load_config(bentoml_config_file: str | None = None):
)


def save_global_config(config_file_handle: t.IO[t.Any]):
def save_config(config_file_handle: t.IO[t.Any]):
import yaml

from ..configuration.containers import BentoMLContainer
Expand Down
27 changes: 17 additions & 10 deletions src/bentoml/_internal/configuration/containers.py
Expand Up @@ -228,13 +228,20 @@ def serve_info() -> ServeInfo:
@providers.SingletonFactory
@staticmethod
def access_control_options(
allow_origin: str | None = Provide[cors.allow_origin],
allow_origin_regex: str | None = Provide[cors.allow_origin_regex],
allow_credentials: bool | None = Provide[cors.allow_credentials],
allow_methods: list[str] | str | None = Provide[cors.allow_methods],
allow_headers: list[str] | str | None = Provide[cors.allow_headers],
max_age: int | None = Provide[cors.max_age],
expose_headers: list[str] | str | None = Provide[cors.expose_headers],
allow_origin: str | None = Provide[cors.access_control_allow_origin],
allow_origin_regex: str
| None = Provide[cors.access_control_allow_origin_regex],
allow_credentials: bool | None = Provide[cors.access_control_allow_credentials],
allow_methods: list[str]
| str
| None = Provide[cors.access_control_allow_methods],
allow_headers: list[str]
| str
| None = Provide[cors.access_control_allow_headers],
max_age: int | None = Provide[cors.access_control_max_age],
expose_headers: list[str]
| str
| None = Provide[cors.access_control_expose_headers],
) -> dict[str, list[str] | str | int]:
return {
k: v
Expand Down Expand Up @@ -270,7 +277,7 @@ def metrics_client(

return PrometheusClient(multiproc_dir=multiproc_dir)

tracing = api_server_config.tracing
tracing = config.tracing

@providers.SingletonFactory
@staticmethod
Expand Down Expand Up @@ -299,8 +306,8 @@ def tracer_provider(
if sample_rate is None:
sample_rate = 0.0
if sample_rate == 0.0:
logger.warning(
"'api_server.tracing.sample_rate' is set to zero. No traces will be collected. Please refer to https://docs.bentoml.org/en/latest/guides/tracing.html for more details."
logger.debug(
"'tracing.sample_rate' is set to zero. No traces will be collected. Please refer to https://docs.bentoml.org/en/latest/guides/tracing.html for more details."
)
resource = {}
# User can optionally configure the resource with the following environment variables. Only
Expand Down
2 changes: 1 addition & 1 deletion src/bentoml/_internal/configuration/helpers.py
Expand Up @@ -36,7 +36,7 @@ def depth(_: t.Any, _level: int = 0): # pragma: no cover


@depth.register(dict)
def _dict_depth(d: dict[str, t.Any], level: int = 0, **kw: t.Any): # type: ignore # pylint: disable
def _(d: dict[str, t.Any], level: int = 0, **kw: t.Any):
return max(depth(v, level + 1, **kw) for v in d.values())


Expand Down
36 changes: 16 additions & 20 deletions src/bentoml/_internal/configuration/v1/__init__.py
Expand Up @@ -96,13 +96,15 @@
"port": s.And(int, ensure_larger_than_zero),
"cors": {
"enabled": bool,
"allow_origin": s.Or(str, None),
"allow_origin_regex": s.Or(s.And(str, s.Use(re.compile)), None),
"allow_credentials": s.Or(bool, None),
"allow_headers": s.Or([str], str, None),
"allow_methods": s.Or([str], str, None),
"max_age": s.Or(int, None),
"expose_headers": s.Or([str], str, None),
"access_control_allow_origin": s.Or(str, None),
"access_control_allow_origin_regex": s.Or(
s.And(str, s.Use(re.compile)), None
),
"access_control_allow_credentials": s.Or(bool, None),
"access_control_allow_headers": s.Or([str], str, None),
"access_control_allow_methods": s.Or([str], str, None),
"access_control_max_age": s.Or(int, None),
"access_control_expose_headers": s.Or([str], str, None),
},
},
"grpc": {
Expand All @@ -118,7 +120,6 @@
"max_message_length": s.Or(int, None),
"maximum_concurrent_rpcs": s.Or(int, None),
},
"tracing": TRACING_CFG,
s.Optional("ssl"): {
"enabled": bool,
s.Optional("certfile"): s.Or(str, None),
Expand Down Expand Up @@ -167,6 +168,7 @@
**_RUNNER_CONFIG,
s.Optional(str): _RUNNER_CONFIG,
},
"tracing": TRACING_CFG,
s.Optional("monitoring"): {
"enabled": bool,
s.Optional("type"): s.Or(str, None),
Expand Down Expand Up @@ -216,7 +218,7 @@ def migration(*, override_config: dict[str, t.Any]):
rename_fields(
override_config,
current=f"api_server.cors.access_control_{f}",
replace_with=f"api_server.http.cors.{f}",
replace_with=f"api_server.http.cors.access_control_{f}",
)

# 4. if ssl is present, in version 2 we introduce a api_server.ssl.enabled field to determine
Expand All @@ -229,31 +231,25 @@ def migration(*, override_config: dict[str, t.Any]):
rename_fields(
override_config,
current="tracing.type",
replace_with="api_server.tracing.exporter_type",
replace_with="tracing.exporter_type",
)
for f in ["sample_rate", "excluded_urls"]:
rename_fields(
override_config,
current=f"tracing.{f}",
replace_with=f"api_server.tracing.{f}",
)
# 5.2. for Zipkin and OTLP, migrate tracing.[exporter].url -> api_server.tracing.[exporter].endpoint
for exporter in ["zipkin", "otlp"]:
rename_fields(
override_config,
current=f"tracing.{exporter}.url",
replace_with=f"api_server.tracing.{exporter}.endpoint",
replace_with=f"tracing.{exporter}.endpoint",
)
# 5.3. For Jaeger, migrate tracing.jaeger.[address|port] -> api_server.tracing.jaeger.thrift.[agent_host_name|agent_port]
rename_fields(
override_config,
current="tracing.jaeger.address",
replace_with="api_server.tracing.jaeger.thrift.agent_host_name",
replace_with="tracing.jaeger.thrift.agent_host_name",
)
rename_fields(
override_config,
current="tracing.jaeger.port",
replace_with="api_server.tracing.jaeger.thrift.agent_port",
replace_with="tracing.jaeger.thrift.agent_port",
)
# we also need to choose which protocol to use for jaeger.
if (
Expand All @@ -266,7 +262,7 @@ def migration(*, override_config: dict[str, t.Any]):
)
!= 0
):
override_config["api_server.tracing.jaeger.protocol"] = "thrift"
override_config["tracing.jaeger.protocol"] = "thrift"
# 6. Last but not least, moving logging.formatting.* -> api_server.logging.access.format.*
for f in ["trace_id", "span_id"]:
rename_fields(
Expand Down
74 changes: 37 additions & 37 deletions src/bentoml/_internal/configuration/v1/default_configuration.yaml
Expand Up @@ -52,13 +52,13 @@ api_server:
port: 3000
cors:
enabled: false
allow_origin: ~
allow_credentials: ~
allow_methods: ~
allow_headers: ~
allow_origin_regex: ~
max_age: ~
expose_headers: ~
access_control_allow_origin: ~
access_control_allow_credentials: ~
access_control_allow_methods: ~
access_control_allow_headers: ~
access_control_allow_origin_regex: ~
access_control_max_age: ~
access_control_expose_headers: ~
grpc:
host: 0.0.0.0
port: 3000
Expand All @@ -72,36 +72,6 @@ api_server:
metrics:
host: 0.0.0.0
port: 3001
tracing:
exporter_type: ~
sample_rate: ~
excluded_urls: ~
timeout: ~
max_tag_value_length: ~
zipkin:
endpoint: ~
local_node_ipv4: ~
local_node_ipv6: ~
local_node_port: ~
jaeger:
protocol: thrift
collector_endpoint: ~
thrift:
agent_host_name: ~
agent_port: ~
udp_split_oversized_batches: ~
grpc:
insecure: ~
otlp:
protocol: ~
endpoint: ~
compression: ~
http:
certificate_file: ~
headers: ~
grpc:
headers: ~
insecure: ~
runner_probe: # configure whether the API server's health check endpoints (readyz, livez, healthz) also check the runners
enabled: true
timeout: 1
Expand All @@ -123,6 +93,36 @@ runners:
metrics:
enabled: true
namespace: bentoml_runner
tracing:
exporter_type: ~
sample_rate: ~
excluded_urls: ~
timeout: ~
max_tag_value_length: ~
zipkin:
endpoint: ~
local_node_ipv4: ~
local_node_ipv6: ~
local_node_port: ~
jaeger:
protocol: thrift
collector_endpoint: ~
thrift:
agent_host_name: ~
agent_port: ~
udp_split_oversized_batches: ~
grpc:
insecure: ~
otlp:
protocol: ~
endpoint: ~
compression: ~
http:
certificate_file: ~
headers: ~
grpc:
headers: ~
insecure: ~
monitoring:
enabled: true
type: default
Expand Down
3 changes: 1 addition & 2 deletions src/bentoml/_internal/runner/runner_handle/remote.py
Expand Up @@ -22,7 +22,6 @@

if TYPE_CHECKING:
import yarl
import aiohttp
from aiohttp import BaseConnector
from aiohttp.client import ClientSession

Expand Down Expand Up @@ -114,7 +113,7 @@ def strip_query_params(url: yarl.URL) -> str:
trace_configs=[
create_trace_config(
# Remove all query params from the URL attribute on the span.
url_filter=strip_query_params, # type: ignore
url_filter=strip_query_params,
tracer_provider=BentoMLContainer.tracer_provider.get(),
)
],
Expand Down
2 changes: 1 addition & 1 deletion src/bentoml/_internal/utils/lazy_loader.py
Expand Up @@ -30,7 +30,7 @@ def __init__(
name: str,
warning: str | None = None,
exc_msg: str | None = None,
exc: t.Type[Exception] = MissingDependencyException,
exc: type[Exception] = MissingDependencyException,
):
self._local_name = local_name
self._parent_module_globals = parent_module_globals
Expand Down

0 comments on commit 3d3af62

Please sign in to comment.