Skip to content

feat(gcp-resources): Add Vertex-AI#5762

Merged
erezrokah merged 4 commits intocloudquery:mainfrom
erezrokah:feat/gcp_ai
Dec 29, 2022
Merged

feat(gcp-resources): Add Vertex-AI#5762
erezrokah merged 4 commits intocloudquery:mainfrom
erezrokah:feat/gcp_ai

Conversation

@erezrokah
Copy link
Copy Markdown
Member

@erezrokah erezrokah commented Dec 18, 2022

Summary

PR to add Vertex-AI resources.

Those require:

  1. Explicitly setting the API endpoint to one of those listed in https://cloud.google.com/vertex-ai/docs/reference/rest#service-endpoint (the API throws errors without it, see aiplatform: Prediction error googleapis/google-cloud-go#6649 (comment)) to list the locations for each resource.
  2. Listing the locations before calling the actual list function (with the correct endpoint for that location), hence the relations.

Caveats

Some API calls fail out of the box, but that happens to gcloud too 😕 I filtered these locations manually for now
image

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 18, 2022

This PR has the following changes to source plugin(s) tables:

  • Table gcp_aiplatform_batch_prediction_jobs was added
  • Table gcp_aiplatform_custom_jobs was added
  • Table gcp_aiplatform_data_labeling_jobs was added
  • Table gcp_aiplatform_dataset_locations was added
  • Table gcp_aiplatform_datasets was added
  • Table gcp_aiplatform_endpoint_locations was added
  • Table gcp_aiplatform_endpoints was added
  • Table gcp_aiplatform_featurestore_locations was added
  • Table gcp_aiplatform_featurestores was added
  • Table gcp_aiplatform_hyperparameter_tuning_jobs was added
  • Table gcp_aiplatform_index_endpoints was added
  • Table gcp_aiplatform_index_locations was added
  • Table gcp_aiplatform_indexendpoint_locations was added
  • Table gcp_aiplatform_indexes was added
  • Table gcp_aiplatform_job_locations was added
  • Table gcp_aiplatform_metadata_locations was added
  • Table gcp_aiplatform_metadata_stores was added
  • Table gcp_aiplatform_model_deployment_monitoring_jobs was added
  • Table gcp_aiplatform_model_locations was added
  • Table gcp_aiplatform_models was added
  • Table gcp_aiplatform_operations was added
  • Table gcp_aiplatform_pipeline_jobs was added
  • Table gcp_aiplatform_pipeline_locations was added
  • Table gcp_aiplatform_specialist_pools was added
  • Table gcp_aiplatform_specialistpool_locations was added
  • Table gcp_aiplatform_studies was added
  • Table gcp_aiplatform_tensorboard_locations was added
  • Table gcp_aiplatform_tensorboards was added
  • Table gcp_aiplatform_training_pipelines was added
  • Table gcp_aiplatform_vizier_locations was added

@erezrokah
Copy link
Copy Markdown
Member Author

erezrokah commented Dec 19, 2022

Blocked by #5803

)

