-
Notifications
You must be signed in to change notification settings - Fork 640
Add default resource generator for log entries #1808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add default resource generator for log entries #1808
Conversation
31b483e to
03ef83d
Compare
packages/logging/src/log.js
Outdated
| }; | ||
|
|
||
| Log.prototype.assignDefaultMetadata_ = function(entry, callback) { | ||
| var entryMetadata = entry.metadata; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * @returns {module:metadata} | ||
| * @chainable | ||
| */ | ||
| Metadata.prototype.getProjectId = function(callback) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/logging/src/metadata.js
Outdated
| * @private | ||
| */ | ||
| Metadata.prototype.attachRequestStreamListeners_ = function(stream) { | ||
| var self = this; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/logging/src/metadata.js
Outdated
| '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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/logging/src/log.js
Outdated
| 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
I noticed this PR doesn't decorate requests sent through the |
d19f782 to
e326dad
Compare
|
refactored the call chain to only affect the |
| 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
814c95a to
285cb40
Compare
packages/logging/src/log.js
Outdated
| 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
285cb40 to
b789a1a
Compare
|
@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 |
|
@stephenplusplus Sorry for the latency -- just finished testing on GCE and all tests pass. This passing test should apply to GKE as well. |
9ddc84c to
b347b54
Compare
|
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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@stephenplusplus I think we need to stub the auth client or something, I'm seeing documentation failures in regards to grabbing the projectId. |
|
Pushed a fix that's a little bit sad. Let me know if you know a better way. |
|
Changes Unknown when pulling 66f67b0 on cristiancavalli:automatic-metadata into ** on GoogleCloudPlatform:master**. |
|
@stephenplusplus I'm ok with that if you are. Alternatively I think we could just stub var FakeAuth = function() {
var Auth = require('google-auto-auth');
Auth.prototype.getProjectId = function(cb) {
cb(null, 'grape-spaceship-123');
};
return Auth;
}; |
|
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()) |
|
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. |
|
Can we add logging/metadata.js to the ignore list within scripts/docs/config.js? |
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.
66f67b0 to
691d385
Compare
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