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-cli): log what activities prevent from transitioning to idle when stuck #26618

Merged

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Aug 24, 2020

Description

This PR allows to run Gatsby with following env vars (you can use one of those or both or ... well none):

  • GATSBY_DIAGNOSTIC_STUCK_STATUS_TIMEOUT - to just log information when Gatsby is stuck in IN_PROGRESS
  • GATSBY_WATCHDOG_STUCK_STATUS_TIMEOUT - to terminate the process when stuck in IN_PROGRESS

Way it determines wether Gatsby is stuck is by (re)setting timer(s) on every log activity - it might mean log line, it might be tick() in progress bar, it might even be things not visible to users (setting activity as pending or using one of those hidden activities that are too fine grained to display in UI).

Few notes about usage:

  • when setting env var to a number (just any other than "1" - more about it in a sec) - it will try to use those numbers as timeout delay (but I did add, so at minimum it's 5s for diagnostic logs and 10s for termination)
  • when setting env var to truthy or "1" (which I reckon is quite popular way of "toggling" env vars), it will use some default timeouts (5 minutes for diagnostic logs and 10 minutes for termination).

In terminal results might look a little like this:

Both flags:
$ ENABLE_GATSBY_REFRESH_ENDPOINT=1 GATSBY_WATCHDOG_STUCK_STATUS_TIMEOUT=10000 GATSBY_DIAGNOSTIC_STUCK_STATUS_TIMEOUT=5000  gatsby develop

[...]

success write out requires - 0.001s
success run page queries - 0.010s - 1/1 102.49/s
warn This is just diagnostic information (enabled by GATSBY_DIAGNOSTIC_STUCK_STATUS_TIMEOUT):

Gatsby is in "IN_PROGRESS" state without any updates for 5.000 seconds. Activities preventing Gatsby from transitioning to idle state:

[
  {
    "id": "pending-but-not-really-running",
    "type": "pending",
    "startTime": [
      167025,
      903782122
    ],
    "status": "NOT_STARTED",
    "diagnostics_elapsed_seconds": "5.236"
  },
  {
    "id": "hidden one",
    "uuid": "eae76780-6d77-4685-aa0a-d8e959b53124",
    "text": "hidden one",
    "type": "hidden",
    "status": "IN_PROGRESS",
    "startTime": [
      167025,
      904008910
    ],
    "statusText": "",
    "diagnostics_elapsed_seconds": "5.236"
  }
]

Process will be terminated in 5.000 seconds if nothing will change.
warn This is just diagnostic information (enabled by GATSBY_DIAGNOSTIC_STUCK_STATUS_TIMEOUT):

There was activity since last diagnostic message. Log action:

{
  "type": "ACTIVITY_END",
  "payload": {
    "uuid": "eae76780-6d77-4685-aa0a-d8e959b53124",
    "id": "hidden one",
    "status": "SUCCESS",
    "duration": 7.51006542,
    "type": "hidden"
  },
  "timestamp": "2020-08-24T14:32:25.307Z"
}

Currently Gatsby is in: "IN_PROGRESS" state.

Activities preventing Gatsby from transitioning to idle state:

[
  {
    "id": "pending-but-not-really-running",
    "type": "pending",
    "startTime": [
      167025,
      903782122
    ],
    "status": "NOT_STARTED",
    "diagnostics_elapsed_seconds": "7.512"
  }
]
warn This is just diagnostic information (enabled by GATSBY_DIAGNOSTIC_STUCK_STATUS_TIMEOUT):

Gatsby is in "IN_PROGRESS" state without any updates for 5.000 seconds. Activities preventing Gatsby from transitioning to idle state:

[
  {
    "id": "pending-but-not-really-running",
    "type": "pending",
    "startTime": [
      167025,
      903782122
    ],
    "status": "NOT_STARTED",
    "diagnostics_elapsed_seconds": "12.515"
  }
]

Process will be terminated in 5.000 seconds if nothing will change.

 ERROR 

Terminating the process (due to GATSBY_WATCHDOG_STUCK_STATUS_TIMEOUT):

Gatsby is in "IN_PROGRESS" state without any updates for 10.000 seconds. Activities preventing Gatsby from transitioning to idle state:

[
  {
    "id": "pending-but-not-really-running",
    "type": "pending",
    "startTime": [
      167025,
      903782122
    ],
    "status": "NOT_STARTED",
    "diagnostics_elapsed_seconds": "17.516"
  }
]
Just `GATSBY_DIAGNOSTIC_STUCK_STATUS_TIMEOUT`:
$ ENABLE_GATSBY_REFRESH_ENDPOINT=1 GATSBY_DIAGNOSTIC_STUCK_STATUS_TIMEOUT=5000  gatsby develop

[...]

success write out requires - 0.001s
success run page queries - 0.010s - 1/1 103.75/s
warn This is just diagnostic information (enabled by GATSBY_DIAGNOSTIC_STUCK_STATUS_TIMEOUT):

Gatsby is in "IN_PROGRESS" state without any updates for 5.000 seconds. Activities preventing Gatsby from transitioning to idle state:

[
  {
    "id": "pending-but-not-really-running",
    "type": "pending",
    "startTime": [
      167090,
      531910219
    ],
    "status": "NOT_STARTED",
    "diagnostics_elapsed_seconds": "5.249"
  },
  {
    "id": "hidden one",
    "uuid": "8e952af8-dd37-418a-9b99-55fd49c331db",
    "text": "hidden one",
    "type": "hidden",
    "status": "IN_PROGRESS",
    "startTime": [
      167090,
      532129975
    ],
    "statusText": "",
    "diagnostics_elapsed_seconds": "5.249"
  }
]
warn This is just diagnostic information (enabled by GATSBY_DIAGNOSTIC_STUCK_STATUS_TIMEOUT):

There was activity since last diagnostic message. Log action:

{
  "type": "ACTIVITY_END",
  "payload": {
    "uuid": "8e952af8-dd37-418a-9b99-55fd49c331db",
    "id": "hidden one",
    "status": "SUCCESS",
    "duration": 7.506380937,
    "type": "hidden"
  },
  "timestamp": "2020-08-24T14:33:29.933Z"
}

Currently Gatsby is in: "IN_PROGRESS" state.

Activities preventing Gatsby from transitioning to idle state:

[
  {
    "id": "pending-but-not-really-running",
    "type": "pending",
    "startTime": [
      167090,
      531910219
    ],
    "status": "NOT_STARTED",
    "diagnostics_elapsed_seconds": "7.507"
  }
]
warn This is just diagnostic information (enabled by GATSBY_DIAGNOSTIC_STUCK_STATUS_TIMEOUT):

Gatsby is in "IN_PROGRESS" state without any updates for 5.000 seconds. Activities preventing Gatsby from transitioning to idle state:

[
  {
    "id": "pending-but-not-really-running",
    "type": "pending",
    "startTime": [
      167090,
      531910219
    ],
    "status": "NOT_STARTED",
    "diagnostics_elapsed_seconds": "12.508"
  }
]
Just `GATSBY_WATCHDOG_STUCK_STATUS_TIMEOUT`:
$ ENABLE_GATSBY_REFRESH_ENDPOINT=1 GATSBY_WATCHDOG_STUCK_STATUS_TIMEOUT=10000  gatsby develop

[...]

success write out requires - 0.002s
success run page queries - 0.010s - 1/1 101.11/s

 ERROR 

Terminating the process (due to GATSBY_WATCHDOG_STUCK_STATUS_TIMEOUT):

Gatsby is in "IN_PROGRESS" state without any updates for 10.000 seconds. Activities preventing Gatsby from transitioning to idle state:

[
  {
    "id": "pending-but-not-really-running",
    "type": "pending",
    "startTime": [
      167245,
      698002618
    ],
    "status": "NOT_STARTED",
    "diagnostics_elapsed_seconds": "17.517"
  }
]

[ch14090]

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Aug 24, 2020
@pieh pieh removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Aug 24, 2020
@gatsby-cloud
Copy link

gatsby-cloud bot commented Aug 24, 2020

Gatsby Cloud Build Report

using-styled-components

🎉 Your build was successful! See the Deploy preview here.

Build Details

View the build logs here.

🕐 Build time: 12s

Performance

Lighthouse report

Metric Score
Performance 💚 100
Accessibility 💚 90
Best Practices 💚 100
SEO 💚 90

🔗 View full report

@gatsby-cloud
Copy link

gatsby-cloud bot commented Aug 24, 2020

Gatsby Cloud Build Report

client-only-paths

🎉 Your build was successful! See the Deploy preview here.

Build Details

View the build logs here.

🕐 Build time: 12s

Performance

Lighthouse report

Metric Score
Performance 💚 100
Accessibility 🔶 85
Best Practices 💚 100
SEO 🔶 70

🔗 View full report

@gatsby-cloud
Copy link

gatsby-cloud bot commented Aug 24, 2020

Gatsby Cloud Build Report

using-reach-skip-nav

🎉 Your build was successful! See the Deploy preview here.

Build Details

View the build logs here.

🕐 Build time: 12s

Performance

Lighthouse report

Metric Score
Performance 💚 100
Accessibility 💚 100
Best Practices 💚 100
SEO 🔶 82

🔗 View full report

@gatsby-cloud
Copy link

gatsby-cloud bot commented Aug 24, 2020

Gatsby Cloud Build Report

gatsby

🎉 Your build was successful! See the Deploy preview here.

Build Details

View the build logs here.

🕐 Build time: 8m

@pieh pieh marked this pull request as ready for review August 25, 2020 07:26
Copy link
Contributor

@vladar vladar left a comment

Choose a reason for hiding this comment

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

Can we have it as Redux middleware? It sounds like a good fit for something like this?

@pieh
Copy link
Contributor Author

pieh commented Aug 25, 2020

Can we have it as Redux middleware? It sounds like a good fit for something like this?

It kind of is in the "middleware" - all structured logs related actions go through it (but also worth mentioning that this is resetting timer only on structured logging actions).

It's just it's not using builtin redux middleware API because logic there for the most part only relates to logging (deciding whether to forward action to ipc) and it supports changing the target store instance (it always starts with store that is local to gatsby-cli, but can swap to gatsby store).

By using redux middleware did you mean to use proper middleware API or that it should reset timer on any action (doesn't have to be structured logging one)? Or both?

@vladar
Copy link
Contributor

vladar commented Aug 25, 2020

Oh, right, I forgot about swapping stores thing. Discard my previous comment.

pvdz
pvdz previously approved these changes Aug 25, 2020
Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

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

No major problems but some things to double check.

packages/gatsby-cli/src/reporter/redux/index.ts Outdated Show resolved Hide resolved
packages/gatsby-cli/src/reporter/redux/index.ts Outdated Show resolved Hide resolved
packages/gatsby-cli/src/reporter/redux/index.ts Outdated Show resolved Hide resolved
packages/gatsby-cli/src/reporter/redux/index.ts Outdated Show resolved Hide resolved
packages/gatsby-cli/src/reporter/redux/index.ts Outdated Show resolved Hide resolved
packages/gatsby-cli/src/reporter/redux/index.ts Outdated Show resolved Hide resolved
@@ -46,6 +117,95 @@ export const dispatch = (action: ActionsUnion | Thunk): void => {

store.dispatch(action)

// ignore diagnostic logs, otherwise diagnostic message itself will reset
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand what this block is doing. It seems to be quite verbose in terms of code for what it's doing (debouncing a "stuck" warning). Can it be abstracted a little bit into a global function? Closures may make that more difficult.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved almost all diagnostics related code to its own file/module (other than calls to init and calling handler in our custom dispatch function). I didn't do much changes otherwise - while there are similarities in 2 timers that I add they are different enough that I'm not sure if there's much value in trying to DRY it too much)

Co-authored-by: Peter van der Zee <209817+pvdz@users.noreply.github.com>

// yuck, we have situation of circular dependencies here
// so this is `reporter` import is delayed until it's actually needed
const { reporter } = require(`../reporter`)
Copy link
Contributor

Choose a reason for hiding this comment

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

🤕

@sidharthachatterjee
Copy link
Contributor

@pieh Is this a noop when those env vars are not set or do they have defaults?

@pieh
Copy link
Contributor Author

pieh commented Aug 25, 2020

@pieh Is this a noop when those env vars are not set or do they have defaults?

They don't have defaults so it is (more or less) no-op when env vars are not set.

@pieh pieh merged commit b88f193 into master Aug 26, 2020
@delete-merged-branch delete-merged-branch bot deleted the log-what-activities-prevent-from-transitioning-to-idle-when-stuck branch August 26, 2020 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants