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

feat: adds enhancements to library #22

Merged
merged 39 commits into from
Dec 18, 2020
Merged

feat: adds enhancements to library #22

merged 39 commits into from
Dec 18, 2020

Conversation

telpirion
Copy link
Contributor

@telpirion telpirion commented Nov 26, 2020

This PR adds the following to the AI Platform library:

  • Adds helper methods to enhanced classes
  • Includes samples and sample tests that demonstrate usage
  • Includes client library tests for manual client library layers

After this pull request is submitted, these tasks are required for follow-up:

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 26, 2020
@snippet-bot
Copy link

snippet-bot bot commented Nov 26, 2020

Here is the summary of changes.

You added 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

@codecov
Copy link

codecov bot commented Dec 3, 2020

Codecov Report

Merging #22 (0f9d93a) into master (4f7318b) will decrease coverage by 0.03%.
The diff coverage is 97.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #22      +/-   ##
==========================================
- Coverage   98.85%   98.81%   -0.04%     
==========================================
  Files          12       15       +3     
  Lines       20173    20493     +320     
  Branches      544      575      +31     
==========================================
+ Hits        19942    20251     +309     
- Misses        223      234      +11     
  Partials        8        8              
Impacted Files Coverage Δ
src/value-converter.ts 93.49% <93.49%> (ø)
src/decorator.ts 99.08% <99.08%> (ø)
src/helpers.ts 100.00% <100.00%> (ø)
src/index.ts 100.00% <100.00%> (ø)
src/v1beta1/endpoint_service_client.ts 98.97% <0.00%> (-0.09%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f7318b...0f9d93a. Read the comment docs.

@telpirion telpirion marked this pull request as ready for review December 14, 2020 00:58
@telpirion telpirion requested review from a team as code owners December 14, 2020 00:58
src/decorator.ts Outdated
const namespace =
namespaceName in rootNamespace
? rootNamespace[namespaceName]
: undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't have to use a ternary here, rootNamespace[namespaceName] will be undefined if it's not there, so just const namespace = rootNamespace[namespaceName] is equivalent to this code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/decorator.ts Outdated

// Get the namespace object from JSON
const namespaceJsonObject =
namespaceName in jsonNode ? jsonNode[namespaceName] : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

same as ↑↑

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/decorator.ts Outdated
}

// Assign the toValue() and fromValue() helper methods to the enhanced message objects.
// tslint:disable-next-line no-any
Copy link
Contributor

Choose a reason for hiding this comment

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

this disable-next-line should be moved one line down I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/helpers.ts Outdated
const value = googleProtobufValueFromObject(obj, (val: any) => {
return val;
});
if (typeof value !== 'undefined') {
Copy link
Contributor

@alexander-fenster alexander-fenster Dec 15, 2020

Choose a reason for hiding this comment

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

This if, combined with the final return undefined, can be replaced with just return value;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/helpers.ts Outdated
return undefined;
}

export function fromValue(value: any): object | null | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

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

tslint-disable-next-line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


