Skip to content

Commit

Permalink
[Model Monitoring] Replace endpoint_id with uid to handle old mod…
Browse files Browse the repository at this point in the history
…el endpoint schemas (#3667)
  • Loading branch information
Eyal-Danieli committed May 30, 2023
1 parent 78f89fa commit 65dd220
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mlrun/model_monitoring/stores/kv_model_endpoint_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_model_endpoint(
raise mlrun.errors.MLRunNotFoundError(f"Endpoint {endpoint_id} not found")

# For backwards compatability: replace null values for `error_count` and `metrics`
mlrun.utils.model_monitoring.validate_errors_and_metrics(endpoint=endpoint)
mlrun.utils.model_monitoring.validate_old_schema_fields(endpoint=endpoint)

return endpoint

Expand Down
16 changes: 11 additions & 5 deletions mlrun/utils/model_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def get_stream_path(project: str = None):
"""Get stream path from the project secret. If wasn't set, take it from the system configurations"""

if is_running_as_api():

# Running on API server side
import mlrun.api.crud.secrets
import mlrun.common.schemas
Expand All @@ -179,7 +178,6 @@ def get_stream_path(project: str = None):
)

else:

import mlrun

stream_uri = mlrun.get_secret_or_env(
Expand All @@ -205,11 +203,13 @@ def get_stream_path(project: str = None):
return stream_uri


def validate_errors_and_metrics(endpoint: dict):
def validate_old_schema_fields(endpoint: dict):
"""
Replace default null values for `error_count` and `metrics` for users that logged a model endpoint before 1.3.0
Replace default null values for `error_count` and `metrics` for users that logged a model endpoint before 1.3.0.
In addition, this function also validates that the key name of the endpoint unique id is `uid` and not
`endpoint_id` that has been used before 1.3.0.
Leaving here for backwards compatibility which related to the model endpoint schema
Leaving here for backwards compatibility which related to the model endpoint schema.
:param endpoint: An endpoint flattened dictionary.
"""
Expand Down Expand Up @@ -241,3 +241,9 @@ def validate_errors_and_metrics(endpoint: dict):
}
}
)
# Validate key `uid` instead of `endpoint_id`
# For backwards compatibility reasons, we replace the `endpoint_id` with `uid` which is the updated key name
if model_monitoring_constants.EventFieldType.ENDPOINT_ID in endpoint:
endpoint[model_monitoring_constants.EventFieldType.UID] = endpoint[
model_monitoring_constants.EventFieldType.ENDPOINT_ID
]

0 comments on commit 65dd220

Please sign in to comment.