Repository navigation
feat(modelexperiments): onboarded model experiments service - #1587
haya-fatima wants to merge 20 commits into
Conversation
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
| delete(flagValues, globalflags.ProjectIdFlag) | ||
| }), | ||
| isValid: false, | ||
| }, |
There was a problem hiding this comment.
Please add more test cases for checking: empty project id, invalid project id, empty instance id, invalid instance id
| } | ||
| } | ||
|
|
||
| func TestBuildDescribeInstanceRequest(t *testing.T) { |
There was a problem hiding this comment.
| func TestBuildDescribeInstanceRequest(t *testing.T) { | |
| func TestBuildRequest(t *testing.T) { |
| }, | ||
| } | ||
|
|
||
| cmd.Flags().Int64(limitFlag, 0, "Maximum number of entries to list") |
There was a problem hiding this comment.
Please carry this into configureFlags functions. I know it is only single line, but please keep the coding standard,
| isValid: false, | ||
| }, | ||
| { | ||
| description: "limit must be greater than zero", |
There was a problem hiding this comment.
You can add another limit check for invalid string
| delete(flagValues, globalflags.ProjectIdFlag) | ||
| }), | ||
| isValid: false, | ||
| }, |
There was a problem hiding this comment.
Please add tests for invalid and empty project ids
| } | ||
| } | ||
|
|
||
| func TestBuildListInstancesRequest(t *testing.T) { |
There was a problem hiding this comment.
| func TestBuildListInstancesRequest(t *testing.T) { | |
| func TestBuildRequest(t *testing.T) { |
| } | ||
|
|
||
| func TestBuildListInstancesRequest(t *testing.T) { | ||
| request := buildRequest( |
| `Update labels on an AI Model Experiments instance`, | ||
| `$ stackit model-experiments instance update xxx --labels env=prod,team=ml`, | ||
| ), | ||
| examples.NewExample( |
| if err != nil { | ||
| return err | ||
| } | ||
|
|
There was a problem hiding this comment.
We should prompt here to ask user confirmation about the update. Please also get instance name and project name by using utils functions and use them in the prompt.
| return nil, &cliErr.ProjectIdError{} | ||
| } | ||
|
|
||
| labels, err := cmd.Flags().GetStringToString(labelsFlag) |
There was a problem hiding this comment.
Please take a look at the flags.FlagToStringToAny function. You can simplify the label handling to a single line. There are already some examples in other services-
labels := flags.FlagToStringToAny(p, cmd, labelFlag)
| Retention: flags.FlagToStringPointer(p, cmd, retentionFlag), | ||
| } | ||
|
|
||
| if model.Name == nil && |
There was a problem hiding this comment.
-instead of this check, you can use cmd.MarkFlagsOneRequired() function in configureFlags. This will give an error if the command is invoked without providing any mentioned flag in function.
| cmd.Flags().String(descriptionFlag, "", "Instance description") | ||
| cmd.Flags().StringToString(labelsFlag, nil, `Labels as comma-separated key-value pairs, e.g. "--labels env=prod,team=ml"`) | ||
| cmd.Flags().String(retentionFlag, "", `Retention period for deleted experiments before permanent purge, e.g. "30d" (min 1d, max 90d)`) | ||
| } |
There was a problem hiding this comment.
here you should use the cmd.MarkFlagsOneRequired function
| isValid: false, | ||
| }, | ||
| { | ||
| description: "project id missing", |
There was a problem hiding this comment.
same like other tests, please extend with further project id, instance id checks
| } | ||
| } | ||
|
|
||
| func TestBuildUpdateInstanceRequest(t *testing.T) { |
There was a problem hiding this comment.
| func TestBuildUpdateInstanceRequest(t *testing.T) { | |
| func TestBuildRequest(t *testing.T) { |
| params := testparams.NewTestParams() | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { |
| } | ||
|
|
||
| func NewCmd(params *types.CmdParams) *cobra.Command { | ||
| cmd := &cobra.Command{Use: "create", Short: "Creates an instance token", Long: "Creates an auth token for an AI Model Experiments instance.", Args: args.NoArgs, Example: examples.Build(examples.NewExample("Create an auth token", "$ stackit model-experiments token create --instance-id xxx --name my-token")), RunE: func(cmd *cobra.Command, _ []string) error { |
There was a problem hiding this comment.
You need to split these to new lines.
| resp, err := buildRequest(context.Background(), model, apiClient).Execute() | ||
| if err != nil { | ||
| return fmt.Errorf("create instance token: %w", err) | ||
| } |
There was a problem hiding this comment.
wait handler is missing here. Token creation is an async operation, we also have a wait handler in SDK for it. Please add it here.
| if err != nil { | ||
| return err | ||
| } | ||
| resp, err := buildRequest(context.Background(), model, apiClient).Execute() |
There was a problem hiding this comment.
prompt is missing. We need to prompt to ask user if they want to trigger creation.
Please also use the project name and instance name utils and use these values in the prompt and output.
| cmd.Flags().String(nameFlag, "", "Token name") | ||
| cmd.Flags().String(descriptionFlag, "", "Token description") | ||
| cmd.Flags().StringToString(labelsFlag, nil, `Labels as comma-separated key-value pairs, e.g. "--labels env=prod,team=ml"`) | ||
| cmd.Flags().String(ttlDurationFlag, "", "Token time to live duration") |
There was a problem hiding this comment.
There is important information for this in API. It must be added here
Maximum allowed duration is 6 months. If not set, defaults to 6 months.
| cmd.Flags().String(nameFlag, "", "Token name") | ||
| cmd.Flags().String(descriptionFlag, "", "Token description") | ||
| cmd.Flags().StringToString(labelsFlag, nil, `Labels as comma-separated key-value pairs, e.g. "--labels env=prod,team=ml"`) | ||
| cmd.Flags().String(ttlDurationFlag, "", "Token time to live duration") |
There was a problem hiding this comment.
and maybe an example how duration must be defined.
| cmd.Flags().String(descriptionFlag, "", "Token description") | ||
| cmd.Flags().StringToString(labelsFlag, nil, `Labels as comma-separated key-value pairs, e.g. "--labels env=prod,team=ml"`) | ||
| cmd.Flags().String(ttlDurationFlag, "", "Token time to live duration") | ||
| _ = flags.MarkFlagsRequired(cmd, instanceIDFlag, nameFlag) |
There was a problem hiding this comment.
error check is missing here.
err := flags.MarkFlagsRequired(cmd,.....
cobra.CheckErr(err)
| if globalFlags.ProjectId == "" { | ||
| return nil, &cliErr.ProjectIdError{} | ||
| } | ||
| labels, err := cmd.Flags().GetStringToString(labelsFlag) |
There was a problem hiding this comment.
Please see the comment I left in the instance commands about the label handling. Same applies here.
| if len(labels) > 0 { | ||
| labelsPtr = &labels | ||
| } | ||
| model := &inputModel{GlobalFlagModel: globalFlags, InstanceID: flags.FlagToStringValue(p, cmd, instanceIDFlag), Name: flags.FlagToStringValue(p, cmd, nameFlag), Description: flags.FlagToStringPointer(p, cmd, descriptionFlag), Labels: labelsPtr, TTLDuration: flags.FlagToStringPointer(p, cmd, ttlDurationFlag)} |
There was a problem hiding this comment.
Please use the standard indentation we use in other commands. This is not a readable code.
| labelsPtr = &labels | ||
| } | ||
| model := &inputModel{GlobalFlagModel: globalFlags, InstanceID: flags.FlagToStringValue(p, cmd, instanceIDFlag), Name: flags.FlagToStringValue(p, cmd, nameFlag), Description: flags.FlagToStringPointer(p, cmd, descriptionFlag), Labels: labelsPtr, TTLDuration: flags.FlagToStringPointer(p, cmd, ttlDurationFlag)} | ||
| if model.Name == "" { |
There was a problem hiding this comment.
This is being already checked in the flags function.
| } | ||
|
|
||
| func buildRequest(ctx context.Context, model *inputModel, apiClient *modelexperiments.APIClient) modelexperiments.ApiCreateInstanceTokenRequest { | ||
| payload := modelexperiments.CreateInstanceTokenPayload{Name: model.Name, Description: model.Description, Labels: model.Labels, TtlDuration: model.TTLDuration} |
There was a problem hiding this comment.
Please use proper indentations
| @@ -0,0 +1,105 @@ | |||
| package create | |||
There was a problem hiding this comment.
All comments I left in my previous review and current review in the instance commands, applies also to the token commands. Please, for each comment, see if you have any other occurrences of the mentioned issue and change that part also.
| flags map[string]string | ||
| valid bool | ||
| want *inputModel | ||
| }{ |
There was a problem hiding this comment.
Please use our standard indentation style. See other service commands as example. And please check indentations in all other commands in the PR, especially in the token instance group.
|
|
||
| type testContextKey struct{} | ||
|
|
||
| var testContext = context.WithValue(context.Background(), testContextKey{}, "token-create") |
There was a problem hiding this comment.
var (
testContext ...
testClient
)
You can group them in a single var definition
| var testInstanceID = uuid.NewString() | ||
|
|
||
| func fixtureFlagValues(mods ...func(map[string]string)) map[string]string { | ||
| values := map[string]string{globalflags.ProjectIdFlag: testProjectID, instanceIDFlag: testInstanceID, globalflags.RegionFlag: "eu01", nameFlag: "example"} |
There was a problem hiding this comment.
as mentioned in the instance commands, you can define region to a const.
| } | ||
| if err := params.Printer.PromptForConfirmation(fmt.Sprintf("Are you sure you want to delete instance token %q?", model.TokenID)); err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
This is also an async operation but as mentioned in create, here also wait handler, prompt and utils functions are missing.
Description
Onboarded the model experiments service to the STACKIT CLI and updated the relevant functionality. Added the necessary tests and verified the changes locally.
In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->
relates to #STACKITMLO-1718
Checklist
make fmtmake generate-docs(will be checked by CI)make test(will be checked by CI)make lint(will be checked by CI)