Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Last Updated: Mar 27, 2024

Basics of Recommender

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM

Introduction

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.

To enable the Recommender API, do the following:

  1. Create an account if you're new to Google Cloud.
     
  2. Choose or create a Google Cloud project from the project selector page in the Google Cloud console.
     
  3. Enable the Recommender API.
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Finding and Applying Recommendations using the Recommendation Hub

Before you begin

It's necessary to have a Google Cloud project for this quickstart.

  1. Navigate to the Google Cloud console.
     
  2. If you don't already have one, choose a Google Cloud project or start one from scratch.
     
  3. 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.

Finding recommendations in the Recommendation Hub

  1. Navigate to the Home dashboard for your project.
     
  2. Choose the Recommendations tab.

    Src: https://cloud.google.com/static/recommender/docs/images/qs-rh-nav.png

Applying Recommendations in the Recommendation Hub

  1. 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.

    Src: https://cloud.google.com/static/recommender/docs/images/qs-rh-card.png 
     
  2. You may examine the categories for specific recommendations by clicking on the category name in the menu.

    Src: https://cloud.google.com/static/recommender/docs/images/qs-rh-costnav.png 
     
  3. To access the detail panel, click on the name of a recommendation in the Recommendation column.

    Src:https://cloud.google.com/static/recommender/docs/images/qs-rh-costrecselection.png
     
  4. 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.

    Src: https://cloud.google.com/static/recommender/docs/images/qs-rh-apply.png 

Finding and applying recommendations in context

Before you begin

It's necessary to have a Google Cloud project for this quickstart.

  1. Navigate to the Google Cloud console.
     
  2. If you don't already have one, choose a Google Cloud project or start one from scratch.
     
  3. 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.

  1. Go to Compute Engine's VM Instances dashboard.
     
  2. In the table, look for the Recommendation header and the Recommendation column.

    Src: https://cloud.google.com/static/recommender/docs/images/qs-context-rectableall.png 

Applying Recommendations

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.

  1. To access the detail panel, click the recommendation beneath the Recommendation title in the table.

    Src: https://cloud.google.com/static/recommender/docs/images/qs-context-rectable.png 
     
  2. To access the detail panel, click on the name of a recommendation in the Recommendation column.

    Src: https://cloud.google.com/static/recommender/docs/images/qs-context-detail.png 
     
  3. Click on Apply.

Recommendations that you can find in context

It's not always possible to find recommendations in context. The following Google Cloud services have recommendations in context:

  • Cloud SQL
  • Cloud Billing
  • Cloud Run
  • IAM
  • Virtual Machine Instances
  • Virtual Machine type
  • Virtual Machine Groups
  • Instance Groups
  • Google Maps Platform

Using the API

Set the default project

The default project should be set if it hasn't already:

gcloud config set project PROJECT_ID

where PROJECT_ID is your project's ID.

Set environment variables

Set the following environment variables for Recommender interactions:

PROJECT=TARGET_PROJECT_ID
LOCATION=LOCATION_ID
RECOMMENDER=RECOMMENDER_ID

Where: 

  • 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.
     
  • Each recommender requires unique permissions. 

Using the API- Recommendations

List recommendations

To include recommendations in the target project:

Enter the following:

gcloud recommender recommendations list \
    --project=${PROJECT} \
    --location=${LOCATION} \
    --recommender=${RECOMMENDER} \
    --format=FORMAT

Where,

FORMAT: Supported gcloud output format

Mark a recommendation as claimed

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.

To indicate a recommendation as claimed:

Enter the following:

gcloud recommender recommendations mark-claimed \
    RECOMMENDATION_ID \
    --project=${PROJECT} \
    --location=${LOCATION} \
    --recommender=${RECOMMENDER} \
    --etag=etag \
    --state-metadata=STATE_METADATA
    --format=FORMAT

Where,

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:

gcloud recommender recommendations STATE_CHANGE \
    RECOMMENDATION_ID \
    --project=${PROJECT} \
    --location=${LOCATION} \
    --recommender=${RECOMMENDER} \
    --etag=etag \
    --state-metadata=priority=high,tracking_number=12345
    --format=FORMAT

Where

  • 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:

gcloud recommender insights list \
    --project=${PROJECT} \
    --location=${LOCATION} \
    --insight-type=${INSIGHT_TYPE} \
    --format=FORMAT

Where,

FORMAT: supported gcloud format.

Mark an insight as accepted

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:

gcloud recommender insights mark-accepted \
    INSIGHT_ID \
    --project=${PROJECT} \
    --location=${LOCATION} \
    --insight-type=${INSIGHT_TYPE} \
    --etag=etag \
    --state-metadata=STATE_METADATA
    --format=FORMAT

where:

  • 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.

Recommended Readings: ping command in linux

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. 

Refer to the links problemstop 100 SQL problemsresources, and mock tests to enhance your knowledge.

For placement preparations, visit interview experiences and interview bundle.

Do upvote our blog to help other ninjas grow. Happy Coding!

An image that displays a thankyou message from coding ninjas.
Topics covered
1.
Introduction
2.
Enabling the API
3.
Finding and Applying Recommendations using the Recommendation Hub
3.1.
Before you begin
3.2.
Finding recommendations in the Recommendation Hub
3.3.
Applying Recommendations in the Recommendation Hub
4.
Finding and applying recommendations in context
4.1.
Before you begin
4.2.
Finding VM resource recommendations in context
4.3.
Applying Recommendations
4.4.
Recommendations that you can find in context
5.
Using the API
5.1.
Set the default project
5.2.
Set environment variables
5.3.
Set permissions
5.4.
Using the API- Recommendations
5.4.1.
List recommendations
5.4.2.
Mark a recommendation as claimed
5.4.3.
Applying recommendations
5.4.4.
Changing the state of a recommendation
5.5.
Using the API - Insights
5.5.1.
List insights
5.5.2.
Mark an insight as accepted
6.
Frequently Asked Questions
6.1.
How do Google recommendations work?
6.2.
What is the use of a recommender system?
6.3.
What is recommender ID?
7.
Conclusion