Skip to content

feat(modelexperiments): onboarded model experiments service - #1587

Open
haya-fatima wants to merge 20 commits into
stackitcloud:mainfrom
haya-fatima:feat/onboard-AI-MEx
Open

haya-fatima wants to merge 20 commits into
stackitcloud:mainfrom
haya-fatima:feat/onboard-AI-MEx

Conversation

@haya-fatima

@haya-fatima haya-fatima commented Sep 8, 2026 •

Copy link
Copy Markdown

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

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see e.g. here)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@haya-fatima
haya-fatima requested a review from a team as a code owner September 8, 2026 07:58
@haya-fatima
haya-fatima marked this pull request as draft September 8, 2026 08:16
@haya-fatima
haya-fatima marked this pull request as ready for review September 9, 2026 07:42
@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the Stale label Sep 19, 2026
@GokceGK GokceGK removed the Stale label Sep 28, 2026
Comment thread go.mod Resolved
Comment thread internal/pkg/config/config.go Resolved
Comment thread internal/pkg/config/config.go Resolved
delete(flagValues, globalflags.ProjectIdFlag)
}),
isValid: false,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more test cases for checking: empty project id, invalid project id, empty instance id, invalid instance id

}
}

func TestBuildDescribeInstanceRequest(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func TestBuildDescribeInstanceRequest(t *testing.T) {
func TestBuildRequest(t *testing.T) {

},
}

cmd.Flags().Int64(limitFlag, 0, "Maximum number of entries to list")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add another limit check for invalid string

delete(flagValues, globalflags.ProjectIdFlag)
}),
isValid: false,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for invalid and empty project ids

}
}

func TestBuildListInstancesRequest(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func TestBuildListInstancesRequest(t *testing.T) {
func TestBuildRequest(t *testing.T) {

}

func TestBuildListInstancesRequest(t *testing.T) {
request := buildRequest(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use single line

`Update labels on an AI Model Experiments instance`,
`$ stackit model-experiments instance update xxx --labels env=prod,team=ml`,
),
examples.NewExample(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if err != nil {
return err
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-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)`)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you should use the cmd.MarkFlagsOneRequired function

isValid: false,
},
{
description: "project id missing",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same like other tests, please extend with further project id, instance id checks

}
}

func TestBuildUpdateInstanceRequest(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single line

}

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 == "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use proper indentations

@@ -0,0 +1,105 @@
package create

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
}{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also an async operation but as mentioned in create, here also wait handler, prompt and utils functions are missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants