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

No-Jira - Implement LighthouseCI #908

Merged
merged 13 commits into from
May 3, 2024
Merged

No-Jira - Implement LighthouseCI #908

merged 13 commits into from
May 3, 2024

Conversation

wrandall22
Copy link
Contributor

@wrandall22 wrandall22 commented Apr 8, 2024

Description

Please explain a bullet-point summary of the changes.
List any PRs that this PR is dependent on and any Jira tickets that this PR is related to.

Checklist:

  • I have given my PR a title with the format "MPDX-(JIRA#) (summary sentence max 80 chars)"
  • I have applied the appropriate labels. (Add the label "On Staging" to get the branch automatically merged into staging.)
  • I have requested a review from another person on the project

@wrandall22 wrandall22 requested review from canac and dr-bizz April 8, 2024 14:29

This comment was marked as outdated.

@wrandall22
Copy link
Contributor Author

wrandall22 commented Apr 8, 2024

Hurdles to overcome:

  • localhost:3000 is not the right url for GHA. Do we use the amplify preview environment somehow instead?
  • The sub-urls for contacts pages don't seem to work out (flows, map) just by going to those URLs, we may not be able to capture them unless we change how that works

@wrandall22 wrandall22 marked this pull request as draft April 8, 2024 14:54
@wrandall22 wrandall22 force-pushed the lighthouse-redone branch 2 times, most recently from 99a5d31 to dd50d81 Compare April 8, 2024 15:54
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-908.d3dytjb8adxkk5.amplifyapp.com

.github/workflows/ci.yml Outdated Show resolved Hide resolved
@dr-bizz
Copy link
Contributor

dr-bizz commented Apr 8, 2024

localhost:3000 is not the right url for GHA. Do we use the amplify preview environment somehow instead?
We want to use the preview environment variable. We know what it is by https://${AWS_BRANCH_ARN#*/branches/}.${AWS_APP_ID}.amplifyapp.com. AWS_BRANCH_ARN is typically always the pr number pr-908 & AWS_APP_ID will stay the same.

The sub-urls for contacts pages don't seem to work out (flows, map) just by going to those URLs, we may not be able to capture them unless we change how that works

I think we can leave the flows & map pages for now.

@dr-bizz
Copy link
Contributor

dr-bizz commented Apr 8, 2024

What account login are we using? I created an account for DataDog, I don't know if we want to use the same one or a different one. Whatever the account, it should have at least 100 contacts and tasks to reflect load times for normal users

@wrandall22
Copy link
Contributor Author

Right now it is the test account (apps+mpdx@cru.org)

Copy link
Contributor

@canac canac left a comment

Choose a reason for hiding this comment

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

This is looking great! Thanks for adding it!

Is there an action that will compare the results from main with the results from the current PR to make it easy to see performance improvements and regressions (kind of like the bundle analyzer action does)? Also, would it be possible to add the core web vitals to the logging in addition to the scores in each of the categories?

lighthouse-auth.js Outdated Show resolved Hide resolved
@wrandall22
Copy link
Contributor Author

I haven't found an existing action to do the comparison, I think we'd have to set up Lighhouse server to make that work (comparing current PR results to the server results), which would take some buy in and cost with spinning up a server.

I'll look into the core web vitals piece. I'm also seeing how hard it would be to post the logs here as a comment.

@canac
Copy link
Contributor

canac commented Apr 10, 2024

The bundle analyzer action does it by storing a GHA artifact whenever it runs on main. My understanding is that artifacts are arbitrary data created by a workflow run that is linked to a specific commit or branch. Then the workflow can lookup that artifact and compare the current run with the saved result of the run on main. But that's probably not worth the effort for us to implement if an action for it doesn't exist already. We can always just look at the latest core vitals averages in DataDog.

@wrandall22
Copy link
Contributor Author

I'm finding that the console log does not match the report summary. If I had to guess, I'd say the console log is probably the last of the 3 runs and the report is the combined median.

@dr-bizz
Copy link
Contributor

dr-bizz commented Apr 11, 2024

If comparing it to the main doesn't work, maybe we could try adding jest tests like on the below medium post. https://medium.com/front-end-weekly/run-lighthouse-performance-audits-on-every-pull-request-6907645d2005

I know we want to hit the PR preview URL, which probably will not work with this, but I thought it was worth sharing in case something is useful.

