Skip to content

Conversation

hostep
Copy link
Contributor

@hostep hostep commented Nov 23, 2023

Description (*)

We found out by surprise today on Slack (thanks @benjamin-volle & @robinero) that running bin/magento cache:clean or bin/magento cache:flush will always flush FPC (built-in or Varnish) entirely, even if you've only provided a type to be cleaned like config, layout, ...

I understand that yes, probably if one of those types get flushed, you'll most likely want to flush FPC as well, but let that be up to the user to decide by seeing if they provided the type full_page explicitly in the command.

This fixes this.

Some history of this problem, flushing FPC via CLI got introduced at the request of #2025 and got fixed by c75c203

This PR enhances this a bit and will only dispatch those 2 events when either no types were provided in the command line or when full_page is one of the types provided.

Related Pull Requests

Fixed Issues (if relevant)

No idea

Manual testing scenarios (*)

  1. Modify this code like so:
diff --git a/app/code/Magento/CacheInvalidate/Observer/FlushAllCacheObserver.php b/app/code/Magento/CacheInvalidate/Observer/FlushAllCacheObserver.php
index 574263ca1ee..1db01887467 100644
--- a/app/code/Magento/CacheInvalidate/Observer/FlushAllCacheObserver.php
+++ b/app/code/Magento/CacheInvalidate/Observer/FlushAllCacheObserver.php
@@ -45,6 +45,8 @@ class FlushAllCacheObserver implements ObserverInterface
      */
     public function execute(\Magento\Framework\Event\Observer $observer)
     {
+        die(sprintf("Flusing FPC in %s\n", $this::class));
+
         if ($this->config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->config->isEnabled()) {
             $this->purgeCache->sendPurgeRequest(['.*']);
         }
diff --git a/app/code/Magento/PageCache/Observer/FlushAllCache.php b/app/code/Magento/PageCache/Observer/FlushAllCache.php
index 6bcfd0e38df..d7684e25d4c 100644
--- a/app/code/Magento/PageCache/Observer/FlushAllCache.php
+++ b/app/code/Magento/PageCache/Observer/FlushAllCache.php
@@ -62,6 +62,8 @@ class FlushAllCache implements ObserverInterface
      */
     public function execute(Observer $observer)
     {
+        die(sprintf("Flushing FPC in %s\n", $this::class));
+
         if ($this->_config->getType() === Config::BUILT_IN) {
             $this->fullPageCache->clean();
         }
  1. Use built-in FPC
  2. Run bin/magento cache:flush and bin/magento cache:clean => expected to hit one of those die statements introduced in step 1
  3. Run bin/magento cache:flush full_page and bin/magento cache:clean full_page => expected to hit one of those die statements introduced in step 1
  4. Run bin/magento cache:flush layout and bin/magento cache:clean layout => expected to not hit one of those die statements introduced in step 1
  5. Configure FPC to use Varnish
  6. Run steps 3 to 5 again

Questions or comments

Since we introduced Magento\PageCache in the Magento_Backend module, should we add magento/module-page-cache as dependency in the Backend module's composer.json file? We can also choose to hardcode full_page and don't use the constant, that's also an option ...
Update: looks like the automated tests also picked this up, I already force-pushed a change to have it hardcoded instead of using a constant from another module, adding a dependency might be out of scope here.

I noticed that the New Relic module also listens for that adminhtml_cache_flush_system event, but it's done in the adminhtml/events.xml file, so that should be fine since it's in the adminhtml area. Running those cli commands wouldn't have triggered this observer anyways. So no regression there.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] Stop flushing fpc when not asked for #38301: Stop flushing fpc when not asked for

Copy link

m2-assistant bot commented Nov 23, 2023

Hi @hostep. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.

Add the comment under your pull request to deploy test or vanilla Magento instance:
  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@hostep
Copy link
Contributor Author

hostep commented Nov 23, 2023

@magento run all tests

Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@hostep hostep force-pushed the stop-flushing-fpc-when-not-asked-for branch from 01b8366 to 53b87ab Compare November 23, 2023 22:31
@hostep
Copy link
Contributor Author

hostep commented Nov 23, 2023

@magento run all tests

Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Bravo engcom-Bravo added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Nov 24, 2023
@engcom-Delta engcom-Delta added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Dec 8, 2023
@sinhaparul sinhaparul added the Project: Community Picked PRs upvoted by the community label Dec 18, 2023
@engcom-Echo
Copy link
Contributor

@magento create issue

@engcom-Echo engcom-Echo self-assigned this Dec 21, 2023
@engcom-Echo
Copy link
Contributor

@magento run all tests

Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Echo
Copy link
Contributor

engcom-Echo commented Dec 26, 2023

✔️ QA Passed

Preconditions:

  • Install fresh Magento 2.4-develop

Manual testing scenario:

  1. We have follow steps from comment

Before: ✖️ 
Screenshot 2023-12-26 at 10 55 57 AM

After: ✔️  
Screenshot 2023-12-26 at 10 57 50 AM

Builds are failing. Hence moving it to Extended Testing

@engcom-Echo
Copy link
Contributor

@magento run Integration Tests,Functional Tests EE,Functional Tests CE,Functional Tests B2B

Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Echo
Copy link
Contributor

Functional Tests B2B and Functional Tests CE failure are different on last two run on same commit.
Functional Tests CE
Run1
Screenshot 2023-12-26 at 4 36 11 PM

Run2
Screenshot 2023-12-26 at 4 36 26 PM

Functional Tests B2B
Run1
Screenshot 2023-12-26 at 4 36 32 PM

Run2
Screenshot 2023-12-26 at 4 36 16 PM

Hence Moving it To merge in progress

@engcom-Charlie
Copy link
Contributor

@magento run Semantic Version Checker

@magento-devops-reposync-svc magento-devops-reposync-svc merged commit ee507f6 into magento:2.4-develop Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept Project: Community Picked PRs upvoted by the community Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Issue] Stop flushing fpc when not asked for
9 participants