[checkLogLevel] read the updated tracing end time from disk

This commit is contained in:
Jakob Ackermann
2020-05-15 13:39:35 +02:00
parent 7be3c208fd
commit 5aad5db40f
5 changed files with 22 additions and 341 deletions
@@ -40,7 +40,9 @@ describe('LoggingManager', function() {
this.Raven = {
Client: sinon.stub().returns(this.ravenClient)
}
this.Request = sinon.stub()
this.Fs = {
readFile: sinon.stub()
}
this.stackdriverStreamConfig = { stream: 'stackdriver' }
this.stackdriverClient = {
stream: sinon.stub().returns(this.stackdriverStreamConfig)
@@ -53,7 +55,7 @@ describe('LoggingManager', function() {
requires: {
bunyan: this.Bunyan,
raven: this.Raven,
request: this.Request,
fs: this.Fs,
'@google-cloud/logging-bunyan': this.GCPLogging
}
})
@@ -260,20 +262,14 @@ describe('LoggingManager', function() {
})
describe('checkLogLevel', function() {
it('should request log level override from google meta data service', function() {
it('should request log level override from the config map', function() {
this.logger.checkLogLevel()
const options = {
headers: {
'Metadata-Flavor': 'Google'
},
uri: `http://metadata.google.internal/computeMetadata/v1/project/attributes/${this.loggerName}-setLogLevelEndTime`
}
this.Request.should.have.been.calledWithMatch(options)
this.Fs.readFile.should.have.been.calledWithMatch('/logging/tracingEndTime')
})
describe('when request has error', function() {
describe('when read errors', function() {
beforeEach(function() {
this.Request.yields('error')
this.Fs.readFile.yields(new Error('error'))
this.logger.checkLogLevel()
})
@@ -284,9 +280,9 @@ describe('LoggingManager', function() {
})
})
describe('when statusCode is not 200', function() {
describe('when the file is empty', function() {
beforeEach(function() {
this.Request.yields(null, { statusCode: 404 })
this.Fs.readFile.yields(null, '')
this.logger.checkLogLevel()
})
@@ -299,7 +295,7 @@ describe('LoggingManager', function() {
describe('when time value returned that is less than current time', function() {
beforeEach(function() {
this.Request.yields(null, { statusCode: 200 }, '1')
this.Fs.readFile.yields(null, '1')
this.logger.checkLogLevel()
})
@@ -314,7 +310,7 @@ describe('LoggingManager', function() {
describe('when level is already set', function() {
beforeEach(function() {
this.bunyanLogger.level.returns(10)
this.Request.yields(null, { statusCode: 200 }, this.start + 1000)
this.Fs.readFile.yields(null, (this.start + 1000).toString())
this.logger.checkLogLevel()
})
@@ -328,7 +324,7 @@ describe('LoggingManager', function() {
describe('when level is not already set', function() {
beforeEach(function() {
this.bunyanLogger.level.returns(20)
this.Request.yields(null, { statusCode: 200 }, this.start + 1000)
this.Fs.readFile.yields(null, (this.start + 1000).toString())
this.logger.checkLogLevel()
})