@wrandall22
Copy link
Contributor Author

The GHA itself can do the assertions, but I don't think we're ready for that yet. I'm playing around with the artifact stuff now. The other thing about hitting the preview URL is that, unless we have a way of waiting on the preview job completing, the performance analyzer will fail the first time on every PR.

Copy link
Contributor

Bundle Sizes

Compared against c0034cc

Route: No significant changes found

Dynamic import: None found.

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

@wrandall22
Copy link
Contributor Author

wrandall22 commented Apr 12, 2024

Remaining issues:

  • This will not work when actions run on the main and staging branches as-is since there are no previews there. I need to tweak the serverUrl so that main will hit production and staging will hit the staging site.
  • It would still be nice to handle a comparison to main at some point (though this PR could be merged before that)
  • An improvement for the future that would be nice is to create a separate bot for comments so that we can override previous comments (or I could write code for this like the bundle analyzer did)

Copy link
Contributor

github-actions bot commented Apr 12, 2024

Scores
  • Overall Scores: 0.63, 0.98, 0.96, 1, 1
  • Largest Contentful Paint: 4.2 s
  • Cumulative Layout Shift: 0.029
Scores
  • Overall Scores: 0.42, 0.86, 0.96, 1, 1
  • Largest Contentful Paint: 6.1 s
  • Cumulative Layout Shift: 0
Scores
  • Overall Scores: 0.37, 0.84, 0.96, 1, 1
  • Largest Contentful Paint: 7.2 s
  • Cumulative Layout Shift: 0.019
Scores
  • Overall Scores: 0.14, 0.85, 0.96, 1, 1
  • Largest Contentful Paint: 7.1 s
  • Cumulative Layout Shift: 1.467
Scores
  • Overall Scores: 0.45, 0.74, 0.96, 1, 1
  • Largest Contentful Paint: 6.6 s
  • Cumulative Layout Shift: 0.021
Scores
  • Overall Scores: 0.48, 0.93, 0.96, 1, 1
  • Largest Contentful Paint: 5.3 s
  • Cumulative Layout Shift: 0

https://lighthouse-redone.d3dytjb8adxkk5.amplifyapp.com/accountLists/5721eaaf-4596-4412-ae68-ccdd291b804d/reports/partnerCurrency

Scores
  • Overall Scores: 0.74, 0.94, 0.96, 0.92, 1
  • Largest Contentful Paint: 1.2 s
  • Cumulative Layout Shift: 0.006

https://lighthouse-redone.d3dytjb8adxkk5.amplifyapp.com/accountLists/5721eaaf-4596-4412-ae68-ccdd291b804d/reports/salaryCurrency

Scores
  • Overall Scores: 0.74, 0.94, 0.96, 0.92, 1
  • Largest Contentful Paint: 1.2 s
  • Cumulative Layout Shift: 0.006

https://lighthouse-redone.d3dytjb8adxkk5.amplifyapp.com/accountLists/5721eaaf-4596-4412-ae68-ccdd291b804d/reports/designationAccounts

Scores
  • Overall Scores: , 0.81, , 1, 1
  • Largest Contentful Paint: undefined
  • Cumulative Layout Shift: undefined

https://lighthouse-redone.d3dytjb8adxkk5.amplifyapp.com/accountLists/5721eaaf-4596-4412-ae68-ccdd291b804d/reports/partnerGivingAnalysis

Scores
  • Overall Scores: 0.7, 0.9, 0.96, 1, 1
  • Largest Contentful Paint: 1.2 s
  • Cumulative Layout Shift: 0.007
Scores
  • Overall Scores: 0.58, 0.85, 0.96, 1, 1
  • Largest Contentful Paint: 4.3 s
  • Cumulative Layout Shift: 0.053

@wrandall22
Copy link
Contributor Author

After pulling in the latest main, I'm getting these errors in the lighthouse browser console:

Screenshot 2024-04-12 at 1 33 55 PM

Copy link
Contributor

github-actions bot commented Apr 12, 2024

Bundle sizes [mpdx-react]

Compared against e75367d

No significant changes found

@wrandall22 wrandall22 force-pushed the lighthouse-redone branch 3 times, most recently from 45832b5 to 5d82678 Compare April 29, 2024 15:17
@wrandall22
Copy link
Contributor Author

run lighthouse

@wrandall22
Copy link
Contributor Author

