feat: model experiments wait handler#7800
Conversation
| ) | ||
|
|
||
| // CreateMExpInstanceWaitHandler will wait for creation of Model Experiments instance | ||
| func CreateMExpInstanceWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceResponse] { |
There was a problem hiding this comment.
| func CreateMExpInstanceWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceResponse] { | |
| func CreateModelExperimentsInstanceWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceResponse] { |
| ActiveState: []modelexperiments.InstanceState{modelexperiments.INSTANCESTATE_ACTIVE}, | ||
| ErrorState: []modelexperiments.InstanceState{modelexperiments.INSTANCESTATE_IMPAIRED}, | ||
| } | ||
| handler := wait.New(waitConfig.Wait()) |
There was a problem hiding this comment.
| handler := wait.New(waitConfig.Wait()) | |
| handler := wait.New(waitConfig.Wait()) | |
| handler.SetTimeout(10 * time.Minute) | |
| return handler |
| } | ||
|
|
||
| // DeleteMExpInstanceWaitHandler will wait for deletion of Model Experiments instance | ||
| func DeleteMExpInstanceWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceResponse] { |
There was a problem hiding this comment.
| func DeleteMExpInstanceWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceResponse] { | |
| func DeleteModelExperimentsInstanceWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceResponse] { |
| }, | ||
| DeleteHttpErrorStatusCodes: []int{http.StatusNotFound}, | ||
| } | ||
| handler := wait.New(waitConfig.Wait()) |
There was a problem hiding this comment.
Like mentioned in create function, please group handler and following lines together.
| } | ||
|
|
||
| // CreateMExpTokenWait Handler will wait for creation of Model Experiments instance token | ||
| func CreateMExpInstanceTokenWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId, tokenId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceTokenResponse] { |
There was a problem hiding this comment.
| func CreateMExpInstanceTokenWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId, tokenId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceTokenResponse] { | |
| func CreateModelExperimentsInstanceTokenWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId, tokenId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceTokenResponse] { |
| ActiveState: []modelexperiments.TokenState{modelexperiments.TOKENSTATE_ACTIVE}, | ||
| ErrorState: []modelexperiments.TokenState{}, | ||
| } | ||
| handler := wait.New(waitConfig.Wait()) |
| } | ||
|
|
||
| // DeleteMExpInstanceTokenWaitHandler will wait for deletion of Model Experiments instance token | ||
| func DeleteMExpInstanceTokenWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId, tokenId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceTokenResponse] { |
There was a problem hiding this comment.
| func DeleteMExpInstanceTokenWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId, tokenId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceTokenResponse] { | |
| func DeleteModelExperimentsInstanceTokenWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId, tokenId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceTokenResponse] { |
| }, | ||
| DeleteHttpErrorStatusCodes: []int{http.StatusNotFound}, | ||
| } | ||
| handler := wait.New(waitConfig.Wait()) |
| } | ||
| } | ||
|
|
||
| func TestCreateMExpInstanceWaitHandler(t *testing.T) { |
There was a problem hiding this comment.
Please adapt test names also
|
|
||
| modelexperimentsClient, err := modelexperiments.NewAPIClient() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err) |
There was a problem hiding this comment.
| fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err) | |
| fmt.Fprintf(os.Stderr, "[Model Experiments] Creating API client: %v\n", err) |
| os.Exit(1) | ||
| } | ||
|
|
||
| // Create a instance |
There was a problem hiding this comment.
| // Create a instance | |
| // Create an instance |
| createTokenPayload := modelexperiments.CreateInstanceTokenPayload{ | ||
| Name: "token-name", | ||
| } | ||
| createTokenResp, err := modelexperimentsClient.DefaultAPI.CreateInstanceToken(context.Background(), projectId, region, createInstanceResp.Instance.Id).CreateInstanceTokenPayload(createTokenPayload).Execute() |
There was a problem hiding this comment.
Wait handler is missing also in here.
|
Thanks for your contribution. Notice.txt is not part of this PR, but I just recognized a point in there. Can you please change the first line to STACKIT Model Experiments SDK for Go |
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `GetInstance`: %v\n", err) | ||
| } else { | ||
| fmt.Printf("Retrieved instance: %+v\n", getInstanceResp.Instance) |
There was a problem hiding this comment.
maybe instead of printing whole instance, you can print 1-2 fields like name and description to increase output readability. As some printed fields are just nil or addresses.
| os.Exit(1) | ||
| } | ||
|
|
||
| // Create an Model Experiments Instance |
There was a problem hiding this comment.
| // Create an Model Experiments Instance | |
| // Create a Model Experiments Instance |
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `CreateInstance`: %v\n", err) | ||
| } else { | ||
| fmt.Printf("[Model Experiments] Created Model Experiments Instance with ID: \"%s\".\n", createInstanceResp.Instance.Id) |
There was a problem hiding this comment.
| fmt.Printf("[Model Experiments] Created Model Experiments Instance with ID: \"%s\".\n", createInstanceResp.Instance.Id) | |
| fmt.Printf("[Model Experiments] Triggered creation of Model Experiments Instance with ID: \"%s\".\n", createInstanceResp.Instance.Id) |
| } | ||
| createInstanceResp, err := modelexperimentsClient.DefaultAPI.CreateInstance(ctx, projectId, region).CreateInstancePayload(createInstancePayload).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `CreateInstance`: %v\n", err) |
There was a problem hiding this comment.
You should either use log.Fatalf instead of fmt.Fprintf or use os.Exit(1) wherever you get an error.
This comment is valid also for the rest of the file.
| fmt.Printf("[Model Experiments] Retrieved %d instances\n", len(listInstaceResp.Instances)) | ||
| } | ||
|
|
||
| // Update an Model Experiments Instance |
There was a problem hiding this comment.
| // Update an Model Experiments Instance | |
| // Update a Model Experiments Instance |
| } | ||
|
|
||
| // List Model Experiments Instances | ||
| listInstaceResp, err := modelexperimentsClient.DefaultAPI.ListInstances(ctx, projectId, region).Execute() |
There was a problem hiding this comment.
| listInstaceResp, err := modelexperimentsClient.DefaultAPI.ListInstances(ctx, projectId, region).Execute() | |
| listInstanceResp, err := modelexperimentsClient.DefaultAPI.ListInstances(ctx, projectId, region).Execute() |
| fmt.Printf("[Model Experiments] Retrieved Model Experiments Instance with ID: \"%s\" and display name: \"%s\"\n", getInstanceResp.Instance.Id, getInstanceResp.Instance.Name) | ||
| } | ||
|
|
||
| // List Model Experiments Instances |
There was a problem hiding this comment.
fmt.Printf("[Model Experiments] Listing Model Experiments instances.\n")
| fmt.Printf("[Model Experiments] Retrieved %d instances\n", len(listInstaceResp.Instances)) | ||
| } | ||
|
|
||
| // Update an Model Experiments Instance |
There was a problem hiding this comment.
fmt.Printf("[Model Experiments] Updating Model Experiments Instance.\n")
| fmt.Printf("[Model Experiments] Updated Model Experiments Instance with ID: \"%s\" and display name: \"%s\"\n", partialUpdateInstanceResp.Instance.Id, partialUpdateInstanceResp.Instance.Name) | ||
| } | ||
|
|
||
| // Delete an Model Experiments Instance |
There was a problem hiding this comment.
| // Delete an Model Experiments Instance | |
| // Delete a Model Experiments Instance |
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `DeleteInstance`: %v\n", err) | ||
| } else { | ||
| fmt.Printf("[Model Experiments] Deleted Model Experiments Instance with ID: \"%s\" and display name: \"%s\"\n", deleteInstanceResp.Instance.Id, deleteInstanceResp.Instance.Name) |
There was a problem hiding this comment.
| fmt.Printf("[Model Experiments] Deleted Model Experiments Instance with ID: \"%s\" and display name: \"%s\"\n", deleteInstanceResp.Instance.Id, deleteInstanceResp.Instance.Name) | |
| fmt.Printf("[Model Experiments] Triggered deletion of Model Experiments Instance with ID: \"%s\" and display name: \"%s\"\n", deleteInstanceResp.Instance.Id, deleteInstanceResp.Instance.Name) |
| fmt.Printf("[Model Experiments] Updated Model Experiments Instance with ID: \"%s\" and display name: \"%s\"\n", partialUpdateInstanceResp.Instance.Id, partialUpdateInstanceResp.Instance.Name) | ||
| } | ||
|
|
||
| // Delete an Model Experiments Instance |
There was a problem hiding this comment.
You should delete the instance at the end of the script, after you delete the token.
Otherwise, this will cause error.
[Model Experiments] Error when calling `CreateToken`: 404 Not Found, status code 404, Body: {"code":404,"message":"mlflow service not available: instance not found","status":"Not Found"}
panic: runtime error: invalid memory address or nil pointer dereference
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `CreateToken`: %v\n", err) | ||
| } else { | ||
| fmt.Printf("[Model Experiments] Created Model Experiments Instance Token: %+v\n", createTokenResp.Token) |
There was a problem hiding this comment.
| fmt.Printf("[Model Experiments] Created Model Experiments Instance Token: %+v\n", createTokenResp.Token) | |
| fmt.Printf("[Model Experiments] Triggered creation of Model Experiments Instance Token: %+v\n", createTokenResp.Token) |
| } | ||
| fmt.Printf("[Model Experiments] Model Experiments Instance \"%s\" has been successfully deleted.\n", deleteInstanceResp.Instance.Id) | ||
|
|
||
| // Create an Model Experiments Instance Token |
There was a problem hiding this comment.
| // Create an Model Experiments Instance Token | |
| // Create a Model Experiments Instance Token |
| fmt.Printf("[Model Experiments] Retrieved %d instance tokens\n", len(listTokenResp.Tokens)) | ||
| } | ||
|
|
||
| // Update an Model Experiments Instance Token |
There was a problem hiding this comment.
| // Update an Model Experiments Instance Token | |
| // Update a Model Experiments Instance Token |
| fmt.Printf("[Model Experiments] Updated Model Experiments Instance Token with ID: \"%s\" and display name: \"%s\"\n", partialUpdateTokenResp.Token.Id, partialUpdateTokenResp.Token.Name) | ||
| } | ||
|
|
||
| // Delete an Model Experiments Instance Token |
There was a problem hiding this comment.
| // Delete an Model Experiments Instance Token | |
| // Delete a Model Experiments Instance Token |
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `DeleteInstanceToken`: %v\n", err) | ||
| } else { | ||
| fmt.Printf("[Model Experiments] Deleted Model Experiments Instance Token with ID: \"%s\" and display name: \"%s\"\n", deleteTokenResp.Token.Id, deleteTokenResp.Token.Name) |
There was a problem hiding this comment.
| fmt.Printf("[Model Experiments] Deleted Model Experiments Instance Token with ID: \"%s\" and display name: \"%s\"\n", deleteTokenResp.Token.Id, deleteTokenResp.Token.Name) | |
| fmt.Printf("[Model Experiments] Triggered deletion of Model Experiments Instance Token with ID: \"%s\" and display name: \"%s\"\n", deleteTokenResp.Token.Id, deleteTokenResp.Token.Name) |
| ) | ||
|
|
||
| // CreateModelExperimentsInstanceWaitHandler will wait for creation of Model Experiments instance | ||
| func CreateModelExperimentsInstanceWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceResponse] { |
There was a problem hiding this comment.
I am thinking if it is better to remove the ModelExperiments completely from the function name.
CreateInstanceWaitHandler
DeleteInstanceWaitHandler
CreateInstanceTokenWaitHandler
DeleteInstanceTokenWaitHandler
There was a problem hiding this comment.
@marceljk what do you think? Is it better without service name?
Description
Wait handlers for model experiments
Checklist
make fmtexamples/directory)make test(will be checked by CI)make lint(will be checked by CI)