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

Pagespeed always returns the same score results for each site #1

Open
nheape opened this issue Jan 15, 2020 · 7 comments
Open

Pagespeed always returns the same score results for each site #1

nheape opened this issue Jan 15, 2020 · 7 comments

Comments

@nheape
Copy link

nheape commented Jan 15, 2020

Hi, thanks for developing this and hopefully it's still something you keep an eye on.

I've been employing the pagespeed-for-slackers Lambda as a Cloudwatch Rule taking custom json. Once I've tested any given URL with the Lambda, it shows the same scores in Slack every time I invoke the Lambda.

e.g. custom / test JSON

{ "url": "http://www.uber.com" }

First test - Google PageSpeed score (desktop): 83, Google PageSpeed score (mobile): 67

All subsequent tests - Google PageSpeed score (desktop): 83, Google PageSpeed score (mobile): 67

I can reproduce this with any url.

Of note, only the header line seems to be the exact same. The Total Resources, otherResponseBytes, etc, all may differ.

@jonknapp
Copy link
Member

Hey, glad this was of some use to someone! I haven't looked at it in awhile to be honest....

That said, I'm not doing any specific caching in the code, so unless a library that is being used is buggy (or the request it makes to Page Speed is being cached) I'm not sure how to help.

The dependencies are a bit out of date in this repo at this point. I would imagine that bumping things to latest versions may potentially fix the issue. Have you attempted to update the psi library to see if it makes a difference?

@nheape
Copy link
Author

nheape commented Jan 16, 2020

Thanks for the response and the idea! I've tried updating psi and I'm getting this error - looks like they may have broken something with the new version of psi.

{ "errorType": "TypeError", "errorMessage": "Cannot read property 'pagespeedonline' of undefined", "trace": [ "TypeError: Cannot read property 'pagespeedonline' of undefined", " at Object.<anonymous> (/var/task/node_modules/psi/index.js:7:36)", " at Module._compile (internal/modules/cjs/loader.js:956:30)", " at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)", " at Module.load (internal/modules/cjs/loader.js:812:32)", " at Function.Module._load (internal/modules/cjs/loader.js:724:14)", " at Module.require (internal/modules/cjs/loader.js:849:19)", " at require (internal/modules/cjs/helpers.js:74:18)", " at Object.<anonymous> (/var/task/index.js:4:29)", " at Module._compile (internal/modules/cjs/loader.js:956:30)", " at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)", " at Module.load (internal/modules/cjs/loader.js:812:32)", " at Function.Module._load (internal/modules/cjs/loader.js:724:14)", " at Module.require (internal/modules/cjs/loader.js:849:19)", " at require (internal/modules/cjs/helpers.js:74:18)", " at _tryRequire (/var/runtime/UserFunction.js:75:12)", " at _loadUserApp (/var/runtime/UserFunction.js:95:12)" ] }

@jonknapp
Copy link
Member

I took a pass at cleaning things up dependency wise, but the data structure is different in the latest version of the page speed API. Could you take a look at the open PR and possibly finish it up? I'm not really sure what the results send back to Slack should look like but I linked to the API docs in the PR.

You should be able to run node test.js locally to test fetching API results while testing the code. No need to deploy it to Lambda first. Let me know if you have any questions.

@nheape
Copy link
Author

nheape commented Feb 5, 2020

I've spent some time looking at this, but I'm more Ops than Dev and I'm unfortunately at a loss. Could you elaborate a bit on what needs to happen here? Attempting to run test.js currently gives the following error:

Loading function
Lambda event data:
{
  "url": "http://example.com"
}
(node:1925) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at pageStatFields (/Users/nheape/git/pagespeed-for-slackers/index.js:70:17)
    at createAttachment (/Users/nheape/git/pagespeed-for-slackers/index.js:40:13)
    at /Users/nheape/git/pagespeed-for-slackers/index.js:122:18
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Promise.all (index 0)
(node:1925) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1925) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.```

@jonknapp
Copy link
Member

jonknapp commented Feb 5, 2020

No problem at all, we'll get this working :)

What version of node are you using? node -v

@nheape
Copy link
Author

nheape commented Feb 5, 2020

v13.1.0

@jonknapp
Copy link
Member

jonknapp commented Feb 5, 2020

Ok, sorry about the mixup. There was no code in the page-speed-v5 branch to show you what the PageSpeed API returned. I pushed one more commit to the branch to console.log the data that the createAttachment method receives.

The part that needs completed is matching that API response (data) to an object that Slack will use to post to their own API.

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

No branches or pull requests

2 participants