// TODO(): Remove this file once https://github.com/protobufjs/protobuf.js/pull/1495 is submitted.
export function googleProtobufValueFromObject(
object: any,
Copy link
Contributor

Choose a reason for hiding this comment

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

tslint-disable-next-line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

synth.py Outdated
@@ -29,6 +29,19 @@
library = gapic.node_library(name, version)
s.copy(library, excludes=["package.json", "README.md"])

# Expose helper module
index_file = 'src/index.ts'
Copy link
Contributor

Choose a reason for hiding this comment

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

So here I always wonder if we should do this or just exclude src/index.ts from the generation (line 30) and just have src/index.ts unchanged by the synthtool. Up to you here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'm going to err on the side of patching the library after generation, for now. We're doing some patching after the fact in the Python library too. @bcoe , your input gratefully accepted.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm following this regex, we're simply matching the end of the file? I think I like this approach for now 👍 as it allows us to add new clients via automation, without manual intervention -- let's try it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome, thank you! I'm happy to work with you on potential better solutions in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per conversation over chat, we decided to not do any post-processing in synth.py and instead exclude the hand-written files from being overwritten.

Copy link
Contributor

@alexander-fenster alexander-fenster left a comment

Choose a reason for hiding this comment

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

LGTM with some nits, all of them minor

@bcoe bcoe added the cla: yes This human has signed the Contributor License Agreement. label Dec 16, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 16, 2020
Copy link
Contributor

@bcoe bcoe 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 very minor nits, you folks did incredible work pulling this together this week.

@@ -12,3 +12,4 @@ system-test/*key.json
.DS_Store
package-lock.json
__pycache__
.vscode
Copy link
Contributor

Choose a reason for hiding this comment

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

we should consider moving .gitignore into a template, @sofisl does your library generation tool populate the file now?

) {
// [START aiplatform_create_training_pipeline_image_classification]
/**
* TODO(developer): Uncomment these variables before running the sample.\
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for the break \ on the end of the line, for multiline comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

stdout,
/Create training pipeline image classification response/
);
trainingPipelineId = stdout
Copy link
Contributor

Choose a reason for hiding this comment

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

I could imagine this assertion becoming a bit fragile, I'd just test for:

assert.match(stdout, /\/locations\/us-central1\/trainingPipelines\//)

Like above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/decorator.ts Outdated
// Walk the tree of nested namespaces contained within the enhanced-types.json file
function walkNamespaces(
// tslint:disable-next-line no-any
jsonNode: Record<string, any>,
Copy link
Contributor

Choose a reason for hiding this comment

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

would it silence these warnings if we we gave a slightly more specific type hint like Record<string, object>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

Unfortunately no, setting those to Record<string, object> didn't work.

I tried to provide define / provide types as much as possible in the recent commits. However, in some cases I needed to cast to unknown before casting to another type. In two specific cases, I wasn't able to work around using any--both uses are deep within the bowels of internal functions. (Even so, I'll continue to noodle on ways to address this issue.)

synth.py Outdated
@@ -29,6 +29,19 @@
library = gapic.node_library(name, version)
s.copy(library, excludes=["package.json", "README.md"])

# Expose helper module
index_file = 'src/index.ts'
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm following this regex, we're simply matching the end of the file? I think I like this approach for now 👍 as it allows us to add new clients via automation, without manual intervention -- let's try it.

tsconfig.json Show resolved Hide resolved
}
}
// [END aiplatform_create_training_pipeline_image_classification]
await createTrainingPipelineImageClassification();
Copy link
Contributor

Choose a reason for hiding this comment

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

This method call needs to be inside of the region tag, or the code the customer pastes will never be run 🙃 Here and anywhere else in the samples please.

Copy link
Contributor

Choose a reason for hiding this comment

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

@telpirion if you take this approach, then the await should be dropped. @sofisl @fhinkel, it would be good to update the sample policies to include uncaughtRejections, so that we properly exit with status code 1, even when we're not awaiting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -13,7 +13,9 @@
"test": "mocha --timeout 600000 test/*.js"
},
"dependencies": {
"@google-cloud/aiplatform": "^1.0.0"
"@google-cloud/aiplatform": "^1.0.0",
"chai": "^4.2.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

chai, and I'm guessing uuid, should be devDependencies if they are not strictly required to run the application code. Dependencies only used in tests go in devDependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

const uuid = require('uuid').v4;
const cp = require('child_process');
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
const cwd = path.join(__dirname, '..');
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably don't need to define or use cwd anywhere here - generally leaving it out works fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

.split('\n')[0];
});

after('should cancel the training pipeline and delete it', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar feedback left recently for @lucaswadedavis - for any of these after hooks, you can't reasonably promise they will always run. If the process crashes, server goes down, someone locally hits CTRL-C - the resources created here will be abandoned. This eventually leads to quota errors, or lagging performance problems as the number of resources grow. We should add some code in the beginning of the test suite that does resource cleanup, reaping any old resources that should have been cleaned up but got missed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved over chat--will follow up with clean up function soon.

src/decorator.ts Outdated
// Walk the tree of nested namespaces contained within the enhanced-types.json file
function walkNamespaces(
// tslint:disable-next-line no-any
jsonNode: Record<string, any>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please treat any lint warnings as errors (we are going to fix this soon)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed (as much as I could). There are still two uses of any that I haven't been able to work around yet (in value-converters.ts). I'll continue to look for ways to remove any where used.

synth.py Outdated
@@ -29,6 +29,19 @@
library = gapic.node_library(name, version)
s.copy(library, excludes=["package.json", "README.md"])

# Expose helper module
index_file = 'src/index.ts'
Copy link
Contributor

Choose a reason for hiding this comment

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

Danger! We very much don't want to make code specific changes like this in synth.py if it can be avoided. Can we double click here and talk about what's happening with @alexander-fenster and @bcoe ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this one is obviously a ❄️ . We have a plan to think how these exceptions (libraries augmented by extra stuff, like speech, vision, and this one) can be avoided, this is something I will look into in Q1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After chatting with @alexander-fenster and @sofisl , I've reverted the changes to synth.py so that we exclude the handwritten changes from being over written (rather than having custom post-processing steps in synth.py).

@telpirion telpirion merged commit b697a38 into master Dec 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants