Skip to content

Commit

Permalink
consistency with scouter server
Browse files Browse the repository at this point in the history
  • Loading branch information
thorrester committed Oct 9, 2024
1 parent e4939e5 commit f17a1a1
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 22 deletions.
18 changes: 13 additions & 5 deletions opsml/app/routes/scouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def insert_profile(request: Request, payload: DriftProfileRequest) -> Success:
return Success()
except Exception as error:
logger.error(f"Failed to insert drift profile: {error}")
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to insert drift profile") from error
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to insert drift profile"
) from error


@router.put("/scouter/drift/profile", name="update_drift_profile", response_model=ProfileUpdateResponse)
Expand Down Expand Up @@ -148,7 +150,9 @@ def update_profile(request: Request, payload: DriftProfileUpdateRequest) -> Prof
return ProfileUpdateResponse()
except Exception as error:
logger.error(f"Failed to insert drift profile: {error}")
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to insert drift profile") from error
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to insert drift profile"
) from error


@router.get("/scouter/drift/profile", name="get_profile", response_model=GetDriftProfileResponse)
Expand Down Expand Up @@ -181,7 +185,9 @@ def get_profile(
return GetDriftProfileResponse(profile=profile)
except Exception as error:
logger.error(f"Failed to get drift profile: {error}")
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to get drift profile") from error
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to get drift profile"
) from error


@router.get("/scouter/drift/values", name="get_drift", response_model=DriftResponse)
Expand Down Expand Up @@ -231,7 +237,9 @@ def get_drift_values(
return DriftResponse(**values)
except Exception as error:
logger.error(f"Failed to get drift values: {error}")
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to get drift values") from error
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to get drift values"
) from error


@router.get("/scouter/feature/distribution", name="feature distribution", response_model=FeatureDistribution)
Expand Down Expand Up @@ -436,7 +444,7 @@ def update_profile_status(
repository=payload.repository,
name=payload.name,
version=payload.version,
status=payload.status,
active=payload.active,
)

return UpdateAlert(**values)
Expand Down
4 changes: 2 additions & 2 deletions opsml/scouter/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def update_drift_profile(
},
)

def update_drift_profile_status(self, repository: str, name: str, version: str, status: bool) -> Dict[str, str]:
def update_drift_profile_status(self, repository: str, name: str, version: str, active: bool) -> Dict[str, str]:
"""Updates drift profile status into scouter server
Args:
Expand All @@ -82,7 +82,7 @@ def update_drift_profile_status(self, repository: str, name: str, version: str,
"name": name,
"repository": repository,
"version": version,
"status": status,
"active": active,
},
)

Expand Down
6 changes: 3 additions & 3 deletions opsml/scouter/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def healthcheck(self) -> bool:
except Exception:
return False

def update_profile_status(self, repository: str, name: str, version: str, status: bool) -> None:
def update_profile_status(self, repository: str, name: str, version: str, active: bool) -> None:
"""Sets the profile to active
Args:
Expand All @@ -67,15 +67,15 @@ def update_profile_status(self, repository: str, name: str, version: str, status
Model name
version:
Model version
status:
active:
Status to set
"""

self._scouter_client.update_drift_profile_status(
repository=repository,
name=name,
version=version,
status=status,
active=active,
)

def insert_drift_profile(self, drift_profile: str, drift_type: DriftType) -> None:
Expand Down
4 changes: 2 additions & 2 deletions opsml/scouter/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def update_drift_profile(
data = {"profile": json.loads(drift_profile), "drift_type": drift_type.value}
return self.request(route=ScouterRoutes.PROFILE, request_type=RequestType.PUT, json=data)

def update_drift_profile_status(self, repository: str, name: str, version: str, status: bool) -> Dict[str, str]:
def update_drift_profile_status(self, repository: str, name: str, version: str, active: bool) -> Dict[str, str]:
"""Updates drift profile status into scouter server
Args:
Expand All @@ -120,7 +120,7 @@ def update_drift_profile_status(self, repository: str, name: str, version: str,
"repository": repository,
"name": name,
"version": version,
"status": status,
"active": active,
},
)

Expand Down
2 changes: 1 addition & 1 deletion opsml/scouter/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ class UpdateProfileStatus(BaseModel):
name: str
repository: str
version: str
status: bool
active: bool
4 changes: 3 additions & 1 deletion tests/test_app/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ def test_register_model_data(
modelcard, datacard = populate_model_data_for_api

assert api_storage_client.exists(Path(datacard.uri, SaveName.CARD.value).with_suffix(Suffix.JSON.value))
assert api_storage_client.exists(Path(datacard.uri, SaveName.DATA.value).with_suffix(datacard.interface.data_suffix))
assert api_storage_client.exists(
Path(datacard.uri, SaveName.DATA.value).with_suffix(datacard.interface.data_suffix)
)

assert api_storage_client.exists(Path(modelcard.uri, SaveName.TRAINED_MODEL.value).with_suffix(".joblib"))
assert api_storage_client.exists(Path(modelcard.uri, SaveName.ONNX_MODEL.value).with_suffix(Suffix.ONNX.value))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_registry/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import polars as pl
import pytest
from pytest_lazyfixture import lazy_fixture
from opsml.scouter import SpcDriftConfig
from sqlalchemy import select

from opsml.cards import (
Expand All @@ -38,6 +37,7 @@
from opsml.registry.records import registry_name_record_map
from opsml.registry.sql.base.query_engine import DialectHelper
from opsml.registry.sql.base.sql_schema import DataSchema
from opsml.scouter import SpcDriftConfig
from tests.conftest import FOURTEEN_DAYS_STR, FOURTEEN_DAYS_TS, OPSML_TRACKING_URI


Expand Down
13 changes: 6 additions & 7 deletions tests/test_scouter/test_client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import pytest
from typing import Generator, Any
from unittest import mock
from opsml.scouter import DriftType
from opsml.storage.api import RequestType, api_routes
from opsml.scouter.client import ScouterApiClient
from starlette.testclient import TestClient


from opsml.registry import CardRegistries
from opsml.scouter.client import ScouterApiClient


@mock.patch("opsml.scouter.server.ScouterServerClient.healthcheck")
Expand All @@ -19,7 +16,9 @@ def test_healthcheck(server: mock.MagicMock, mock_request: mock.MagicMock, api_r

@mock.patch("opsml.scouter.server.ScouterServerClient.update_drift_profile_status")
@mock.patch("opsml.scouter.integration.ScouterClient.server_running")
def test_update_profile_status(server: mock.MagicMock, mock_request: mock.MagicMock, api_registries: CardRegistries) -> None:
def test_update_profile_status(
server: mock.MagicMock, mock_request: mock.MagicMock, api_registries: CardRegistries
) -> None:
server.return_value = True
mock_request.return_value = {"status": "success", "message": "Profile updated"}
client = ScouterApiClient()
Expand Down

0 comments on commit f17a1a1

Please sign in to comment.