Skip to content
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

feat(gatsby): structured logging #14973

Merged
merged 160 commits into from Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
d24dea9
initial commit
pieh Jun 20, 2019
4271f8f
Merge remote-tracking branch 'origin/master' into logs-to-redux
pieh Jun 30, 2019
74c99c6
update code after error-map merge
pieh Jul 1, 2019
7453800
Merge remote-tracking branch 'origin/master' into logs-to-redux
pieh Jul 31, 2019
0ee5018
update
pieh Aug 1, 2019
aabfcaf
update
pieh Aug 8, 2019
e21b8ea
Merge remote-tracking branch 'origin/master' into logs-to-redux
pieh Aug 8, 2019
7de3b0e
update
pieh Aug 12, 2019
2b0a5e7
Merge remote-tracking branch 'origin/master' into logs-to-redux
pieh Aug 12, 2019
adb4314
yes, I'm empty commit, just to make publishing easier
pieh Aug 12, 2019
6208382
pass all message properties to action
pieh Aug 12, 2019
f517a08
errors messages - use errorCode instead of id
pieh Aug 22, 2019
8b1aae4
richer finished activity logs
pieh Aug 23, 2019
ed9111f
errorCode -> code
pieh Aug 23, 2019
5a8fe24
uuid, no stateful logs
pieh Aug 23, 2019
df279e8
more no stateful logs
pieh Aug 23, 2019
99cd553
make "building static html for pages" progress activity
pieh Aug 26, 2019
894b8cd
Add test suite and fix some bugs
sidharthachatterjee Aug 26, 2019
cd57794
Add tests for logs in development
sidharthachatterjee Aug 26, 2019
1afec44
Run in CI
sidharthachatterjee Aug 26, 2019
70ca6e2
Fix linting
sidharthachatterjee Aug 26, 2019
1d0da7e
Fix tests
sidharthachatterjee Aug 26, 2019
a527b2c
fixup reporter test properly
pieh Aug 26, 2019
0594b32
Merge remote-tracking branch 'origin/master' into logs-to-redux
pieh Aug 27, 2019
1869209
ensure FAILED status when panic is called
pieh Aug 27, 2019
14a2bd4
Fix dep and name in package.json
sidharthachatterjee Aug 27, 2019
33fd166
Add test for failed status on panic
sidharthachatterjee Aug 27, 2019
47cfa2f
Add timestamp for all actions
sidharthachatterjee Aug 27, 2019
cf9d169
WIP handle exit
sidharthachatterjee Aug 27, 2019
11437a1
integration test - fixup gatsby dep version
pieh Aug 27, 2019
82e0177
fix failing test, runInBand
pieh Aug 27, 2019
7b91234
Add panicOnBuild for activities
sidharthachatterjee Aug 27, 2019
d48db3b
Clean up tests
sidharthachatterjee Aug 27, 2019
527910d
Clean up
sidharthachatterjee Aug 28, 2019
05a8b04
Wait for jobs to finish before setting status
sidharthachatterjee Aug 28, 2019
82a92b9
debounce SET_STATUS
pieh Aug 28, 2019
c98e8d4
fix lint
pieh Aug 28, 2019
65268fb
Fix tests
sidharthachatterjee Aug 29, 2019
dd5a024
Fix more tests
sidharthachatterjee Aug 29, 2019
1bd7a78
Add ipc.json
sidharthachatterjee Aug 29, 2019
b833d71
Fix order of set status in develop
sidharthachatterjee Aug 29, 2019
4a281a8
Consistently check global status for activity actions
sidharthachatterjee Aug 29, 2019
3c0a72f
Remove debug code
sidharthachatterjee Aug 29, 2019
68c12b9
don't emit actions for activities used only internally to keep track …
pieh Sep 2, 2019
473f85f
Merge branch 'master' into logs-to-redux
sidharthachatterjee Sep 2, 2019
d27d2a0
Life is one giant hack
sidharthachatterjee Sep 2, 2019
50e0f55
merge conflicts are the worst
pieh Sep 4, 2019
3c1b731
chore sync yarn.lock
pieh Sep 4, 2019
75e4c57
Merge remote-tracking branch 'origin/master' into logs-to-redux
pieh Sep 4, 2019
869770b
get rid of commented out code
pieh Sep 5, 2019
8a0e973
fix-up regressions to open tracing
pieh Sep 5, 2019
6a45b35
fix lint
pieh Sep 5, 2019
1d1974c
don't use ink as reporter in jest
pieh Sep 5, 2019
c07dc85
Pass through error code in premature end handler in signal exit
sidharthachatterjee Sep 5, 2019
7d2c02c
fix webpack rebuilds not failing correctly
pieh Sep 5, 2019
a5ed126
more cleanup
pieh Sep 5, 2019
3853e8d
remove debug log
pieh Sep 5, 2019
834eda7
Hide some internal activities
sidharthachatterjee Sep 5, 2019
2ecd6b0
Move stuff over to constants
sidharthachatterjee Sep 5, 2019
ea0c9f6
fml
sidharthachatterjee Sep 5, 2019
a5289da
fml: the sequel
sidharthachatterjee Sep 5, 2019
6d4f1e4
fml: revolutions
sidharthachatterjee Sep 5, 2019
3b78d24
Fix mocks in tests
sidharthachatterjee Sep 5, 2019
743004c
actually emit stack as part of error messages
pieh Sep 5, 2019
e961366
sanitze structured stack traces
pieh Sep 6, 2019
3e52a92
drop `methodName` and `typeName`
pieh Sep 8, 2019
9328418
fix tests (?)
pieh Sep 9, 2019
1d01108
make fields on call site nullable
pieh Sep 9, 2019
cdc0bbe
check only error messages and not all logs
pieh Sep 9, 2019
1860bd1
Group constants because sanity is hard to regain once lost
sidharthachatterjee Sep 9, 2019
93706a1
`fileName` is not nullable - those are filtered out before stack shap…
pieh Sep 9, 2019
090184d
Merge remote-tracking branch 'upstream/master' into logs-to-redux
Sep 9, 2019
e194743
Merge remote-tracking branch 'upstream/master' into logs-to-redux
Sep 9, 2019
0558820
split page and static query running in builds (keep single activity)
pieh Sep 10, 2019
fab5b4b
remove debug log
pieh Sep 11, 2019
fa8c7ee
update constants
pieh Sep 11, 2019
50c8066
fix lint
pieh Sep 11, 2019
d9c944e
sync yurnalist logger
pieh Sep 11, 2019
97bb87b
display webpack warnings for develop + build-javascript
pieh Sep 12, 2019
505e8e7
return full structured errors when calling panicOnBuild
pieh Sep 12, 2019
b8fc424
fix export name
pieh Sep 12, 2019
23bade6
emit structured errors from query extraction to browser overlay
pieh Sep 12, 2019
ebb902b
fix lint
pieh Sep 12, 2019
dba2cc7
get rid of debugging code
pieh Sep 13, 2019
4294ea8
Apply suggestions from code review
pieh Sep 13, 2019
7fa5491
more onLogAaction -> onLogAction
pieh Sep 13, 2019
ace411c
Update packages/gatsby/src/commands/develop.js
pieh Sep 13, 2019
8792cc5
basic handling of structured errors in dev browser overlay
pieh Sep 16, 2019
355be52
Merge remote-tracking branch 'origin/master' into logs-to-redux
pieh Sep 16, 2019
7a60612
cleanup remainings of ditched stateful logs
pieh Sep 16, 2019
4591917
remove unused graphqlValidationError error (it's structured right now)
pieh Sep 16, 2019
8ee618f
structure multiple root query error
pieh Sep 16, 2019
7a8b784
strcuture babel parsing error in query extraction
pieh Sep 16, 2019
6476d40
structure parsing error on preprocessed code
pieh Sep 16, 2019
8916b3d
structure file reading error when extracting
pieh Sep 16, 2019
37c6228
fix lint
pieh Sep 16, 2019
3db6f6e
Update packages/gatsby-cli/src/reporter/index.js
sidharthachatterjee Sep 16, 2019
770c06d
Update packages/gatsby-cli/src/reporter/index.js
sidharthachatterjee Sep 16, 2019
c5c3ce9
set default context to be empty object
pieh Sep 16, 2019
ff1eadc
structure file parsing errors
pieh Sep 16, 2019
774a983
ink(error): swap truthy check to typeof check for location
pieh Sep 16, 2019
edc6e44
cleanup commented out code and outdated comment
pieh Sep 17, 2019
b34efdb
fix snapshot
pieh Sep 17, 2019
993ad20
fix ACTIVITY_DURATION telemetry
pieh Sep 17, 2019
2320dbb
don't exit process in signalExit - it seems to interupt other signalE…
pieh Sep 18, 2019
db39d4d
fix telemetry duration for activity_duration and emit duration as num…
pieh Sep 18, 2019
3286bf2
Remove Version action
sidharthachatterjee Sep 24, 2019
d3219f6
Remove Promise.resolve
sidharthachatterjee Sep 24, 2019
65971c5
add todo tests that we need to write
pieh Sep 18, 2019
141b996
Clean up imports in api-runner-node
sidharthachatterjee Sep 24, 2019
1ed087b
Rename redux to redux manager
sidharthachatterjee Sep 24, 2019
ce980c5
Rename gatsby_logger to GATSBY_LOGGER
sidharthachatterjee Sep 24, 2019
2960d28
Add human readable status to CLI
sidharthachatterjee Sep 24, 2019
1d497d6
Fix bad import
sidharthachatterjee Sep 24, 2019
18ee8f5
Fix more bad imports
sidharthachatterjee Sep 24, 2019
a898633
Add panic function in activities
sidharthachatterjee Sep 24, 2019
c1ddcca
Merge branch 'master' into logs-to-redux
sidharthachatterjee Sep 24, 2019
92b7e7c
Fix more broken imports
sidharthachatterjee Sep 24, 2019
4e0a8c9
gatsby-telemetry: handle errorCode field change
pieh Sep 24, 2019
46f8a15
Revert "Rename redux to redux manager"
sidharthachatterjee Sep 25, 2019
13499ca
Revert "Fix bad import"
sidharthachatterjee Sep 25, 2019
8648f21
Revert "Fix more broken imports"
sidharthachatterjee Sep 25, 2019
6685b85
Fix broken imports yet again
sidharthachatterjee Sep 25, 2019
e25e37d
Don't emit Debug, Success and Log over IPC
sidharthachatterjee Sep 25, 2019
9f78e0d
Update tests for INFO override
sidharthachatterjee Sep 25, 2019
6973be2
Only override action level for IPC and not for dispatch
sidharthachatterjee Sep 25, 2019
6ef8f17
fix: restore internal query running APIs
pieh Sep 26, 2019
c9addbc
moar testing
sidharthachatterjee Sep 27, 2019
7b264c3
wip
sidharthachatterjee Oct 1, 2019
9224f52
Merge branch 'master' into logs-to-redux
sidharthachatterjee Oct 4, 2019
fa8fd18
Fix tests
sidharthachatterjee Oct 4, 2019
6cd1ea8
wip
sidharthachatterjee Oct 5, 2019
84a2c6a
more wip
sidharthachatterjee Oct 9, 2019
e155edb
more straight forward SET_STATUS debounce without extra abstractions
pieh Oct 9, 2019
b1f346d
fix SET_STATUS when exiting process
pieh Oct 9, 2019
a8d1921
comment out debugging code
sidharthachatterjee Oct 9, 2019
9b2f8c0
test: dont die on the inside
pieh Oct 9, 2019
629081d
remove that pesky git diff from editing index.js
sidharthachatterjee Oct 9, 2019
72e8529
Merge branch 'master' into logs-to-redux
sidharthachatterjee Oct 9, 2019
35c4ead
fix more tests
sidharthachatterjee Oct 9, 2019
b7f123d
interrupted status
sidharthachatterjee Oct 9, 2019
fb1713a
clean up
sidharthachatterjee Oct 9, 2019
9ff55af
show query results on page
pieh Oct 9, 2019
109c40a
add tests for preview workflows
pieh Oct 9, 2019
de12a3c
invalid code should actually be invalid
pieh Oct 9, 2019
8d033d9
Bump up event collection grace period to 5 seconds
sidharthachatterjee Oct 10, 2019
66a62a1
Bump up grace period for preview tests
sidharthachatterjee Oct 10, 2019
ac728d1
Apply suggestions from code review
pieh Oct 11, 2019
15ef36a
revert weird svg changes
pieh Oct 11, 2019
4014e46
Add comment for activity tests
sidharthachatterjee Oct 11, 2019
7b57f4a
Use switch over a series of if else because Ward says so
sidharthachatterjee Oct 11, 2019
fa629bc
Clean up constructError
sidharthachatterjee Oct 11, 2019
57c8a47
Add fallback UI for Ink and ensure telemetry works
sidharthachatterjee Oct 11, 2019
7692cc1
Skip problematic tests
sidharthachatterjee Oct 11, 2019
7655209
Update snapshots
sidharthachatterjee Oct 11, 2019
90c3647
Conditionally add code
sidharthachatterjee Oct 11, 2019
f1c8a70
Explain why we need to setStore in bootstrap
sidharthachatterjee Oct 11, 2019
a213d03
cleanup query-compiler
pieh Oct 11, 2019
8f6a5b5
info-ify logs only over ipc
pieh Oct 11, 2019
4713fa5
fix tests
pieh Oct 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .circleci/config.yml
Expand Up @@ -160,6 +160,12 @@ jobs:
- e2e-test:
test_path: integration-tests/gatsby-pipeline

integration_tests_structured_logging:
executor: node
steps:
- e2e-test:
test_path: integration-tests/structured-logging

e2e_tests_path-prefix:
<<: *e2e-executor
environment:
Expand Down Expand Up @@ -327,6 +333,8 @@ workflows:
<<: *e2e-test-workflow
- integration_tests_gatsby_pipeline:
<<: *e2e-test-workflow
- integration_tests_structured_logging:
<<: *e2e-test-workflow
- e2e_tests_path-prefix:
<<: *e2e-test-workflow
- e2e_tests_gatsby-image:
Expand Down
21 changes: 21 additions & 0 deletions integration-tests/structured-logging/LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 gatsbyjs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions integration-tests/structured-logging/README.md
@@ -0,0 +1,5 @@
# Structured Logging

## Problems

- Concurrent tests will need to generate a unique build folder name
172 changes: 172 additions & 0 deletions integration-tests/structured-logging/__tests__/logs.js
@@ -0,0 +1,172 @@
const { spawn } = require(`child_process`)
const path = require(`path`)

jest.setTimeout(100000)

const gatsbyBin = path.join(
`node_modules`,
`gatsby`,
`dist`,
`bin`,
`gatsby.js`
)

describe(`Activities`, () => {
let gatsbyProcess
let events = []

beforeAll(async done => {
gatsbyProcess = spawn(gatsbyBin, [`develop`], {
stdio: [`ignore`, `ignore`, `ignore`, `ipc`],
env: {
...process.env,
NODE_ENV: `development`,
ENABLE_GATSBY_REFRESH_ENDPOINT: true,
FAILING_ACTIVITY: true,
},
})

gatsbyProcess.on(`message`, msg => {
// console.log(msg)
events.push(msg)
// we are ready for tests
if (
msg.action &&
msg.action.type === `SET_STATUS` &&
msg.action.payload !== `IN_PROGRESS`
) {
done()
}
})
})

afterAll(async () => {
gatsbyProcess.kill()
})

it.todo(`emits actions with a timestamp`)

/* There are two typical lifecycles for activities. Most activities have
- Start
- Update (Optional)
- End

These tests assert whether events are correctly emitted for the complete lifecycle.
*/
it(`emit start, update and end events for a successful activity`, async () => {
const activityEvents = events.filter(
event =>
event.type === `LOG_ACTION` &&
event.action.payload.id === `Successful activity`
)

// console.log(util.inspect(activityEvents, { depth: null }))

const activityUuid = activityEvents[0].action.payload.uuid

expect(activityEvents).toEqual([
expect.objectContaining({
type: `LOG_ACTION`,
action: expect.objectContaining({
type: `ACTIVITY_START`,
payload: expect.objectContaining({
id: `Successful activity`,
uuid: activityUuid,
total: 100,
}),
}),
}),
expect.objectContaining({
type: `LOG_ACTION`,
action: expect.objectContaining({
type: `ACTIVITY_UPDATE`,
payload: expect.objectContaining({
id: `Successful activity`,
uuid: activityUuid,
current: 50,
}),
}),
}),
expect.objectContaining({
type: `LOG_ACTION`,
action: expect.objectContaining({
type: `ACTIVITY_END`,
payload: expect.objectContaining({
id: `Successful activity`,
uuid: activityUuid,
status: `SUCCESS`,
}),
}),
}),
])
})

it(`emit start, update and end events for a failed activity`, async () => {
const activityEvents = events.filter(
event =>
event.type === `LOG_ACTION` &&
event.action.payload.id === `Failing activity`
)

// console.log(util.inspect(activityEvents, { depth: null }))

const activityUuid = activityEvents[0].action.payload.uuid

expect(activityEvents).toEqual([
expect.objectContaining({
type: `LOG_ACTION`,
action: expect.objectContaining({
type: `ACTIVITY_START`,
payload: expect.objectContaining({
id: `Failing activity`,
uuid: activityUuid,
total: 100,
}),
}),
}),
expect.objectContaining({
type: `LOG_ACTION`,
action: expect.objectContaining({
type: `ACTIVITY_UPDATE`,
payload: expect.objectContaining({
id: `Failing activity`,
uuid: activityUuid,
current: 75,
}),
}),
}),
expect.objectContaining({
type: `LOG_ACTION`,
action: expect.objectContaining({
type: `ACTIVITY_END`,
payload: expect.objectContaining({
id: `Failing activity`,
uuid: activityUuid,
status: `FAILED`,
}),
}),
}),
])
})
;[`success`, `info`, `warn`, `log`, `error`].forEach(level => {
// success, info and log all emit `INFO`
const mapActionToLevel = {
success: `INFO`,
info: `INFO`,
warn: `WARNING`,
log: `INFO`,
error: `ERROR`,
}

it(`emits LOG_ACTION for ${level}`, async () => {
const event = events.find(
e =>
e.type === `LOG_ACTION` &&
e.action.type === `LOG` &&
mapActionToLevel[level] === e.action.payload.level &&
level === e.action.payload.text
)
expect(event).toBeDefined()
})
})
})
71 changes: 71 additions & 0 deletions integration-tests/structured-logging/__tests__/panic.js
@@ -0,0 +1,71 @@
const { spawn } = require(`child_process`)
const path = require(`path`)

jest.setTimeout(100000)

const gatsbyBin = path.join(
`node_modules`,
`gatsby`,
`dist`,
`bin`,
`gatsby.js`
)

describe(`Panic`, () => {
let gatsbyProcess
let events = []

beforeEach(async () => {
gatsbyProcess = spawn(gatsbyBin, [`build`], {
// inherit lets us see logs in console
// stdio: [`inherit`, `inherit`, `inherit`, `ipc`],
stdio: [`ignore`, `ignore`, `ignore`, `ipc`],
env: {
...process.env,
NODE_ENV: `production`,
ENABLE_GATSBY_REFRESH_ENDPOINT: true,
PANIC_ON_BUILD: true,
},
})

await new Promise(resolve => {
gatsbyProcess.on(`message`, msg => {
events.push(msg)
})

gatsbyProcess.on(`exit`, exitCode => {
resolve()
})
})
})

it(`emits SET_STATUS FAILURE`, async () => {
expect(events).toEqual(
expect.arrayContaining([
expect.objectContaining({
type: `LOG_ACTION`,
action: expect.objectContaining({
type: `SET_STATUS`,
payload: `FAILED`,
}),
}),
])
)
})
it(`emits LOG`, async () => {
expect(events).toEqual(
expect.arrayContaining([
expect.objectContaining({
type: `LOG_ACTION`,
action: expect.objectContaining({
type: `LOG`,
payload: expect.objectContaining({
level: `ERROR`,
text: `Your house is on fire`,
}),
}),
}),
])
)
})
})