Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHOAIENG-3458: Introduce edge client and model registry client #234

Merged

Conversation

devguyio
Copy link
Contributor

@devguyio devguyio commented Mar 22, 2024

Description

Using the model registry to implement the edge use case includes a lot of custom logic.

This PR adds a model registry client and an edge client as two abstractions that encapsulate such logic and can be used by the CLI directly.

This PR also refactors the models command to use the newly introduced edge client and streamlines the command design.

Tip

This PR is reviewed best commit-by-commit. Instead of using the Files changed tab:

  • Use the Commits tab
  • Click on the top commit and review that commit
  • Use n and p to go to the next and previous commits respectively to review each commit.

How Has This Been Tested?

cd cli
make cli-build
./odh models

image

./odh models add "voice-recognition-model" "A ML model for voice recognition" "v1"   

image

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

Running odh command without any subcommands should show the
help message and not execute any functionality. The listing
of namespaces was only added as a test. Make the root
command not runnable and remove the unecessary test.
@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 22, 2024

@devguyio: This pull request references RHOAIENG-3458 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.16.0" version, but no target version was set.

In response to this:

Description

Using the model registry to implement the edge use case includes a lot of custom logic.

This PR adds a model registry client and an edge client as two abstractions that encapsulate such logic and can be used by the CLI directly.

This PR also refactors the models command to use the newly introduced edge client and streamlines the command design.

[!TIP]
This PR is reviewed best commit-by-commit. Instead of using the Files changed tab:

  • Use the Commits tab
  • Click on the top commit and review that commit
  • Use n and p to go to the next and previous commits respectively to review each commit.

How Has This Been Tested?

cd cli
make cli-build
./odh models

image

./odh models add "voice-recognition-model" "A ML model for voice recognition" "v1"   

image

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 22, 2024

@devguyio: This pull request references RHOAIENG-3458 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.16.0" version, but no target version was set.

In response to this:

Description

Using the model registry to implement the edge use case includes a lot of custom logic.

This PR adds a model registry client and an edge client as two abstractions that encapsulate such logic and can be used by the CLI directly.

This PR also refactors the models command to use the newly introduced edge client and streamlines the command design.

[!TIP]
This PR is reviewed best commit-by-commit. Instead of using the Files changed tab:

  • Use the Commits tab
  • Click on the top commit and review that commit
  • Use n and p to go to the next and previous commits respectively to review each commit.

How Has This Been Tested?

cd cli
make cli-build
./odh models

image

./odh models add "voice-recognition-model" "A ML model for voice recognition" "v1"   

image

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 22, 2024

@devguyio: This pull request references RHOAIENG-3458 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.16.0" version, but no target version was set.

In response to this:

Description

Using the model registry to implement the edge use case includes a lot of custom logic.

This PR adds a model registry client and an edge client as two abstractions that encapsulate such logic and can be used by the CLI directly.

This PR also refactors the models command to use the newly introduced edge client and streamlines the command design.

[!TIP]
This PR is reviewed best commit-by-commit. Instead of using the Files changed tab:

  • Use the Commits tab
  • Click on the top commit and review that commit
  • Use n and p to go to the next and previous commits respectively to review each commit.

How Has This Been Tested?

cd cli
make cli-build
./odh models

image

./odh models add "voice-recognition-model" "A ML model for voice recognition" "v1"   

image

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@devguyio
Copy link
Contributor Author

@biswassri FYI

@devguyio devguyio mentioned this pull request Mar 22, 2024
3 tasks
cli/pkg/commands/common/types.go Outdated Show resolved Hide resolved
cli/pkg/commands/common/cmd.go Show resolved Hide resolved
cli/pkg/edgeclient/client.go Show resolved Hide resolved
@Sara4994
Copy link
Contributor

Sara4994 commented Mar 24, 2024

Can we have an Readme containing instructions to build and run the cli, also list of available commands and its syntax? it will be easy for others to try it out. wdyt?

@grdryn
Copy link
Member

grdryn commented Mar 25, 2024

/lint

Copy link

@openshift-ci openshift-ci bot left a comment

Choose a reason for hiding this comment

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

@grdryn: 54 warnings.

In response to this:

/lint

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

cli/pkg/pipelines/params.go Outdated Show resolved Hide resolved
cli/pkg/pipelines/params.go Show resolved Hide resolved
cli/pkg/pipelines/params.go Show resolved Hide resolved
cli/pkg/pipelines/params.go Show resolved Hide resolved
cli/pkg/commands/common/cmd.go Show resolved Hide resolved
cli/pkg/edgeclient/client.go Outdated Show resolved Hide resolved
cli/pkg/httptest/server.go Show resolved Hide resolved
cli/pkg/httptest/server.go Show resolved Hide resolved
cli/pkg/httptest/server.go Show resolved Hide resolved
cli/pkg/httptest/server.go Show resolved Hide resolved
Copy link
Member

@grdryn grdryn left a comment

Choose a reason for hiding this comment

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

Is the JIRA ID correct in the title? It appears to reference a closed issue RHOAIENG-3458

cli/pkg/modelregistry/client.go Outdated Show resolved Hide resolved
cli/pkg/modelregistry/errors.go Outdated Show resolved Hide resolved
cli/pkg/modelregistry/errors.go Show resolved Hide resolved
return nil, fmt.Errorf("error creating model version: %w", err)
} else {
if resp.StatusCode != 201 {
// TODO: Remove this workaround when model registry returns 404 when the model is not found
Copy link
Member

Choose a reason for hiding this comment

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

Is there an issue that can be linked for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean linked in the source code?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, possibly. I think linking issues in the source code is useful, so that when we stumble across this TODO in future, we'll have concrete places to look to see if it can be progressed.

cli/pkg/modelregistry/client.go Outdated Show resolved Hide resolved
cli/pkg/edgeclient/client.go Outdated Show resolved Hide resolved
cli/params.yaml Outdated Show resolved Hide resolved
cli/params.yaml Outdated Show resolved Hide resolved
cli/params.yaml Outdated Show resolved Hide resolved
cli/pkg/edgeclient/types.go Outdated Show resolved Hide resolved
@grdryn
Copy link
Member

grdryn commented Mar 25, 2024

This PR is reviewed best commit-by-commit. Instead of using the Files changed tab [...]

One drawback of this approach is that I don't seem to be able to leave inline suggestions as easily on all files; and also I don't seem to be able to mark all files as viewed, although I can for some (I presume if a file is changed in more than one commit in the PR, it can't be marked as viewed in any single one of those).

@grdryn
Copy link
Member

grdryn commented Mar 27, 2024

/remove-approve

(new process)

@openshift-ci openshift-ci bot removed the approved label Mar 27, 2024
Copy link
Member

@MarianMacik MarianMacik left a comment

Choose a reason for hiding this comment

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

We should also include this in the Makefile and in the PR check as well under the make test target.

cli/params.yaml Outdated Show resolved Hide resolved
cli/pkg/commands/models/add.go Outdated Show resolved Hide resolved
cli/pkg/commands/models/add.go Outdated Show resolved Hide resolved
cli/pkg/pipelines/params.go Outdated Show resolved Hide resolved
cli/pkg/modelregistry/client.go Show resolved Hide resolved
cli/pkg/modelregistry/client.go Outdated Show resolved Hide resolved
cli/pkg/modelregistry/client.go Outdated Show resolved Hide resolved
cli/pkg/edgeclient/types.go Outdated Show resolved Hide resolved
cli/pkg/modelregistry/errors.go Outdated Show resolved Hide resolved
@devguyio devguyio force-pushed the rhoaieng-3458-models-cmd branch from 142d095 to 9738cec Compare April 9, 2024 13:04
@devguyio
Copy link
Contributor Author

devguyio commented Apr 9, 2024

/lint

Copy link

@openshift-ci openshift-ci bot left a comment

Choose a reason for hiding this comment

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

@devguyio: 4 warnings.

In response to this:

/lint

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

cli/pkg/modelregistry/client.go Outdated Show resolved Hide resolved
cli/pkg/modelregistry/client.go Outdated Show resolved Hide resolved
cli/pkg/modelregistry/client.go Outdated Show resolved Hide resolved
cli/pkg/modelregistry/client.go Outdated Show resolved Hide resolved
@devguyio devguyio force-pushed the rhoaieng-3458-models-cmd branch from 9738cec to e9ede5b Compare April 9, 2024 13:11
@devguyio
Copy link
Contributor Author

devguyio commented Apr 9, 2024

/lint

Copy link

@openshift-ci openshift-ci bot left a comment

Choose a reason for hiding this comment

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

@devguyio: 0 warnings.

In response to this:

/lint

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@devguyio
Copy link
Contributor Author

devguyio commented Apr 9, 2024

Can we have an Readme containing instructions to build and run the cli, also list of available commands and its syntax? it will be easy for others to try it out. wdyt?

@Sara4994 I added a readme.

@openshift-ci openshift-ci bot added the lgtm label Apr 12, 2024
@Sara4994
Copy link
Contributor

This PR looks good to me, leaving this to Gerard and Landon now :)

@devguyio
Copy link
Contributor Author

Holding for other reviewers

/hold

@devguyio
Copy link
Contributor Author

This PR looks good to me, leaving this to Gerard and Landon now :)

And @MarianMacik

Copy link
Member

@grdryn grdryn left a comment

Choose a reason for hiding this comment

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

/lgtm

@LaVLaS
Copy link
Contributor

LaVLaS commented Apr 15, 2024

/unhold

Copy link
Member

@MarianMacik MarianMacik left a comment

Choose a reason for hiding this comment

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

I have just a few more comments. Nothing blocking, though. Thanks for all the changes, the code looks even better now!

Comment on lines 48 to 52
- name: testDataConfigMapName
value: CONFIG_MAP_NAME
# Whether to add a workspace directory to the pipeline. Can be set to "true" or "false"
- name: addDirWorkspace
value: "true"
Copy link
Member

Choose a reason for hiding this comment

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

These are still present but as you said they are not used for this change, so maybe it would be better to remove these from this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 95 to 103
for _, f := range flags {
if !f.IsRootFlag() {
if f.IsInherited() {
cmd.PersistentFlags().StringP(f.String(), f.Shorthand(), f.Value(), f.Usage())
} else {
cmd.Flags().StringP(f.String(), f.Shorthand(), f.Value(), f.Usage())
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a cobra expert, but with the model add command we are inheriting the FlagModelRegistryURL param from the root command. Here we are defining it again as a persistent flag even though it is not needed. If it works, then I'm fine with it. However, maybe we could register "new" flags here only if it is not a root flag AND it is not inherited. I am guessing this would be the right way to do it.

Copy link
Contributor Author

@devguyio devguyio Apr 16, 2024

Choose a reason for hiding this comment

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

Here we're registering non-root flags only. Root flags are registered in pkg/commands/root.go. The FlagsModelRegistryURL is a root flag as declared in pkg/commands/flags/flags.go.

One logical error that I just fixed, is that root flags should also be set as inherited. I pushed a fix. It wasn't producing a bug but it was logically incorrect.

A root flag means it's defined at the root level, so can be inherited by all subcommands.

There can be a case of an inherited flag that's not root. In that case, it's defined by a specific sub-command and will be inherited by all of its nested sub-commands.

Copy link
Member

Choose a reason for hiding this comment

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

@devguyio I see, I didn't realize that it is a root flag :)

However, in case of an inherited flag that is not root, if we add the third layer of commands, such a flag will be re-added at the third layer to the persistent flags, right? Because it will need to be listed among the flags to read and because it is the same slice, it will be iterated over when registering as well.
Right now it is not an issue as everything non-root should be registered. Also, maybe it won't be an issue even afterwards because cobra maybe can handle it.

docs/cli.md Show resolved Hide resolved
@devguyio devguyio force-pushed the rhoaieng-3458-models-cmd branch from 38f8c04 to 66fb903 Compare April 16, 2024 00:08
@openshift-ci openshift-ci bot removed the lgtm label Apr 16, 2024
@devguyio devguyio requested a review from MarianMacik April 16, 2024 00:14
cli/pkg/commands/models/models.go Outdated Show resolved Hide resolved
Comment on lines 95 to 103
for _, f := range flags {
if !f.IsRootFlag() {
if f.IsInherited() {
cmd.PersistentFlags().StringP(f.String(), f.Shorthand(), f.Value(), f.Usage())
} else {
cmd.Flags().StringP(f.String(), f.Shorthand(), f.Value(), f.Usage())
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

@devguyio I see, I didn't realize that it is a root flag :)

However, in case of an inherited flag that is not root, if we add the third layer of commands, such a flag will be re-added at the third layer to the persistent flags, right? Because it will need to be listed among the flags to read and because it is the same slice, it will be iterated over when registering as well.
Right now it is not an issue as everything non-root should be registered. Also, maybe it won't be an issue even afterwards because cobra maybe can handle it.

@MarianMacik
Copy link
Member

We should also include this in the Makefile and in the PR check as well under the make test target.

@MarianMacik can you please clarify what should be included in the Makefile?

@devguyio I meant to include cli tests under the root makefile test target.

@devguyio devguyio force-pushed the rhoaieng-3458-models-cmd branch 2 times, most recently from 25ddb80 to b3d2259 Compare April 16, 2024 10:56
@devguyio
Copy link
Contributor Author

We should also include this in the Makefile and in the PR check as well under the make test target.

@MarianMacik can you please clarify what should be included in the Makefile?

@devguyio I meant to include cli tests under the root makefile test target.

@MarianMacik I've pushed the following changes:

  • Added the cli-test as part of the root test target
  • Changed the flags packaged by renaming the rootFlag to parentFlag and now it means that this is a flag that will be declared by a parent so we're only interested in getting its value, not in declaring it.
  • Fixed a bug that was preventing adding two version with two different names under the same model:
    • pkg/modelregistry package
      • Added FindRegisteredModel & FindModelVersion
      • Updated AutoRegisterModelVersionArtifact method to check if the model or version exist first, and create them only if they don't exist.

Using the introduced edge client, refactor the model command
to simply use the edge client for listing and adding models.

Also refactor the commands design to streamline the flags
and commands initialization.
@devguyio devguyio force-pushed the rhoaieng-3458-models-cmd branch from b3d2259 to 0e2569d Compare April 16, 2024 11:56
Copy link
Member

@MarianMacik MarianMacik left a comment

Choose a reason for hiding this comment

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

Nice catch with that bug, thanks for incorporating my comments!
/lgtm

@devguyio
Copy link
Contributor Author

/override ci/prow/test-ai-edge

Copy link

openshift-ci bot commented Apr 16, 2024

@devguyio: Overrode contexts on behalf of devguyio: ci/prow/test-ai-edge

In response to this:

/override ci/prow/test-ai-edge

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Member

@grdryn grdryn left a comment

Choose a reason for hiding this comment

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

/approve

Copy link

openshift-ci bot commented Apr 17, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: grdryn

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit bca628b into opendatahub-io:main Apr 17, 2024
2 checks passed
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.

6 participants