Skip to content

Commit

Permalink
logging: use correct case for cluster-name attribtue (#2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofrobots authored and stephenplusplus committed Aug 11, 2017
1 parent 60701c5 commit 89bfd37
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
9 changes: 5 additions & 4 deletions src/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,17 @@ Metadata.getGCEDescriptor = function(callback) {
* @return {object}
*/
Metadata.getGKEDescriptor = function(callback) {
gcpMetadata.instance('attributes/clusterName', function(err, _, clusterName) {
if (err) {
callback(err);
gcpMetadata.instance('attributes/cluster-name', function(e, _, clusterName) {
if (e) {
callback(e);
return;
}

callback(null, {
type: 'container',
labels: {
// TODO(ofrobots): it would be good to include the namespace_id as well.
// TODO(ofrobots): it would be good to include the namespace_id as
// well.
cluster_name: clusterName
}
});
Expand Down
34 changes: 25 additions & 9 deletions test/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ var assert = require('assert');
var extend = require('extend');
var proxyquire = require('proxyquire');

var instanceArgsOverride;
var instanceOverride;
var fakeGcpMetadata = {
instance: function(path, cb) {
setImmediate(function() {
var args = instanceArgsOverride || [null, null, 'fake-instance-value'];
if (instanceOverride && instanceOverride.path) {
assert.strictEqual(path, instanceOverride.path);
}
var args = (instanceOverride && instanceOverride.args) ||
[null, null, 'fake-instance-value'];
cb.apply(fakeGcpMetadata, args);
});
}
Expand Down Expand Up @@ -53,7 +57,7 @@ describe('metadata', function() {
};
extend(Metadata, MetadataCached);
metadata = new Metadata(LOGGING);
instanceArgsOverride = null;
instanceOverride = null;
});

afterEach(function() {
Expand Down Expand Up @@ -119,7 +123,10 @@ describe('metadata', function() {
var CLUSTER_NAME = 'gke-cluster-name';

it('should return the correct descriptor', function(done) {
instanceArgsOverride = [null, null, CLUSTER_NAME];
instanceOverride = {
path: 'attributes/cluster-name',
args: [null, null, CLUSTER_NAME]
};

Metadata.getGKEDescriptor(function(err, descriptor) {
assert.ifError(err);
Expand All @@ -135,7 +142,7 @@ describe('metadata', function() {

it('should return error on failure to acquire metadata', function(done) {
var FAKE_ERROR = new Error();
instanceArgsOverride = [ FAKE_ERROR ];
instanceOverride = { args: [ FAKE_ERROR ] };

Metadata.getGKEDescriptor(function(err) {
assert.strictEqual(err, FAKE_ERROR);
Expand All @@ -148,7 +155,10 @@ describe('metadata', function() {
var INSTANCE_ID = 'fake-instance-id';

it('should return the correct descriptor', function(done) {
instanceArgsOverride = [null, null, INSTANCE_ID];
instanceOverride = {
path: 'id',
args: [null, null, INSTANCE_ID]
};

Metadata.getGCEDescriptor(function(err, descriptor) {
assert.ifError(err);
Expand All @@ -164,7 +174,7 @@ describe('metadata', function() {

it('should return error on failure to acquire metadata', function(done) {
var FAKE_ERROR = new Error();
instanceArgsOverride = [ FAKE_ERROR ];
instanceOverride = { args: [ FAKE_ERROR ] };

Metadata.getGCEDescriptor(function(err) {
assert.strictEqual(err, FAKE_ERROR);
Expand Down Expand Up @@ -240,7 +250,10 @@ describe('metadata', function() {
describe('compute engine', function() {
it('should return correct descriptor', function(done) {
var INSTANCE_ID = 'overridden-value';
instanceArgsOverride = [null, null, INSTANCE_ID];
instanceOverride = {
path: 'id',
args: [null, null, INSTANCE_ID]
};

metadata.logging.auth.getEnvironment = function(callback) {
callback(null, {
Expand All @@ -264,7 +277,10 @@ describe('metadata', function() {
describe('container engine', function() {
it('should return correct descriptor', function(done) {
var CLUSTER_NAME = 'overridden-value';
instanceArgsOverride = [null, null, CLUSTER_NAME];
instanceOverride = {
path: 'attributes/cluster-name',
args: [null, null, CLUSTER_NAME]
};

metadata.logging.auth.getEnvironment = function(callback) {
callback(null, {
Expand Down

0 comments on commit 89bfd37

Please sign in to comment.