Comment-driven won't work until this is merged to main.

@wrandall22 wrandall22 requested a review from canac April 30, 2024 13:04
}

return await new Promise((resolve) => {
const initialLoadId = setInterval(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't wait for the initial load, which is great. However, it appears that for retries it will load the page, wait one minute, then check the status, introducing an unnecessary delay.

Copy link
Contributor Author

@wrandall22 wrandall22 Apr 30, 2024

Choose a reason for hiding this comment

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

My understanding is that, if the first load does not succeed, it will then wait 60 seconds, check the status again (which won't have changed) and then reload the page, and keep doing that loop until it finds it. I guess this will mean that we aren't checking the status again right after the next load, which is the unnecessary delay you mention. Perhaps we should also introduce a limit of retries.

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 it could be simplified a little, but the logic looks great now!

Copy link
Contributor

@canac canac left a comment

Choose a reason for hiding this comment

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

I'm going to go ahead and approve since my feedback was minor.

Comment on lines 66 to 69
if (pageFound(originResponse)) {
resolve(originResponse);
clearInterval(initialLoadId);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

This branch isn't needed anymore, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is needed because otherwise it never re-queries the page.

}
}

export async function loadInitialPage(page, origin, timeout = 60_000) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Uggh, this waiting approach of waiting on the status code to not be 404 probably won't work. I just made a PR with a preview environment, and while the first build is building, the response to any page is 200 with the following body:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Welcome</title>
    <style>
        body {
            background-color: #d5dbdb;
            margin: 5em 5em 5em 5em;
            font-family: "Amazon Ember", Helvetica, Arial, sans-serif;
        }

        div {
            background-color: #ffffff;
            padding: 1em 2em 2em 2em;
        }

        h1 {
            color: #16191f;
        }

        h3 {
            color: #16191f;
        }
    </style>
</head>
<body>
<div>
    <h1>Welcome</h1>
    <h3>Your app will appear here once you complete your first deployment.</h3>
    <p>
        Deployment didn't work? Here are some options:
        <ul>
            <li>Check out <b><a href="https://docs.aws.amazon.com/amplify/latest/userguide/welcome.html">our docs</a></b></li>
            <li>Click the <b>Feedback</b> button in the bottom-left corner of the service page</li>
        </ul>
    </p>
    <p>
        Quick tips:
        <ul>
            <li>Have you checked your build settings? The <b>baseDirectory</b> parameter in the 
                <b>artifacts</b> step of your YAML file should match your build output directory</li>
            <li>Building your app should produce an <b>index.html</b> file. Try building your app 
                locally and check a file with that name exists in the artifacts base directory.</li>
        </ul>
        </p>
</div>
</body>
</html>

We may have to make this method try again if the page content contains Your app will appear here once you complete your first deployment. and hope Amplify doesn't change that placeholder page's content.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or we could cycle wait on something on all of our pages, if such a thing exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like I could look for <div id="__next"> which seems to be consistent.

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've made a commit to this effect, let me know what you think.

Copy link
Contributor

@canac canac left a comment

Choose a reason for hiding this comment

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

I like the idea of using the built-in timeout to wait before trying again!

lighthouse/lighthouse-auth.mjs Outdated Show resolved Hide resolved
lighthouse/lighthouse-auth.test.ts Outdated Show resolved Hide resolved
lighthouse/lighthouse-auth.test.ts Outdated Show resolved Hide resolved
lighthouse/lighthouse-auth.test.ts Outdated Show resolved Hide resolved
wrandall22 added 13 commits May 2, 2024 15:00
…pt where it was always going to the same URL for at least the logged outputs, so I fixed that while I was in there.
… url. This involved separating out the auth logic to a separate file that can use ES Modules, which was a bit tricky to figure out.
…vironment comes up with a basic landing page so the prior method will not come back with a 404. Instead, we can check for a common div on all of the MPDx pages and move forward after it is up. Preview environments can take up to 13 minutes to deploy
@wrandall22 wrandall22 force-pushed the lighthouse-redone branch from a47d8a5 to 5c163d8 Compare May 2, 2024 19:25
@wrandall22 wrandall22 merged commit 6e336f7 into main May 3, 2024
18 checks passed
@wrandall22 wrandall22 deleted the lighthouse-redone branch May 3, 2024 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Preview Environment Add this label to create an Amplify Preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants