chore(samples): interactive tutorials code samples for import user events#152
chore(samples): interactive tutorials code samples for import user events#152sofisl merged 2 commits intogoogleapis:mainfrom
Conversation
|
Here is the summary of changes. You are about to add 3 region tags.
This comment is generated by snippet-bot.
|
2383954 to
7033425
Compare
| @@ -0,0 +1,89 @@ | |||
| // Copyright 2021 Google Inc. All Rights Reserved. | |||
063169f to
04aa8d5
Compare
a6ca925 to
04f5507
Compare
sofisl
left a comment
There was a problem hiding this comment.
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(); |
| IOperation: 2, | ||
| }; | ||
|
|
||
| const callImportUserEvents = async () => { |
There was a problem hiding this comment.
I think slightly easier to read as async function callImportUserEvents() {
There was a problem hiding this comment.
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']; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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']; |
There was a problem hiding this comment.
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']; |
There was a problem hiding this comment.
same comment, would rather this not be an env variable.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Is this a sample? We don't have region tags, or a lot of the normal strucutre.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
this is not the Retail code sample it is the supporting code for the uploading the catalog data
won't fix
| const schema = 'interactive-tutorials/resources/events_schema.json'; | ||
| const sourceFile = 'interactive-tutorials/resources/user_events.json'; | ||
|
|
||
| before(async () => { |
There was a problem hiding this comment.
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();
});
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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")
There was a problem hiding this comment.
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.
|
Hi @sofisl, may I ask you to merge the PR as it is approved? |
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:
Fixes #<issue_number_goes_here> 🦕