Skip to content

Commit

Permalink
fix(sdk): Propagate transformer ID during re-deployment (#497)
Browse files Browse the repository at this point in the history
<!--  Thanks for sending a pull request!  Here are some tips for you:

1. Run unit tests and ensure that they are passing
2. If your change introduces any API changes, make sure to update the
e2e tests
3. Make sure documentation is updated for your PR!

-->

**What this PR does / why we need it**:
<!-- Explain here the context and why you're making the change. What is
the problem you're trying to solve. --->

This PR exposes the Transformer `id` to the SDK methods so that, in the
event of a model redeployment, the transformer's ID can be re-used to
trigger an update.

**Which issue(s) this PR fixes**:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->

Model redeployment capabilities were added to the SDK in
#455. With this, however,
transformer updates were not being done correctly and instead, a new
transformer entity would be attempted to be created with every version
endpoint update (re-deployment). The re-deployment operation would
eventually fail with an error like below, leaving the endpoint stuck in
the "pending" state:

```
unable to update endpoint status for model: abcd, version: 2, reason: ERROR: duplicate key value violates unique constraint "transformers_version_endpoint_id_key" (SQLSTATE 23505)
```

This PR addresses this issue by exposing the transformer's id to the SDK
and copying the id to the new transformer specs, during version endpoint
updates.

#### Summary of changes
* `swagger.yaml` - Update `Transformer` specs to include `id`
* `api/client/`, `python/sdk/client/` - Re-generate client code
* `python/sdk/merlin/endpoint.py` - Add `transformer` property to
`VersionEndpoint`
* `python/sdk/merlin/model.py`
    - Propagate transformer id during re-deployment
- Re-get the endpoint after a deployment so that its status would've
updated to "pending". When updating an endpoint (PUT), the status change
to "pending" is not immediate and may not be reflected in the response
from the update call.
* `python/sdk/merlin/transformer.py` - Add `id` property to the
`Transformer` class
* `python/sdk/test/integration_test.py` - Expand the re-deployment test
case to cover the id check for transformer. In the test case, the
Tensorflow model (which requires a specific input) is replaced with a
custom model so that the echo transformer can be used alongside.
* `python/sdk/test/model_test.py` - Update mock responses, owning to the
change in `python/sdk/merlin/model.py` to re-get the version endpoint
after deployment.

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required. Enter your extended release note in
the block below.
If the PR requires additional action from users switching to the new
release, include the string "action required".

For more information about release notes, see kubernetes' guide here:
http://git.k8s.io/community/contributors/guide/release-notes.md
-->

```release-note
Fix: Update transformer specs correctly when re-deploying a model through the SDK
```

**Checklist**

- [x] Added unit test, integration, and/or e2e tests
- [x] Tested locally
- [ ] Updated documentation
- [ ] Update Swagger spec if the PR introduce API changes
- [x] Regenerated Golang and Python client if the PR introduce API
changes
  • Loading branch information
krithika369 authored Nov 29, 2023
1 parent 3340e2f commit 67b0583
Show file tree
Hide file tree
Showing 19 changed files with 255 additions and 184 deletions.
15 changes: 6 additions & 9 deletions api/client/api_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ type AlertApiService service

/*
AlertApiService Lists teams for alert notification channel.
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return []string
*/
func (a *AlertApiService) AlertsTeamsGet(ctx context.Context) ([]string, *http.Response, error) {
Expand Down Expand Up @@ -125,9 +124,8 @@ func (a *AlertApiService) AlertsTeamsGet(ctx context.Context) ([]string, *http.R

/*
AlertApiService Lists alerts for given model.
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
@return []ModelEndpointAlert
*/
func (a *AlertApiService) ModelsModelIdAlertsGet(ctx context.Context, modelId int32) ([]ModelEndpointAlert, *http.Response, error) {
Expand Down Expand Up @@ -224,10 +222,9 @@ func (a *AlertApiService) ModelsModelIdAlertsGet(ctx context.Context, modelId in

/*
AlertApiService Gets alert for given model endpoint.
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param modelEndpointId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param modelEndpointId
@return ModelEndpointAlert
*/
func (a *AlertApiService) ModelsModelIdEndpointsModelEndpointIdAlertGet(ctx context.Context, modelId int32, modelEndpointId string) (ModelEndpointAlert, *http.Response, error) {
Expand Down
34 changes: 16 additions & 18 deletions api/client/api_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ type EndpointApiService service

/*
EndpointApiService Get all container belong to a version endpoint
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param versionId
- @param endpointId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param versionId
* @param endpointId
@return Container
*/
func (a *EndpointApiService) ModelsModelIdVersionsVersionIdEndpointEndpointIdContainersGet(ctx context.Context, modelId int32, versionId int32, endpointId string) (Container, *http.Response, error) {
Expand Down Expand Up @@ -131,10 +130,11 @@ func (a *EndpointApiService) ModelsModelIdVersionsVersionIdEndpointEndpointIdCon

/*
EndpointApiService Undeploy the specified model version deployment
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param versionId
- @param endpointId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param versionId
* @param endpointId
*/
func (a *EndpointApiService) ModelsModelIdVersionsVersionIdEndpointEndpointIdDelete(ctx context.Context, modelId int32, versionId int32, endpointId string) (*http.Response, error) {
var (
Expand Down Expand Up @@ -213,11 +213,10 @@ func (a *EndpointApiService) ModelsModelIdVersionsVersionIdEndpointEndpointIdDel

/*
EndpointApiService Get version endpoint resource
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param versionId
- @param endpointId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param versionId
* @param endpointId
@return VersionEndpoint
*/
func (a *EndpointApiService) ModelsModelIdVersionsVersionIdEndpointEndpointIdGet(ctx context.Context, modelId int32, versionId int32, endpointId string) (VersionEndpoint, *http.Response, error) {
Expand Down Expand Up @@ -431,10 +430,9 @@ func (a *EndpointApiService) ModelsModelIdVersionsVersionIdEndpointEndpointIdPut

/*
EndpointApiService List all endpoint of a model version
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param versionId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param versionId
@return []VersionEndpoint
*/
func (a *EndpointApiService) ModelsModelIdVersionsVersionIdEndpointGet(ctx context.Context, modelId int32, versionId int32) ([]VersionEndpoint, *http.Response, error) {
Expand Down
26 changes: 12 additions & 14 deletions api/client/api_model_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ type ModelEndpointsApiService service

/*
ModelEndpointsApiService List model endpoint
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
@return []ModelEndpoint
*/
func (a *ModelEndpointsApiService) ModelsModelIdEndpointsGet(ctx context.Context, modelId int32) ([]ModelEndpoint, *http.Response, error) {
Expand Down Expand Up @@ -127,9 +126,10 @@ func (a *ModelEndpointsApiService) ModelsModelIdEndpointsGet(ctx context.Context

/*
ModelEndpointsApiService Stop serving traffic to the model endpoint, then delete it.
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param modelEndpointId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param modelEndpointId
*/
func (a *ModelEndpointsApiService) ModelsModelIdEndpointsModelEndpointIdDelete(ctx context.Context, modelId int32, modelEndpointId string) (*http.Response, error) {
var (
Expand Down Expand Up @@ -207,10 +207,9 @@ func (a *ModelEndpointsApiService) ModelsModelIdEndpointsModelEndpointIdDelete(c

/*
ModelEndpointsApiService Get a model endpoint
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param modelEndpointId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param modelEndpointId
@return ModelEndpoint
*/
func (a *ModelEndpointsApiService) ModelsModelIdEndpointsModelEndpointIdGet(ctx context.Context, modelId int32, modelEndpointId string) (ModelEndpoint, *http.Response, error) {
Expand Down Expand Up @@ -421,10 +420,9 @@ func (a *ModelEndpointsApiService) ModelsModelIdEndpointsModelEndpointIdPut(ctx

/*
ModelEndpointsApiService Create a model endpoint
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param body Model endpoint object that has to be added
- @param modelId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param body Model endpoint object that has to be added
* @param modelId
@return ModelEndpoint
*/
func (a *ModelEndpointsApiService) ModelsModelIdEndpointsPost(ctx context.Context, body ModelEndpoint, modelId int32) (ModelEndpoint, *http.Response, error) {
Expand Down
29 changes: 12 additions & 17 deletions api/client/api_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ type ModelsApiService service

/*
ModelsApiService Lists teams for alert notification channel.
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return []string
*/
func (a *ModelsApiService) AlertsTeamsGet(ctx context.Context) ([]string, *http.Response, error) {
Expand Down Expand Up @@ -125,9 +124,8 @@ func (a *ModelsApiService) AlertsTeamsGet(ctx context.Context) ([]string, *http.

/*
ModelsApiService Lists alerts for given model.
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
@return []ModelEndpointAlert
*/
func (a *ModelsApiService) ModelsModelIdAlertsGet(ctx context.Context, modelId int32) ([]ModelEndpointAlert, *http.Response, error) {
Expand Down Expand Up @@ -224,10 +222,9 @@ func (a *ModelsApiService) ModelsModelIdAlertsGet(ctx context.Context, modelId i

/*
ModelsApiService Gets alert for given model endpoint.
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param modelEndpointId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param modelEndpointId
@return ModelEndpointAlert
*/
func (a *ModelsApiService) ModelsModelIdEndpointsModelEndpointIdAlertGet(ctx context.Context, modelId int32, modelEndpointId string) (ModelEndpointAlert, *http.Response, error) {
Expand Down Expand Up @@ -621,10 +618,9 @@ func (a *ModelsApiService) ProjectsProjectIdModelsGet(ctx context.Context, proje

/*
ModelsApiService Delete model
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param projectId project id of the project to be deleted
- @param modelId model id of the model to be deleted
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param projectId project id of the project to be deleted
* @param modelId model id of the model to be deleted
@return int32
*/
func (a *ModelsApiService) ProjectsProjectIdModelsModelIdDelete(ctx context.Context, projectId int32, modelId int32) (int32, *http.Response, error) {
Expand Down Expand Up @@ -722,10 +718,9 @@ func (a *ModelsApiService) ProjectsProjectIdModelsModelIdDelete(ctx context.Cont

/*
ModelsApiService Get model
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param projectId project id of the project to be retrieved
- @param modelId model id of the model to be retrieved
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param projectId project id of the project to be retrieved
* @param modelId model id of the model to be retrieved
@return []Model
*/
func (a *ModelsApiService) ProjectsProjectIdModelsModelIdGet(ctx context.Context, projectId int32, modelId int32) ([]Model, *http.Response, error) {
Expand Down
34 changes: 16 additions & 18 deletions api/client/api_prediction_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ type PredictionJobsApiService service

/*
PredictionJobsApiService List all prediction jobs of a model version
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param versionId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param versionId
@return []PredictionJob
*/
func (a *PredictionJobsApiService) ModelsModelIdVersionsVersionIdJobsGet(ctx context.Context, modelId int32, versionId int32) ([]PredictionJob, *http.Response, error) {
Expand Down Expand Up @@ -129,11 +128,10 @@ func (a *PredictionJobsApiService) ModelsModelIdVersionsVersionIdJobsGet(ctx con

/*
PredictionJobsApiService Get all container belong to a prediction job
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param versionId
- @param jobId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param versionId
* @param jobId
@return Container
*/
func (a *PredictionJobsApiService) ModelsModelIdVersionsVersionIdJobsJobIdContainersGet(ctx context.Context, modelId int32, versionId int32, jobId string) (Container, *http.Response, error) {
Expand Down Expand Up @@ -232,11 +230,10 @@ func (a *PredictionJobsApiService) ModelsModelIdVersionsVersionIdJobsJobIdContai

/*
PredictionJobsApiService Get prediction jobs with given id
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param versionId
- @param jobId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param versionId
* @param jobId
@return PredictionJob
*/
func (a *PredictionJobsApiService) ModelsModelIdVersionsVersionIdJobsJobIdGet(ctx context.Context, modelId int32, versionId int32, jobId int32) (PredictionJob, *http.Response, error) {
Expand Down Expand Up @@ -335,10 +332,11 @@ func (a *PredictionJobsApiService) ModelsModelIdVersionsVersionIdJobsJobIdGet(ct

/*
PredictionJobsApiService Stop prediction jobs with given id
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param versionId
- @param jobId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param versionId
* @param jobId
*/
func (a *PredictionJobsApiService) ModelsModelIdVersionsVersionIdJobsJobIdStopPut(ctx context.Context, modelId int32, versionId int32, jobId int32) (*http.Response, error) {
var (
Expand Down
17 changes: 7 additions & 10 deletions api/client/api_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ func (a *ProjectApiService) ProjectsGet(ctx context.Context, localVarOptionals *

/*
ProjectApiService Create new project
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param body Project object that has to be added
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param body Project object that has to be added
@return Project
*/
func (a *ProjectApiService) ProjectsPost(ctx context.Context, body Project) (Project, *http.Response, error) {
Expand Down Expand Up @@ -235,9 +234,8 @@ func (a *ProjectApiService) ProjectsPost(ctx context.Context, body Project) (Pro

/*
ProjectApiService Get project
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param projectId project id of the project to be retrieved
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param projectId project id of the project to be retrieved
@return Project
*/
func (a *ProjectApiService) ProjectsProjectIdGet(ctx context.Context, projectId int32) (Project, *http.Response, error) {
Expand Down Expand Up @@ -334,10 +332,9 @@ func (a *ProjectApiService) ProjectsProjectIdGet(ctx context.Context, projectId

/*
ProjectApiService Update project
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param body Project object that has to be updated
- @param projectId project id of the project to be updated
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param body Project object that has to be updated
* @param projectId project id of the project to be updated
@return Project
*/
func (a *ProjectApiService) ProjectsProjectIdPut(ctx context.Context, body Project, projectId int32) (Project, *http.Response, error) {
Expand Down
12 changes: 6 additions & 6 deletions api/client/api_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ type SecretApiService service

/*
SecretApiService List secret
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param projectId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param projectId
@return []Secret
*/
func (a *SecretApiService) ProjectsProjectIdSecretsGet(ctx context.Context, projectId int32) ([]Secret, *http.Response, error) {
Expand Down Expand Up @@ -238,9 +237,10 @@ func (a *SecretApiService) ProjectsProjectIdSecretsPost(ctx context.Context, pro

/*
SecretApiService Delete secret
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param projectId
- @param secretId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param projectId
* @param secretId
*/
func (a *SecretApiService) ProjectsProjectIdSecretsSecretIdDelete(ctx context.Context, projectId int32, secretId int32) (*http.Response, error) {
var (
Expand Down
14 changes: 6 additions & 8 deletions api/client/api_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,9 @@ func (a *VersionApiService) ModelsModelIdVersionsPost(ctx context.Context, model

/*
VersionApiService Delete version by ID from model
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param versionId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param versionId
@return int32
*/
func (a *VersionApiService) ModelsModelIdVersionsVersionIdDelete(ctx context.Context, modelId int32, versionId int32) (int32, *http.Response, error) {
Expand Down Expand Up @@ -358,10 +357,9 @@ func (a *VersionApiService) ModelsModelIdVersionsVersionIdDelete(ctx context.Con

/*
VersionApiService Get version by ID from model
- @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
- @param modelId
- @param versionId
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param modelId
* @param versionId
@return Version
*/
func (a *VersionApiService) ModelsModelIdVersionsVersionIdGet(ctx context.Context, modelId int32, versionId int32) (Version, *http.Response, error) {
Expand Down
1 change: 1 addition & 0 deletions api/client/model_transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

type Transformer struct {
Id string `json:"id,omitempty"`
Enabled bool `json:"enabled,omitempty"`
TransformerType string `json:"transformer_type,omitempty"`
Image string `json:"image,omitempty"`
Expand Down
Loading

0 comments on commit 67b0583

Please sign in to comment.