Skip to content

Conversation

@cristiancavalli
Copy link
Contributor

@cristiancavalli cristiancavalli commented Nov 20, 2016

To Dos

To accommodate invocations like:
syslog.entry({textPayload: 'test'})
Create a basic class which attempts to automatically
establish resource values based on connectivity to
the metadata service and environmental variables.

This addition does not affect the existing API and
does not modify or augment user supplied resources.
The meta data class will attempt to determine if the
resource is a cloud function, app engine application
or compute engine instance. If it can't match on any
of these configurations but can still locate a project
id then it will produce a global resource id.

This addition adds behavioral tests and adds a new
Metadata class-specific set of unit tests which reach
100% module coverage:
https://coveralls.io/github/cristiancavalli/google-cloud-node

cc @ofrobots

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 20, 2016
@cristiancavalli cristiancavalli force-pushed the automatic-metadata branch 14 times, most recently from 31b483e to 03ef83d Compare November 20, 2016 21:10
@stephenplusplus stephenplusplus added enhancement api: logging Issues related to the Cloud Logging API. labels Nov 21, 2016
};

Log.prototype.assignDefaultMetadata_ = function(entry, callback) {
var entryMetadata = entry.metadata;

This comment was marked as spam.

This comment was marked as spam.

* @returns {module:metadata}
* @chainable
*/
Metadata.prototype.getProjectId = function(callback) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

* @private
*/
Metadata.prototype.attachRequestStreamListeners_ = function(stream) {
var self = this;

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

'Must supply a callback function as an argument to invocation.');
} else if (!is.empty(self.processProjectId_()) &&
is.string(self.processProjectId_())) {
// The process's GCLOUD_PROJECT env variable has been set

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

if (!is.object(entryMetadata) || !is.object(entryMetadata.resource)) {
this.metadata_.getDefaultResource(function(err, resource) {
if (err) {
callback(err);

This comment was marked as spam.

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor

I noticed this PR doesn't decorate requests sent through the write method, but only ones the severity shortcuts. Is this intentional?

@cristiancavalli cristiancavalli force-pushed the automatic-metadata branch 2 times, most recently from d19f782 to e326dad Compare November 21, 2016 17:57
@cristiancavalli
Copy link
Contributor Author

refactored the call chain to only affect the write method

labels: {
project_id: projectId,
module_id: process.env.GAE_SERVICE,
version_id: process.env.GAE_VERSION

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@cristiancavalli cristiancavalli force-pushed the automatic-metadata branch 3 times, most recently from 814c95a to 285cb40 Compare November 21, 2016 22:12
var self = this;
this.metadata_.getDefaultResource(function(err, resource) {
if (err) {
callback(err);

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@googlebot googlebot removed the cla: yes This human has signed the Contributor License Agreement. label Nov 22, 2016
@stephenplusplus
Copy link
Contributor

@cristiancavalli can you try this out on the various environments to see that it's working as intended? I've made a small zip you can run (edit the env object in system-test/logging.js, npm install && npm run system-test after installing), https://storage.googleapis.com/stephen-has-a-new-bucket/pr-1808-test.zip

@cristiancavalli
Copy link
Contributor Author

cristiancavalli commented Nov 30, 2016

@stephenplusplus Sorry for the latency -- just finished testing on GCE and all tests pass. This passing test should apply to GKE as well.

@stephenplusplus stephenplusplus force-pushed the automatic-metadata branch 2 times, most recently from 9ddc84c to b347b54 Compare November 30, 2016 16:18
@stephenplusplus
Copy link
Contributor

This is ready for a final review. @callmehiphop PTAL.

var formattedEntry = entry.toJSON();
formattedEntry.logName = this.formattedName_;
return formattedEntry;
async.map(entries, function(entry, callback) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@callmehiphop
Copy link
Contributor

@stephenplusplus I think we need to stub the auth client or something, I'm seeing documentation failures in regards to grabbing the projectId.

@stephenplusplus
Copy link
Contributor

Pushed a fix that's a little bit sad. Let me know if you know a better way.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 66f67b0 on cristiancavalli:automatic-metadata into ** on GoogleCloudPlatform:master**.

@callmehiphop
Copy link
Contributor

@stephenplusplus I'm ok with that if you are. Alternatively I think we could just stub google-auto-auth in the docs spec file. Something like..

var FakeAuth = function() {
  var Auth = require('google-auto-auth');
  Auth.prototype.getProjectId = function(cb) {
    cb(null, 'grape-spaceship-123');
  };
  return Auth;
};

@stephenplusplus
Copy link
Contributor

stephenplusplus commented Dec 1, 2016

I went that way originally, but couldn't get it to work :( It's like it's never required directly in our snippet tests. Let me know if you know a better way to do it than:

--- a/test/docs.js
+++ b/test/docs.js
@@ -57,6 +57,14 @@ var JSHintError = createErrorClass('JSHintError', function(err) {
   this.code = err.code;
 });

+var FakeAuth = function() {
+  var Auth = require('google-auto-auth');
+  Auth.prototype.getProjectId = function(cb) {
+    cb(null, 'grape-spaceship-123');
+  };
+  return Auth;
+};
+
 var FakeConsole = Object.keys(console)
   .reduce(function(console, method) {
     console[method] = noop;
@@ -245,6 +253,7 @@ function createSnippet(mod, instantiation, method) {
       'keyFilename: \'/path/to/keyfile.json\'',
       'keyFilename: \'\''
     )
+    .replace('require(\'google-auto-auth\')', FakeAuth.toString())
     .replace('require(\'express\')', FakeExpress.toString())
     .replace('require(\'level\')', FakeLevel.toString())
     .replace('require(\'bluebird\')', FakeBluebird.toString())

@callmehiphop
Copy link
Contributor

Ah, right. We only swap out dependencies in the examples themselves.. I think if we wanted to go this route we'd probably have to run some code in the sandbox that uses proxyquire. So I think this is fine for now and maybe I'll try and take a crack at implementing proxyquire later.

@callmehiphop
Copy link
Contributor

Can we add logging/metadata.js to the ignore list within scripts/docs/config.js?

cristiancavalli and others added 10 commits December 2, 2016 08:12
To accommodate invocations like:
  `syslog.entry({textPayload: 'test'})`
Create a basic class which attempts to automatically
establish resource values based on connectivity to
the metadata service and environmental variables.

This addition does not affect the existing API and
does not modify or augment user supplied resources.
The meta data class will attempt to determine if the
resource is a cloud function, app engine application
or compute engine instance. If it can't match on any
of these configurations but can still locate a project
id then it will produce a global resource id.
@stephenplusplus stephenplusplus merged commit 978b1f5 into googleapis:master Dec 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: logging Issues related to the Cloud Logging API. cla: no This human has *not* signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants