Skip to content

Commit

Permalink
[Model Monitoring] Fix SQL store with multiple filter criteria (#5629)
Browse files Browse the repository at this point in the history
  • Loading branch information
jond01 committed May 27, 2024
1 parent cb4a548 commit 76e658b
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 141 deletions.
60 changes: 37 additions & 23 deletions mlrun/model_monitoring/db/stores/sqldb/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional, Union
from functools import partial
from typing import Optional, TypeVar, Union

from .mysql import ApplicationResultTable as MySQLApplicationResultTable
from .mysql import ModelEndpointsTable as MySQLModelEndpointsTable
Expand All @@ -21,29 +22,42 @@
from .sqlite import ModelEndpointsTable as SQLiteModelEndpointsTable
from .sqlite import MonitoringSchedulesTable as SQLiteMonitoringSchedulesTable

MySQLTableType = TypeVar("MySQLTableType")
SQLiteTableType = TypeVar("SQLiteTableType")

def _get_model_endpoints_table(
connection_string: Optional[str] = None,
) -> Union[type[MySQLModelEndpointsTable], type[SQLiteModelEndpointsTable]]:
"""Return ModelEndpointsTable based on the provided connection string"""
if connection_string and "mysql:" in connection_string:
return MySQLModelEndpointsTable
return SQLiteModelEndpointsTable


def _get_application_result_table(
connection_string: Optional[str] = None,
) -> Union[type[MySQLApplicationResultTable], type[SQLiteApplicationResultTable]]:
"""Return ModelEndpointsTable based on the provided connection string"""
if connection_string and "mysql:" in connection_string:
return MySQLApplicationResultTable
return SQLiteApplicationResultTable
_MYSQL_SCHEME = "mysql:"


def _get_monitoring_schedules_table(
def _get_sql_table(
*,
mysql_table: MySQLTableType,
sqlite_table: SQLiteTableType,
connection_string: Optional[str] = None,
) -> Union[type[MySQLMonitoringSchedulesTable], type[SQLiteMonitoringSchedulesTable]]:
"""Return ModelEndpointsTable based on the provided connection string"""
if connection_string and "mysql:" in connection_string:
return MySQLMonitoringSchedulesTable
return SQLiteMonitoringSchedulesTable
) -> Union[MySQLTableType, SQLiteTableType]:
"""
Return a SQLAlchemy table for MySQL or SQLite according to the connection string.
Note: this function should not be directly used in other modules.
"""
if connection_string and _MYSQL_SCHEME in connection_string:
return mysql_table
return sqlite_table


_get_model_endpoints_table = partial(
_get_sql_table,
mysql_table=MySQLModelEndpointsTable,
sqlite_table=SQLiteModelEndpointsTable,
)


_get_application_result_table = partial(
_get_sql_table,
mysql_table=MySQLApplicationResultTable,
sqlite_table=SQLiteApplicationResultTable,
)

_get_monitoring_schedules_table = partial(
_get_sql_table,
mysql_table=MySQLMonitoringSchedulesTable,
sqlite_table=SQLiteMonitoringSchedulesTable,
)
Loading

0 comments on commit 76e658b

Please sign in to comment.