Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

chore(samples): interactive tutorials code samples for import user events#152

Merged
sofisl merged 2 commits intogoogleapis:mainfrom
nmykhailets:user-events-import
Mar 14, 2022
Merged

chore(samples): interactive tutorials code samples for import user events#152
sofisl merged 2 commits intogoogleapis:mainfrom
nmykhailets:user-events-import

Conversation

@nmykhailets
Copy link
Copy Markdown
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@nmykhailets nmykhailets requested a review from a team March 1, 2022 13:44
@product-auto-label product-auto-label Bot added api: retail Issues related to the googleapis/nodejs-retail API. samples Issues that are directly related to samples. labels Mar 1, 2022
@snippet-bot
Copy link
Copy Markdown

snippet-bot Bot commented Mar 1, 2022

Here is the summary of changes.

You are about to add 3 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@kweinmeister kweinmeister added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Mar 1, 2022
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 1, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 1, 2022
@nmykhailets nmykhailets force-pushed the user-events-import branch 2 times, most recently from 2383954 to 7033425 Compare March 7, 2022 20:57
@kweinmeister kweinmeister added the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 7, 2022
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 7, 2022
@kweinmeister kweinmeister added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Mar 7, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 7, 2022
@@ -0,0 +1,89 @@
// Copyright 2021 Google Inc. All Rights Reserved.
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.

Use 2022 throughout

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@kweinmeister kweinmeister added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 8, 2022
@kweinmeister kweinmeister added owlbot:run Add this label to trigger the Owlbot post processor. and removed owlbot:run Add this label to trigger the Owlbot post processor. labels Mar 8, 2022
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 8, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 8, 2022
@kweinmeister kweinmeister added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Mar 8, 2022
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 8, 2022
@yoshi-kokoro yoshi-kokoro removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Mar 8, 2022
@kweinmeister kweinmeister added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Mar 9, 2022
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 9, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 9, 2022
Copy link
Copy Markdown
Contributor

@sofisl sofisl left a comment

Choose a reason for hiding this comment

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

I think a lot of the comments go for all the samples that I just didn't want to repeat multiple times (i.e., env variables, local variables, etc), so please make sure to apply those comments to all the samples where appropriate. Thanks for submitting these samples!

};

// Instantiates a client.
const retailClient = new UserEventServiceClient();
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.

Can this go up on line 22?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

IOperation: 2,
};

const callImportUserEvents = async () => {
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.

I think slightly easier to read as async function callImportUserEvents() {

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.

The arrow function is a popular features of ES6, it has become a standard as it is more compact and actually convenient to read. If you have any doubts, please create an Issue and we will update the whole code we have submitted with such code style. will it work for you?

// Imports the Google Cloud client library.
const {UserEventServiceClient} = require('@google-cloud/retail').v2;

const projectNumber = process.env['GCLOUD_PROJECT'];
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.

I'd rather not rely on env variables if possible, especially for running tests locally. If your tutorial relies on it, it's fine but I'd rather users have to specifically change these variables.

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 tests should not be run locally. for the kokoro test run we have the long-living resources created. And the code samples itself will run in the CloudShell environment, we provide user with the guide how to create the required resources: service account, buckets, big query tables, and set their names as env variables

// Imports the Google Cloud client library.
const {UserEventServiceClient} = require('@google-cloud/retail').v2;

const projectNumber = process.env['GCLOUD_PROJECT'];
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.

On the top of these variables, can we add something like TODO(developer): uncomment these variables and fill appropriately so that people know to change them? We should also bring up line 30 under line 24 so users know to change that variable.

// Imports the Google Cloud client library.
const {UserEventServiceClient} = require('@google-cloud/retail').v2;

const projectNumber = process.env['GCLOUD_PROJECT'];
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 comment, would rather this not be an env variable.

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 received a task to change the approach of reading the ProjectId value fron the env variable, but to read it from gcloud config or from google.auth instead. We are working on this task Now and the new Pull request will be introduced shortly


'use strict';

async function main() {
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.

Is this a sample? We don't have region tags, or a lot of the normal strucutre.

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.

it is not a sample, this is the supporting code for the uploading the catalog data

'use strict';

async function main(generatedBucketName) {
const utils = require('./setup-cleanup');
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.

missing region tags

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 not the Retail code sample it is the supporting code for the uploading the catalog data
won't fix

Comment thread samples/interactive-tutorials/setup/update-user-events-json.js
const schema = 'interactive-tutorials/resources/events_schema.json';
const sourceFile = 'interactive-tutorials/resources/user_events.json';

before(async () => {
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.

In order to avoid using env variables, especially for running tests locally, we can require a projectId variable, and in the test, instantiate it like so:

const client = new UserEventServiceClient();
describe('test', () => {
  let projectId;

  before(async () => {
    projectId = await client.getProjectId();
  });

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 not a regular code samples, this is the code for interactive tutorials, the concept is a bit different. The tests here are developed only to make sure the tutorials are not broken, ti is not the desired flow if user will run the tests locally

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 was a task we've got recently, the project Id should be read from the google auth or from the gcloud config, so we are working on this task and the PR will be created shortly

'use strict';

async function main() {
const utils = require('./setup-cleanup');
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.

I'm probably just out of context here, so take this comment with a grain of salt, but I generally don't feel like the use of utils is beneficial in samples. If someone is really trying to follow this sample, it's harder to read when the code is splintered like this. Of course there are good reasons for using utils, but just my thoughts from the perspective of someone trying to use this sample (i.e., they can't just "copy and paste")

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.

Hi @sofisl, let me describe a bit the purpose of these code. It is Not the regular code samples which are in this repository.
The task is to design the interactive tutorials which user will be able to run in CloudShell.
In the tutorials we ask user to set a GC project, and create a user account, and then user should open and run in the CloudShell the code samples. The tutorials are really granular, if it is about product updating we want show user only code related to using this method, and to avoid to overload user with extra code. so for theis particular example, we want to hide the methods for product creation and deletion in utils and present only the the update product method.

About using the env variables. We must use them for the bucket names (we use GCS buckets as an importing source) but we will make the Project_ID to be read from the gcloud config.

@kweinmeister kweinmeister added the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 10, 2022
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 10, 2022
@kweinmeister kweinmeister added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Mar 10, 2022
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 10, 2022
@t-karasova
Copy link
Copy Markdown
Contributor

Hi @sofisl, may I ask you to merge the PR as it is approved?

@sofisl sofisl merged commit 27f7cc4 into googleapis:main Mar 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: retail Issues related to the googleapis/nodejs-retail API. owlbot:run Add this label to trigger the Owlbot post processor. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants