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

Improve performance by caching Filament components and warn if APP_KEY is missing #19

Merged
merged 8 commits into from
Jun 7, 2024

Conversation

alexjustesen
Copy link
Contributor

linuxserver.io


  • I have read the contributing guideline and understand that I have made the correct modifications

Description:

This PR improves performance by caching Filament components during startup and will now warn a user if an APP_KEY is not present and how to generate one.

Benefits of this PR and context:

Improving performance by caching views and documentation by guiding user setup.

How Has This Been Tested?

Same startup process for caching I'm using in app:install command for development.

Source / References:

https://github.com/alexjustesen/speedtest-tracker/blob/ce697bd9aae51227130ef97d2ec80647a3a6e134/app/Console/Commands/InstallCommand.php#L41-L43

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thanks for opening this pull request! Be sure to follow the pull request template!

@LinuxServer-CI
Copy link
Contributor

I am a bot, here are the test results for this PR:
https://ci-tests.linuxserver.io/lspipepr/speedtest-tracker/v0.19.0-pkg-9bbcbbb7-dev-2fb2a4dd0cc890d2ebc2d11b49786b7da5969e22-pr-19/index.html
https://ci-tests.linuxserver.io/lspipepr/speedtest-tracker/v0.19.0-pkg-9bbcbbb7-dev-2fb2a4dd0cc890d2ebc2d11b49786b7da5969e22-pr-19/shellcheck-result.xml

Tag Passed
amd64-v0.19.0-pkg-9bbcbbb7-dev-2fb2a4dd0cc890d2ebc2d11b49786b7da5969e22-pr-19
arm64v8-v0.19.0-pkg-9bbcbbb7-dev-2fb2a4dd0cc890d2ebc2d11b49786b7da5969e22-pr-19

@thespad
Copy link
Member

thespad commented Jun 7, 2024

If we're going to make that change then you also need to update the readme-vars to move the APP_KEY env from optional to mandatory and add a note to the changelog so we've got an easy record of when the change was made.

@alexjustesen
Copy link
Contributor Author

alexjustesen commented Jun 7, 2024

On it, @thespad just to confirm you'll want readme.md and readme-vars.yml updated?

@thespad
Copy link
Member

thespad commented Jun 7, 2024

Just the readme-vars, the actual readme.md is templated at build time.

@alexjustesen
Copy link
Contributor Author

@thespad pushed the updates, let me know if you need anything else

@LinuxServer-CI
Copy link
Contributor

I am a bot, here are the test results for this PR:
https://ci-tests.linuxserver.io/lspipepr/speedtest-tracker/v0.20.0-pkg-04a48603-dev-042b5d6670b2b14d69055d0c1cf95577d49a019c-pr-19/index.html
https://ci-tests.linuxserver.io/lspipepr/speedtest-tracker/v0.20.0-pkg-04a48603-dev-042b5d6670b2b14d69055d0c1cf95577d49a019c-pr-19/shellcheck-result.xml

Tag Passed
amd64-v0.20.0-pkg-04a48603-dev-042b5d6670b2b14d69055d0c1cf95577d49a019c-pr-19
arm64v8-v0.20.0-pkg-04a48603-dev-042b5d6670b2b14d69055d0c1cf95577d49a019c-pr-19

@thespad
Copy link
Member

thespad commented Jun 7, 2024

So based on my testing of 0.20, DISPLAY_TIMEZONE now seems to be mandatory too (not sure if that's intentional or not, but I'm getting

[2024-06-07 12:48:03] production.ERROR: Carbon\Carbon::timezone(): Argument #1 ($value) must be of type DateTimeZone|string|int, null given, called in /app/www/app/Filament/Widgets/RecentUploadLatencyChartWidget.php on line 83 {"userId":1,"exception":"[object] (TypeError(code: 0): Carbon\\Carbon::timezone(): Argument #1 ($value) must be of type DateTimeZone|string|int, null given, called in /app/www/app/Filament/Widgets/RecentUploadLatencyChartWidget.php on line 83 at /app/www/vendor/nesbot/carbon/src/Carbon/Traits/Date.php:1831)

Without it set. We can set it to a UTC default in the Dockerfiles if that's easier.

Also your example settings for SPEEDTEST_SCHEDULE and SPEEDTEST_SERVERS should either be

      - SPEEDTEST_SCHEDULE=47 */6 * * *
      - SPEEDTEST_SERVERS=60700,51643,57802,22971

or

      - "SPEEDTEST_SCHEDULE=47 */6 * * *"
      - "SPEEDTEST_SERVERS=60700,51643,57802,22971"

or even

      SPEEDTEST_SCHEDULE: 47 */6 * * *
      SPEEDTEST_SERVERS: 60700,51643,57802,22971

but not

      - SPEEDTEST_SCHEDULE="47 */6 * * *"
      - SPEEDTEST_SERVERS="60700,51643,57802,22971"

As that will include the quotes as part of the env (unless you have code in place to handle that internally).

@thespad
Copy link
Member

thespad commented Jun 7, 2024

Oh, also you might want to change Get a key at to You can generate a key at so that people don't read it as implying some kind of license key situation.

@alexjustesen
Copy link
Contributor Author

Oh, also you might want to change Get a key at to You can generate a key at so that people don't read it as implying some kind of license key situation.

Good catch, it does sound like one is required.

I should be defaulting to UTC in the application instead of null so this PR alexjustesen/speedtest-tracker#1471 fixes that and will be in v0.20.1 that I'll release in a few.

Also examples have been updated, thanks for the suggestion. I wrote them looking at my .env file locally.

@LinuxServer-CI
Copy link
Contributor

I am a bot, here are the test results for this PR:
https://ci-tests.linuxserver.io/lspipepr/speedtest-tracker/v0.20.0-pkg-04a48603-dev-743efc9f23362d3b5134a90c1141f74b10e2c1a2-pr-19/index.html
https://ci-tests.linuxserver.io/lspipepr/speedtest-tracker/v0.20.0-pkg-04a48603-dev-743efc9f23362d3b5134a90c1141f74b10e2c1a2-pr-19/shellcheck-result.xml

Tag Passed
amd64-v0.20.0-pkg-04a48603-dev-743efc9f23362d3b5134a90c1141f74b10e2c1a2-pr-19
arm64v8-v0.20.0-pkg-04a48603-dev-743efc9f23362d3b5134a90c1141f74b10e2c1a2-pr-19

@thespad
Copy link
Member

thespad commented Jun 7, 2024

Seeing cp: cannot stat '/app/www/.env.production': No such file or directory in the startup, is that file no longer there?

Should we be copying env.example instead?

Edit: here https://github.com/linuxserver/docker-speedtest-tracker/blob/main/root/etc/s6-overlay/s6-rc.d/init-speedtest-tracker-config/run#L65-L68

@alexjustesen
Copy link
Contributor Author

Seeing cp: cannot stat '/app/www/.env.production': No such file or directory in the startup, is that file no longer there?

Should we be copying env.example instead?

Edit: here https://github.com/linuxserver/docker-speedtest-tracker/blob/main/root/etc/s6-overlay/s6-rc.d/init-speedtest-tracker-config/run#L65-L68

I'm no longer using .env in the file system for environment variables and instead want people to set those in their Docker Docker Compose files.

I can remove this copy statement in a few unless I'm missing an issue this would cause. I do believe I have coverage across vars with APP_KEY being required.

@thespad
Copy link
Member

thespad commented Jun 7, 2024

You need to also change this if block

if ! grep -E "APP_KEY=[0-9A-Za-z:+\/=]{1,}" /app/www/.env > /dev/null; then

Probably to something like

if ! grep -qE "APP_KEY=[0-9A-Za-z:+\/=]{1,}" /app/www/.env 2> /dev/null; then

So that it will handle people who already have an APP_KEY set in their .env file but won't error if there isn't one at all.

@alexjustesen
Copy link
Contributor Author

I also moved creating the symlink to only if an .env file exists, thinking this might make better sense for backwards compatibility.

@LinuxServer-CI
Copy link
Contributor

I am a bot, here are the test results for this PR:
https://ci-tests.linuxserver.io/lspipepr/speedtest-tracker/v0.20.0-pkg-04a48603-dev-435ccf1af141dbff76a73d22630320fffd9e7dbf-pr-19/index.html
https://ci-tests.linuxserver.io/lspipepr/speedtest-tracker/v0.20.0-pkg-04a48603-dev-435ccf1af141dbff76a73d22630320fffd9e7dbf-pr-19/shellcheck-result.xml

Tag Passed
amd64-v0.20.0-pkg-04a48603-dev-435ccf1af141dbff76a73d22630320fffd9e7dbf-pr-19
arm64v8-v0.20.0-pkg-04a48603-dev-435ccf1af141dbff76a73d22630320fffd9e7dbf-pr-19

@thespad
Copy link
Member

thespad commented Jun 7, 2024

I think we need to do a sleep infinity if no APP_KEY is found otherwise it'll appear to start OK but just 500 error and not be clear why unless users dig into the logs.

@thespad
Copy link
Member

thespad commented Jun 7, 2024

Realised it was quicker just to do those bits myself - added an app_key to the CI envs so it boots correctly for the CI tests.

@thespad
Copy link
Member

thespad commented Jun 7, 2024

Though obviously that's still going to fail right now because of the DISPLAY_TIMEZONE bug.

@alexjustesen
Copy link
Contributor Author

alexjustesen commented Jun 7, 2024

Cool thank you, I've been trying to respond between meetings this morning.

v0.21.1 fixes the DISPLAY_TIMEZONE bug

@thespad
Copy link
Member

thespad commented Jun 7, 2024

Oh, I forgot to ask, what's the behaviour for an existing user updating to 0.20 who doesn't set SPEEDTEST_SCHEDULE or SPEEDTEST_SERVERS?

@alexjustesen
Copy link
Contributor Author

Their scheduled tests will stop until they get those options setup.

@thespad
Copy link
Member

thespad commented Jun 7, 2024

In that case I'd suggest some kind of UI indication that there's no schedule and/or server selection or we're going to get a bunch of users who don't understand why their installs have stopped working.

@thespad
Copy link
Member

thespad commented Jun 7, 2024

Oh and don't worry about the CI tests failing all of a sudden, I forgot that external PRs don't use the generated Jenkinsfile for security reasons, so the sleep is taking effect and not the APP_KEY env, but it'll be fine once merged.

@alexjustesen
Copy link
Contributor Author

In that case I'd suggest some kind of UI indication that there's no schedule and/or server selection or we're going to get a bunch of users who don't understand why their installs have stopped working.

Good idea, captured that separately so I don't lose it in comments.

alexjustesen/speedtest-tracker#1475

@thespad
Copy link
Member

thespad commented Jun 7, 2024

Updated the readme with the new envs, I think we're probably good to merge this unless you've got anything else you think needs to be updated?

@alexjustesen
Copy link
Contributor Author

Updated the readme with the new envs, I think we're probably good to merge this unless you've got anything else you think needs to be updated?

I'm good, any issues should be application side which I'll handle in app releases. Thanks!

@thespad thespad merged commit 7b98df7 into linuxserver:main Jun 7, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants