mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #18 from overleaf/jpa-csh-tracing-end-time-from-fs
[checkLogLevel] read the updated tracing end time from disk
This commit is contained in:
commit
2895b867cf
5 changed files with 1617 additions and 747 deletions
|
@ -1 +1,2 @@
|
||||||
10.21.0
|
10.21.0
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const bunyan = require('bunyan')
|
const bunyan = require('bunyan')
|
||||||
const request = require('request')
|
const fs = require('fs')
|
||||||
const yn = require('yn')
|
const yn = require('yn')
|
||||||
const OError = require('@overleaf/o-error')
|
const OError = require('@overleaf/o-error')
|
||||||
const GCPLogging = require('@google-cloud/logging-bunyan')
|
const GCPLogging = require('@google-cloud/logging-bunyan')
|
||||||
|
@ -42,18 +42,12 @@ const Logger = (module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
checkLogLevel() {
|
checkLogLevel() {
|
||||||
const options = {
|
fs.readFile('/logging/tracingEndTime', (error, end) => {
|
||||||
headers: {
|
if (error || !end) {
|
||||||
'Metadata-Flavor': 'Google'
|
|
||||||
},
|
|
||||||
uri: `http://metadata.google.internal/computeMetadata/v1/project/attributes/${this.loggerName}-setLogLevelEndTime`
|
|
||||||
}
|
|
||||||
request(options, (err, response, body) => {
|
|
||||||
if (err) {
|
|
||||||
this.logger.level(this.defaultLevel)
|
this.logger.level(this.defaultLevel)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (parseInt(body) > Date.now()) {
|
if (parseInt(end) > Date.now()) {
|
||||||
this.logger.level('trace')
|
this.logger.level('trace')
|
||||||
} else {
|
} else {
|
||||||
this.logger.level(this.defaultLevel)
|
this.logger.level(this.defaultLevel)
|
||||||
|
|
2309
libraries/logger/package-lock.json
generated
2309
libraries/logger/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -7,7 +7,7 @@
|
||||||
"url": "http://github.com/sharelatex/logger-sharelatex.git"
|
"url": "http://github.com/sharelatex/logger-sharelatex.git"
|
||||||
},
|
},
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
"version": "2.0.0",
|
"version": "2.1.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha test/**/*.js",
|
"test": "mocha test/**/*.js",
|
||||||
"format": "prettier-eslint '**/*.js' --list-different",
|
"format": "prettier-eslint '**/*.js' --list-different",
|
||||||
|
@ -19,12 +19,11 @@
|
||||||
"@overleaf/o-error": "^3.0.0",
|
"@overleaf/o-error": "^3.0.0",
|
||||||
"bunyan": "1.8.12",
|
"bunyan": "1.8.12",
|
||||||
"raven": "1.1.3",
|
"raven": "1.1.3",
|
||||||
"request": "2.88.0",
|
|
||||||
"yn": "^3.1.1"
|
"yn": "^3.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "4.2.0",
|
"chai": "4.2.0",
|
||||||
"eslint": "^4.18.1",
|
"eslint": "^6.6.0",
|
||||||
"eslint-config-prettier": "^3.1.0",
|
"eslint-config-prettier": "^3.1.0",
|
||||||
"eslint-config-standard": "^11.0.0",
|
"eslint-config-standard": "^11.0.0",
|
||||||
"eslint-plugin-chai-expect": "^1.1.1",
|
"eslint-plugin-chai-expect": "^1.1.1",
|
||||||
|
@ -36,6 +35,7 @@
|
||||||
"eslint-plugin-standard": "^3.0.1",
|
"eslint-plugin-standard": "^3.0.1",
|
||||||
"mocha": "^5.2.0",
|
"mocha": "^5.2.0",
|
||||||
"prettier": "^1.18.2",
|
"prettier": "^1.18.2",
|
||||||
|
"prettier-eslint-cli": "^5.0.0",
|
||||||
"sandboxed-module": "2.0.3",
|
"sandboxed-module": "2.0.3",
|
||||||
"sinon": "7.2.3",
|
"sinon": "7.2.3",
|
||||||
"sinon-chai": "3.3.0"
|
"sinon-chai": "3.3.0"
|
||||||
|
|
|
@ -40,7 +40,9 @@ describe('LoggingManager', function() {
|
||||||
this.Raven = {
|
this.Raven = {
|
||||||
Client: sinon.stub().returns(this.ravenClient)
|
Client: sinon.stub().returns(this.ravenClient)
|
||||||
}
|
}
|
||||||
this.Request = sinon.stub()
|
this.Fs = {
|
||||||
|
readFile: sinon.stub()
|
||||||
|
}
|
||||||
this.stackdriverStreamConfig = { stream: 'stackdriver' }
|
this.stackdriverStreamConfig = { stream: 'stackdriver' }
|
||||||
this.stackdriverClient = {
|
this.stackdriverClient = {
|
||||||
stream: sinon.stub().returns(this.stackdriverStreamConfig)
|
stream: sinon.stub().returns(this.stackdriverStreamConfig)
|
||||||
|
@ -53,7 +55,7 @@ describe('LoggingManager', function() {
|
||||||
requires: {
|
requires: {
|
||||||
bunyan: this.Bunyan,
|
bunyan: this.Bunyan,
|
||||||
raven: this.Raven,
|
raven: this.Raven,
|
||||||
request: this.Request,
|
fs: this.Fs,
|
||||||
'@google-cloud/logging-bunyan': this.GCPLogging
|
'@google-cloud/logging-bunyan': this.GCPLogging
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -286,20 +288,16 @@ describe('LoggingManager', function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('checkLogLevel', 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()
|
this.logger.checkLogLevel()
|
||||||
const options = {
|
this.Fs.readFile.should.have.been.calledWithMatch(
|
||||||
headers: {
|
'/logging/tracingEndTime'
|
||||||
'Metadata-Flavor': 'Google'
|
)
|
||||||
},
|
|
||||||
uri: `http://metadata.google.internal/computeMetadata/v1/project/attributes/${this.loggerName}-setLogLevelEndTime`
|
|
||||||
}
|
|
||||||
this.Request.should.have.been.calledWithMatch(options)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when request has error', function() {
|
describe('when read errors', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.Request.yields('error')
|
this.Fs.readFile.yields(new Error('error'))
|
||||||
this.logger.checkLogLevel()
|
this.logger.checkLogLevel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -310,9 +308,9 @@ describe('LoggingManager', function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when statusCode is not 200', function() {
|
describe('when the file is empty', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.Request.yields(null, { statusCode: 404 })
|
this.Fs.readFile.yields(null, '')
|
||||||
this.logger.checkLogLevel()
|
this.logger.checkLogLevel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -325,7 +323,7 @@ describe('LoggingManager', function() {
|
||||||
|
|
||||||
describe('when time value returned that is less than current time', function() {
|
describe('when time value returned that is less than current time', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.Request.yields(null, { statusCode: 200 }, '1')
|
this.Fs.readFile.yields(null, '1')
|
||||||
this.logger.checkLogLevel()
|
this.logger.checkLogLevel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -340,7 +338,7 @@ describe('LoggingManager', function() {
|
||||||
describe('when level is already set', function() {
|
describe('when level is already set', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.bunyanLogger.level.returns(10)
|
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()
|
this.logger.checkLogLevel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -354,7 +352,7 @@ describe('LoggingManager', function() {
|
||||||
describe('when level is not already set', function() {
|
describe('when level is not already set', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.bunyanLogger.level.returns(20)
|
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()
|
this.logger.checkLogLevel()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue