Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bojiang committed Nov 3, 2022
1 parent 90c881b commit 351adf5
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions src/bentoml/_internal/monitoring/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from simple_di import Provide

from ..types import LazyType
from ..context import trace_context
from ..context import component_context
from ..configuration.containers import BentoMLContainer

Expand Down Expand Up @@ -241,7 +242,6 @@ def log(
name: str,
role: str,
data_type: str,
ignore_existing: bool = False,
) -> None:
"""
log a data with column name, role and type to the current record
Expand All @@ -261,15 +261,14 @@ def log(
"role": role,
"type": data_type,
}
elif not ignore_existing:
raise ValueError(
f"Column {name} already exists. Please use a different name."
else:
logger.warning(
"Column %s already exists. Will use the existing column meta.",
name,
)
if self._is_first_column:
self._is_first_column = False

from ..context import trace_context

# universal columns
self._columns[self.COLUMN_TIME].append(datetime.datetime.now().isoformat())
self._columns[self.COLUMN_RID].append(trace_context.request_id)
Expand All @@ -286,13 +285,42 @@ def log_batch(
"""
Log a batch of data. The data will be logged as a single column.
"""
if name in self.PRESERVED_COLUMNS:
raise ValueError(
f"Column name {name} is preserved. Please use a different name."
)

assert role in BENTOML_MONITOR_ROLES, f"Invalid role {role}"
assert data_type in BENTOML_MONITOR_TYPES, f"Invalid data type {data_type}"

if self._is_first_record:
if name not in self._column_meta:
self._column_meta[name] = {
"name": name,
"role": role,
"type": data_type,
}
else:
logger.warning(
"Column %s already exists. Will use the existing column meta.",
name,
)

try:
for data in data_batch:
self.log(data, name, role, data_type, ignore_existing=True)
if self._is_first_column:
# universal columns
self._columns[self.COLUMN_TIME].append(
datetime.datetime.now().isoformat()
)
self._columns[self.COLUMN_RID].append(trace_context.request_id)
self._columns[name].append(data)
except TypeError:
raise ValueError(
"data_batch is not iterable. Please use log() to log a single data."
) from None
if self._is_first_column:
self._is_first_column = False

def log_table(
self,
Expand Down

0 comments on commit 351adf5

Please sign in to comment.