func init() {
resources := []*Resource{
Copy link
Copy Markdown
Member Author

@erezrokah erezrokah Dec 19, 2022

Choose a reason for hiding this comment

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

This is the bulk of the PR, the other are changes to support listing locations before listing the actual resources.

These are the locations.*.list top level resources from https://cloud.google.com/vertex-ai/docs/reference/rest.

The resources to list the locations are generated based on these.
To get the locations we need to use the specific client for that resource, for example (&aiplatform.JobClient{}).ListLocations != (&aiplatform.DatasetClient{}).ListLocations

gcpClient, err := {{.Service}}.{{.NewFunctionName}}(ctx, c.ClientOptions...)
{{ if .ClientOptions }}
clientOptions := c.ClientOptions
clientOptions = append([]option.ClientOption{ {{ range .ClientOptions }}{{.}},{{end}} }, clientOptions...)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We prepend the options, otherwise the tests won't be able to override the endpoint URL

@erezrokah erezrokah changed the title feat(gcp): Add Vertex-AI resources feat(gcp): Add Vertex-AI top level resources Dec 19, 2022
@erezrokah erezrokah changed the title feat(gcp): Add Vertex-AI top level resources feat(gcp): Add Vertex-AI top level resources projects.locations.*.list Dec 19, 2022
@erezrokah erezrokah changed the title feat(gcp): Add Vertex-AI top level resources projects.locations.*.list feat(gcp): Add Vertex-AI top level resources - projects.locations.*.list Dec 19, 2022
@erezrokah erezrokah force-pushed the feat/gcp_ai branch 2 times, most recently from 4ca074f to 9b8c448 Compare December 20, 2022 15:21
@erezrokah erezrokah force-pushed the feat/gcp_ai branch 2 times, most recently from 66d5d42 to 863ced8 Compare December 20, 2022 17:07
}

func isFieldMockable(field reflect.StructField) bool {
nonMockables := []any{&structpb.Value{}, &structpb.Struct{}, &pb.Model{}, &pb.PipelineJob_RuntimeConfig{}}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Faker can't mock these as we need to set the fields in a specific way so they can be MarshalJSONed

return responseHasNextPage
}

func generateMockTestData(r *recipes.Resource) {
Copy link
Copy Markdown
Member Author

@erezrokah erezrokah Dec 20, 2022

Choose a reason for hiding this comment

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

This function creates the data necessary to mock the relations gRPC server calls.
We create a server implementation with all the List* methods, then register it.
See example in https://github.com/erezrokah/cloudquery/blob/863ced86bda2266a3d076b98ecd2f70ac1d23403/plugins/source/gcp/resources/services/aiplatform/job_locations_mock_test.go#L44

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think we can use this approach to get all list functions of a client to remove some boilerplate. I'll look into it separately


locationSubService := getLocationsServiceName(resource.NewFunction) + "_locations"
locationResource := locationsMap[locationSubService]
if locationResource == nil {
Copy link
Copy Markdown
Member Author

@erezrokah erezrokah Dec 20, 2022

Choose a reason for hiding this comment

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

We need a location resource for all the resources under it, for example JobClient.ListLocations will allow us to list all resources under JobClient.
That's the reason need to check for an existing one, and append the resource as a relation (e.g. JobClient.ListLocations resource we have all relevant List* resources as relations)

// NameTransformer custom name transformer for resource
NameTransformer func(field reflect.StructField) (string, error)
// ClientOptions is a list of options to pass to the client
ClientOptions []string
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We need ClientOptions so we can override the endpoint

ClientOptions []string
// IgnoreInTestsColumns is a list of columns to ignore in tests
IgnoreInTestsColumns []string
ParentFilterFunc string
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Apparently ListLocations returns invalid locations us and eu that can't be used to list sub resources, so we need to filter them. The function itself is manually written

@erezrokah erezrokah marked this pull request as ready for review December 20, 2022 18:09
@erezrokah erezrokah requested a review from disq as a code owner December 20, 2022 18:09
@vercel
Copy link
Copy Markdown

vercel bot commented Dec 21, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
cloudquery-web 🔄 Building (Inspect) Dec 26, 2022 at 1:56PM (UTC)

@erezrokah erezrokah changed the title feat(gcp): Add Vertex-AI top level resources - projects.locations.*.list feat(gcp-resources): Add Vertex-AI Dec 27, 2022
@erezrokah erezrokah force-pushed the feat/gcp_ai branch 2 times, most recently from db15807 to fe62993 Compare December 28, 2022 16:50
@erezrokah erezrokah added automerge Automatically merge once required checks pass and removed automerge Automatically merge once required checks pass labels Dec 29, 2022
@erezrokah erezrokah merged commit d22b69d into cloudquery:main Dec 29, 2022
@erezrokah erezrokah deleted the feat/gcp_ai branch December 29, 2022 10:16
kodiakhq bot pushed a commit that referenced this pull request Jan 3, 2023
🤖 I have created a release *beep* *boop*
---


## [5.4.0](plugins-source-gcp-v5.3.1...plugins-source-gcp-v5.4.0) (2023-01-03)


### Features

* **gcp-codegen:** Make ListFunction optional ([#5971](#5971)) ([5717f05](5717f05))
* **gcp-resources:** Add AppEngine resources ([#5972](#5972)) ([d6b6c6a](d6b6c6a))
* **gcp-resources:** Add Artifact Registry ([#6020](#6020)) ([76faa06](76faa06))
* **gcp-resources:** Add Bare Metal Solution ([#6044](#6044)) ([9a80b27](9a80b27))
* **gcp-resources:** Add Batch ([#6128](#6128)) ([43cd3be](43cd3be))
* **gcp-resources:** Add BeyondCorp ([#6133](#6133)) ([48aafd0](48aafd0))
* **gcp-resources:** Add Vertex-AI ([#5762](#5762)) ([d22b69d](d22b69d))
* **gcp:** Auto generate services list ([#5961](#5961)) ([0467de5](0467de5))


### Bug Fixes

* **deps:** Update google.golang.org/genproto digest to f9683d7 ([#6170](#6170)) ([0df29be](0df29be))
* **deps:** Update module github.com/cloudquery/plugin-sdk to v1.14.0 ([#6025](#6025)) ([35b2cfc](35b2cfc))
* **deps:** Update module github.com/cloudquery/plugin-sdk to v1.15.0 ([#6071](#6071)) ([684b525](684b525))
* **deps:** Update module github.com/cloudquery/plugin-sdk to v1.15.1 ([#6079](#6079)) ([650659c](650659c))
* **deps:** Update module github.com/cloudquery/plugin-sdk to v1.16.0 ([#6098](#6098)) ([7bacdf3](7bacdf3))
* **deps:** Update module github.com/cloudquery/plugin-sdk to v1.16.1 ([#6214](#6214)) ([53b2415](53b2415))
* **deps:** Update module github.com/cloudquery/plugin-sdk to v1.17.0 ([#6256](#6256)) ([b19f6cd](b19f6cd))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants