A Google Cloud service called a recommender makes suggestions on how to use specific Google Cloud resources. Recommenders are tailored to a single resource category and Google Cloud product. A single product can have numerous recommenders, each offering a unique suggestion for a different site.
Let us learn more about recommenders with the help of the information below.
Enabling the API
The Recommender API must be enabled to see and manage suggestions and insights via the gcloud and REST APIs.
Finding and Applying Recommendations using the Recommendation Hub
Before you begin
It's necessary to have a Google Cloud project for this quickstart.
Navigate to the Google Cloud console.
If you don't already have one, choose a Google Cloud project or start one from scratch.
To view the project's recommendations, ensure you have the necessary Identity and Access Management (IAM) permissions. The recommendation hub may look empty if you don't have the necessary permissions to access some recommendations.
Applying Recommendations in the Recommendation Hub
On a recommendation card, click view more. You could see a panel open (see step 3) or a page with a list of all the recommendations of that type, depending on the recommendation type.
Use the apply button to accept or reject recommendations you have been given the authority to act upon. Certain advice might not be immediately applicable in the detail panel or page. To use them, adhere to the directions provided on the detail page.
It's necessary to have a Google Cloud project for this quickstart.
Navigate to the Google Cloud console.
If you don't already have one, choose a Google Cloud project or start one from scratch.
To view the project's recommendations, ensure that you have the necessary Identity and Access Management (IAM) permissions. The recommendation hub may look empty if you don't have the necessary permissions to access some recommendations.
Finding VM resource recommendations in context
We'll use Compute Engine in this manual to identify suggestions for lowering VM resource expenses.
Go to Compute Engine's VM Instances dashboard.
In the table, look for the Recommendation header and the Recommendation column.
For certain recommendations, the procedure could seem different when you visit product sites and make the modifications there. But for the most part, the procedure is the same and may be used for most recommendations.
To access the detail panel, click the recommendation beneath the Recommendation title in the table.
TARGET_PROJECT_ID: a project whose recommendations you wish to list. This might be a separate project from your existing one.
The project ID must be used for gcloud operations.
You may use the project number or project ID to make API calls. A project number is recommended.
LOCATION_ID: Google Cloud location containing materials related to the recommendations (for example, global or us-central1-a).
RECOMMENDER_ID: ID of properly qualified recommender (for example, google.compute.instance.MachineTypeRecommender).
Set permissions
You must have the authorization to access recommendations in the target project.
For requesters who include a billing project in their request. The project utilized in the request must be in good standing, and the user must have a role in the project that holds the serviceusage.services.use permission. The needed permission is contained under the Service Usage Consumer role.
You can mark a recommendation as claimed if you intend to make the suggested modifications to the connected resource. When you claim a recommendation, your user name is assigned as the recommendation's actor, and Recommender does not update the recommendation with updated content.
RECOMMENDATION_ID is the identifier of a recommendation obtained in a previous call to list recommendations.
etag: The returned etag reflecting the recommendation state is etag.
STATE_METADATA is optional operation metadata. The metadata should be specified as a comma-separated list of KEY=VALUE pairs. This option is accessible whether you claim, succeed, or fail a recommendation.
Applying recommendations
After you've marked a recommendation as claimed, you may use it using gcloud commands or REST API requests tailored to the resource type.
For example, to alter the size of a VM instance in response to a recommendation from the VM instance sizing recommender, you utilize Compute Engine gcloud commands or Compute Engine REST API requests.
When you conduct these actions, you use the value of the resource field in the OperationsGroup array in the returned Recommendation object to identify the target resource. This field is formatted as follows:
//API_NAME/RESOURCE_PATH
Changing the state of a recommendation
After implementing a recommendation, you may mark it as succeeded or failed.
To indicate a recommendation as succeeded, use the following:
STATE_CHANGE: The change you wish to make to a recommendation.
STATE_METADATA: Optional metadata describing the operation. Specify the metadata as a comma-separated list of KEY=VALUE pairs. This option is accessible when you mark a recommendation as claimed, succeeded, or failed.
Valid values are:
mark-succeeded: To mark the recommendation as succeeded.
mark-failed: To mark the recommendation as failed.
Using the API - Insights
List insights
To list the insights in the target project, enter the following:
You can mark an insight as accepted if you plan to or have taken action on an associated resource based on the information in the insight. When you accept an insight, your user name is assigned as the insight's actor, and Recommender will not update the insight with updated content.
To mark an insight as accepted, enter the following:
INSIGHT_ID: The id of an insight obtained from a previous call to list insights
etag: The returned etag reflecting the insight state
STATE_METADATA: An optional operation metadata. The metadata should be specified as a comma-separated list of KEY=VALUE pairs.
Frequently Asked Questions
How do Google recommendations work?
The Recommendations page analyzes your account's performance history, campaign parameters, and Google trends to offer recommendations that might enhance your success.
What is the use of a recommender system?
Based on the user's profile, a recommender system may forecast whether a particular user would like an item or not.
What is recommender ID?
Each recommender has a distinct recommender ID used to identify the service. When engaging with suggestions using the Recommender gcloud commands or the REST or RPC APIs, you utilize the recommender ID.
Conclusion
In this article, we have extensively discussed the basics of Recommender in Google Cloud. Our discussion mainly focused on enabling the recommender API and finding and applying recommendations.
We hope this blog has helped you enhance your Google Cloud Platform knowledge. For more about Google Cloud Platform concepts, refer to our articles on All about GCP Certifications: Google Cloud Platform | Coding Ninjas Blog.
Refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSA, DBMS, Competitive Programming, Python, Java, JavaScript, etc.