Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/logging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"google-proto-files": "^0.12.0",
"is": "^3.0.1",
"pumpify": "^1.3.5",
"snakecase-keys": "^1.1.0",
"stream-events": "^1.0.1",
"string-format-obj": "^1.0.0",
"through2": "^2.0.3"
Expand Down
4 changes: 4 additions & 0 deletions packages/logging/src/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var arrify = require('arrify');
var common = require('@google-cloud/common');
var extend = require('extend');
var is = require('is');
var snakeCaseKeys = require('snakecase-keys');

/**
* @type {module:logging/entry}
Expand Down Expand Up @@ -591,6 +592,9 @@ Log.prototype.write = function(entry, options, callback) {
writeWithResource(resource);
});
} else {
if (options.resource.labels) {
options.resource.labels = snakeCaseKeys(options.resource.labels);
}
writeWithResource(options.resource);
}

Expand Down
12 changes: 12 additions & 0 deletions packages/logging/system-test/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,18 @@ describe('Logging', function() {
});
});

it('should write a log with camelcase resource label keys', function(done) {
log.write(logEntries, {
resource: {
type: 'gce_instance',
labels: {
zone: 'global',
instanceId: '3'
}
}
}, done);
});

it('should write to a log with alert helper', function(done) {
log.alert(logEntries, options, done);
});
Expand Down
33 changes: 33 additions & 0 deletions packages/logging/test/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,39 @@ describe('Log', function() {
log.write(ENTRY, optionsWithResource, done);
});

it('should transform camelcase label keys to snake case', function(done) {
var CUSTOM_RESOURCE = {
labels: {
camelCaseKey: 'camel-case-key-val'
}
};
var EXPECTED_RESOURCE = {
labels: {
camel_case_key: 'camel-case-key-val'
}
};
var optionsWithResource = extend({}, OPTIONS, {
resource: CUSTOM_RESOURCE
});

log.logging.request = function(config, callback) {
assert.strictEqual(config.client, 'loggingServiceV2Client');
assert.strictEqual(config.method, 'writeLogEntries');

assert.deepEqual(config.reqOpts, {
logName: log.formattedName_,
entries: [ENTRY],
resource: EXPECTED_RESOURCE
});

assert.strictEqual(config.gaxOpts, undefined);

callback();
};

log.write(ENTRY, optionsWithResource, done);
});

it('should make the correct API request', function(done) {
log.logging.request = function(config, callback) {
assert.strictEqual(config.client, 'loggingServiceV2Client');
Expand Down