Skip to content

Improve logging #29

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

Merged
merged 3 commits into from
Nov 21, 2017
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
37 changes: 31 additions & 6 deletions bin/plotly-export-server_electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const pkg = require('../package.json')

const argv = getServerArgs()
const SHOW_LOGS = !argv.quiet
const DEBUG = argv.debug

if (argv.version) {
console.log(pkg.version)
Expand Down Expand Up @@ -48,36 +49,60 @@ const opts = {
launch()

app.on('after-connect', (info) => {
if (SHOW_LOGS) {
if (DEBUG) {
console.log(`Listening on port ${info.port} after a ${info.startupTime} ms bootup`)
console.log(`Open routes: ${info.openRoutes.join(' ')}`)
}
})

app.on('after-export', (info) => {
if (SHOW_LOGS) {
console.log(`after-export, fig: ${info.fid} in ${info.processingTime} ms`)
console.log(JSON.stringify({
severity: 'INFO',
httpRequest: {
requestMethod: info.method
},
labels: {
fid: info.fid,
head: info.head,
processingTime: info.processingTime
}
}))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which looks like:

image

does that look ok @scjody ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we could use a severity field in the after-export section. maybe 'INFO'?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good to me. Have you been able to deploy it to stage and see if it looks OK on Stackdriver?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I just tried doing that via plotbot, but I got:

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've fixed Plotbot permissions, but there's no Docker image to deploy.

screen shot 2017-11-16 at 17 14 30

The Docker build needs to succeed before you can deploy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This may have been an intermittent CircleCI issue so I'm going to retry the build.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rebuild worked. Now I'm dealing with a different deployment issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that worked. The latest version of this branch has been deployed to stage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it looks OK on Stackdriver?

From a private convo with @scjody :

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we could use a severity field in the after-export section. maybe 'INFO'?

done in cbb4e13

}
})

app.on('export-error', (info) => {
if (SHOW_LOGS) {
console.log(`export error ${info.code} - ${info.msg}`)
console.log(JSON.stringify({
severity: 'ERROR',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

textPayload: `${info.code} - ${info.msg}`,
labels: {
fid: info.fid,
head: info.head
}
}))
}
})

process.on('uncaughtException', (err) => {
console.warn(err)
if (SHOW_LOGS) {
console.log(JSON.stringify({
severity: 'ERROR',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

textPayload: err.toString()
}))
}

if (argv.keepAlive) {
if (SHOW_LOGS) {
if (DEBUG) {
console.log('... relaunching')
}
launch()
}
})

function launch () {
console.log(`Spinning up server with pid: ${process.pid}`)
if (DEBUG) {
console.log(`Spinning up server with pid: ${process.pid}`)
}
app = plotlyExporter.serve(opts)
}
1 change: 1 addition & 0 deletions src/app/server/create-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function createServer (app, BrowserWindow, ipcMain, opts) {
// and is emitted on 'export-error' and 'after-export'
const fullInfo = {
port: opts.port,
method: req.method,
id: id
}

Expand Down
17 changes: 9 additions & 8 deletions test/unit/server_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ tap.test('createServer:', t => {
const app = args[0]

app.on('after-export', (info) => {
t.equal(Object.keys(info).length, 15, '# of keys')
t.equal(Object.keys(info).length, 16, '# of keys')
t.equal(info.method, 'POST', 'method')
t.type(info.id, 'string', 'id')
t.equal(info.port, args[3].port, 'port')
t.equal(info.pending, 0, 'pending')
Expand Down Expand Up @@ -179,7 +180,7 @@ tap.test('createServer:', t => {

t.test('on invalid route', t => {
_boot([], (args) => {
wrapApp(t, args, [4, 404, 'invalid route'])
wrapApp(t, args, [5, 404, 'invalid route'])

_post('not-gonna-work', body0(), (err, res, body) => {
if (err) t.fail()
Expand All @@ -193,7 +194,7 @@ tap.test('createServer:', t => {
const opts = opts0()

_boot([false, false, false, opts], (args) => {
wrapApp(t, args, [4, 504, 'window for given route does not exist'])
wrapApp(t, args, [5, 504, 'window for given route does not exist'])

_post('', body0(), (err, res, body) => {
if (err) t.fail()
Expand All @@ -208,7 +209,7 @@ tap.test('createServer:', t => {
BrowserWindow.getAllWindows = () => ({length: Infinity})

_boot([false, BrowserWindow], (args) => {
wrapApp(t, args, [4, 402, 'too many windows are opened'])
wrapApp(t, args, [5, 402, 'too many windows are opened'])

_post('', body0(), (err, res, body) => {
if (err) t.fail()
Expand All @@ -220,7 +221,7 @@ tap.test('createServer:', t => {

t.test('on json parse errors', t => {
_boot([], (args) => {
wrapApp(t, args, [4, 422, 'json parse error'])
wrapApp(t, args, [5, 422, 'json parse error'])

_post('', body0() + '/', (err, res, body) => {
if (err) t.fail()
Expand All @@ -236,7 +237,7 @@ tap.test('createServer:', t => {
sinon.stub(_module, 'parse').yields(432)

_boot([false, false, false, opts], (args) => {
wrapApp(t, args, [4, 432, ''])
wrapApp(t, args, [5, 432, ''])

_post('', body0(), (err, res, body) => {
if (err) t.fail()
Expand All @@ -251,7 +252,7 @@ tap.test('createServer:', t => {
const opts = mockWebContents(opts0(), 467, {msg: 'error msg'})

_boot([false, false, false, opts], (args) => {
wrapApp(t, args, [11, 467, 'error msg'])
wrapApp(t, args, [12, 467, 'error msg'])

_post('', body0(), (err, res, body) => {
if (err) t.fail()
Expand All @@ -267,7 +268,7 @@ tap.test('createServer:', t => {
sinon.stub(_module, 'convert').yields(483)

_boot([false, false, false, opts], (args) => {
wrapApp(t, args, [12, 483, ''])
wrapApp(t, args, [13, 483, ''])

_post('', body0(), (err, res, body) => {
if (err) t.fail()
Expand Down