Skip to content

Conversation

@irataxy
Copy link
Contributor

@irataxy irataxy commented Aug 28, 2024

Description

Fixes b: 355523386

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed guidelines from CONTRIBUTING.MD and Samples Style Guide
  • Tests pass: npm test (see Testing)
  • Lint pass: npm run lint (see Style)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This pull request is from a branch created directly off of GoogleCloudPlatform/nodejs-docs-samples. Not a fork.
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new sample directory, and I created GitHub Actions workflow for this sample
  • [] This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@irataxy irataxy requested review from a team as code owners August 28, 2024 01:14
@snippet-bot
Copy link

snippet-bot bot commented Aug 28, 2024

Here is the summary of changes.

You are about to add 1 region tag.

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

@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: workflows Issues related to the Workflows API. labels Aug 28, 2024
@irataxy irataxy changed the title docs: add a REST sample and test for AML AI feat: add a REST sample and test for AML AI Aug 28, 2024
Copy link
Contributor

@subfuzion subfuzion left a comment

Choose a reason for hiding this comment

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

A few changes requested, but looks good overall. Thanks.

@irataxy irataxy requested a review from subfuzion September 11, 2024 20:12
Copy link
Contributor

@subfuzion subfuzion left a comment

Choose a reason for hiding this comment

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

Approved. Test fails because financialservices.googleapis.com isn't enabled (pending: cl/674939991).


// node listLocations.js
main().catch(err => {
console.error(err);
Copy link
Contributor

@subfuzion subfuzion Sep 15, 2024

Choose a reason for hiding this comment

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

Changed this so mocha's reporter prints the reason for the failure. The current mocha test reporter filters out stdout but prints stderr, see logs using console.log() vs. console.error().

Copy link
Contributor

Choose a reason for hiding this comment

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

cl/674939991 is merged, waiting on API enablement now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @irataxy The API was enabled (internal: cl/676595619). Looks like a few conflicts must be resolved to get this merged, however. Do you have bandwidth to follow up, or would you like to convert this to a draft or close it for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Converted to draft for now

Copy link
Contributor

Choose a reason for hiding this comment

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

@irataxy The PR to enable the financialservices api was merged. I'm going to take this out of draft mode and rerun tests to confirm.

Copy link
Contributor

Choose a reason for hiding this comment

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

Per @irataxy, proper client libraries for this are coming soon. Closing for now. @irataxy Feel free to reopen or create a new PR when you're ready. Thanks!

@irataxy irataxy marked this pull request as draft October 7, 2024 18:17
@subfuzion subfuzion marked this pull request as ready for review November 15, 2024 18:07
@subfuzion subfuzion requested a review from a team as a code owner November 15, 2024 18:07
Copy link
Contributor

@code-review-assist-experimental code-review-assist-experimental bot left a comment

Choose a reason for hiding this comment

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

Hi @irataxy and reviewers,

I'm currently reviewing this pull request and will post my detailed review in a few minutes. In the meantime, here's a quick summary to help everyone get up to speed:

This pull request adds a new REST sample and test for the AML AI product. The changes include:

  • A new directory aml-ai containing the sample code (listLocations.js) and its corresponding test (aml-ai.test.js).
  • A new GitHub Actions workflow (aml-ai.yaml) for building and testing the sample.
  • Updates to CODEOWNERS to assign ownership of the new sample.
  • Updates to .github/workflows/utils/workflows.json to include the new workflow.
  • A package.json file for managing dependencies within the aml-ai directory.

The intent is to provide a clear and concise example of how to use the AML AI API to list locations. The test verifies that the sample correctly retrieves the expected location information.

If there's anything unclear or missing from this summary, please let me know. I'll provide a more detailed review shortly.

And now, a little haiku to lighten the mood:

Code flows like a stream,
Tests run, a green light appears,
Joy fills the coder's heart.

Copy link
Contributor

@code-review-assist-experimental code-review-assist-experimental bot left a comment

Choose a reason for hiding this comment

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

This pull request adds a REST sample and test for AML AI. The implementation looks good, and the inclusion of tests and adherence to the contribution guidelines is commendable. Here are a few suggestions for improvement:

permissions:
contents: 'read'
id-token: 'write'
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run'
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Consider adding a comment explaining the purpose of the actions:force-run label and when it should be used.

Suggested change
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run'
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' # Allows manual rerun via label

permissions:
contents: 'read'
id-token: 'write'
if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail
Copy link
Contributor

Choose a reason for hiding this comment

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

low

Consider adding a comment explaining what the always() function does in this context.

Suggested change
if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail
if: github.event_name == 'schedule' && always() # Submits logs even if tests fail

scopes: 'https://www.googleapis.com/auth/cloud-platform',
headers: {'Content-Type': 'application/json; charset=utf-8'},
});
// TODO(developer): update the project ID as needed
Copy link
Contributor

Choose a reason for hiding this comment

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

low

The TODO should be more specific about how the developer should update the project ID. Is it via an environment variable? Should it be hardcoded? Provide an example.

Suggested change
// TODO(developer): update the project ID as needed
// TODO(developer): Replace with your project ID. For example:
// const projectId = 'my-project-id';

try {
response = await client.request({url, method: 'GET'});
} catch (err) {
throw new Error(`API request failed: ${err}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Instead of just logging the error message, consider including the original error object (err) as well. This can be helpful for debugging. Also, consider logging the status code if available.

Suggested change
throw new Error(`API request failed: ${err}`);
throw new Error(`API request failed: ${err.message} (status: ${err.status}, error: ${err})`);

console.log(JSON.stringify(response.data));
};

return await listLocations();
Copy link
Contributor

Choose a reason for hiding this comment

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

low

The await keyword is unnecessary here since listLocations is already awaited when called. Removing it won't change the behavior but will slightly improve performance.

Suggested change
return await listLocations();
return listLocations();

const cloudRegion = 'us-central1';

it('should get the AML AI API locations', () => {
const output = execSync('node listLocations.js', {cwd});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

It's good practice to assert on the full response or specific fields within the response data, rather than just checking if a string is included. This makes the test more robust and less prone to false positives. Also, consider using JSON.parse() to parse the output and assert on the structured data.

Suggested change
const output = execSync('node listLocations.js', {cwd});
const output = JSON.parse(execSync('node listLocations.js', {cwd}));
assert.ok(output.locations.some(location => location.locationId === cloudRegion));

@subfuzion subfuzion closed this Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: workflows Issues related to the Workflows API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants