-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Integrate archiveReports with ArchiveMetrics timer #23906
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
Merged
+223
−8
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bf8072f
Integrate archiveReports with ArchiveMetrics timer
caddoo e919d2f
Create event and hook timer into it
caddoo 314b8be
Add better typing
caddoo 46ad73e
Make sure plugin is loaded for integration test
caddoo ed193e0
Skip metrics for single-report archiving
caddoo af603d4
Add test-only timer reset helper
caddoo 08b1f2f
Simplify archive loader test GET handling
caddoo 1651bee
Add nullable type for instance
caddoo 4f60002
cs fix
caddoo 7eca2a1
Add strict types
caddoo ad8a520
Allow reports to have metrics recorded
caddoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
plugins/CoreAdminHome/tests/Integration/ArchiveReportsMetricsTimerTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Matomo - free/libre analytics platform | ||
| * | ||
| * @link https://matomo.org | ||
| * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Piwik\Plugins\CoreAdminHome\tests\Integration; | ||
|
|
||
| use Piwik\Common; | ||
| use Piwik\Db; | ||
| use Piwik\Plugins\ArchivingMetrics\Timer; | ||
| use Piwik\Plugins\CoreAdminHome\API as CoreAdminHomeAPI; | ||
| use Piwik\Tests\Framework\Fixture; | ||
| use Piwik\Tests\Framework\TestCase\IntegrationTestCase; | ||
|
|
||
| /** | ||
| * @group CoreAdminHome | ||
| * @group CoreAdminHome_ArchiveReportsMetricsTimer | ||
| * @group Plugins | ||
| */ | ||
| class ArchiveReportsMetricsTimerTest extends IntegrationTestCase | ||
| { | ||
| public static function setUpBeforeClass(): void | ||
| { | ||
| self::$fixture->extraPluginsToLoad[] = 'ArchivingMetrics'; | ||
|
|
||
| parent::setUpBeforeClass(); | ||
| } | ||
|
|
||
| public function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| Timer::resetInstanceForTests(); | ||
| } | ||
|
|
||
| public function testArchiveReportsWritesMetricsOnceAndDoesNotWriteAgainWhenReusingDbArchive(): void | ||
| { | ||
| Fixture::createSuperUser(true); | ||
| $_GET['trigger'] = 'archivephp'; | ||
|
|
||
| $idSite = Fixture::createWebsite('2024-01-01 00:00:00'); | ||
|
|
||
| $t = Fixture::getTracker($idSite, '2024-01-01 12:00:00'); | ||
| $t->setUrl('http://example.com/'); | ||
| Fixture::checkResponse($t->doTrackPageView('test')); | ||
|
|
||
| CoreAdminHomeAPI::getInstance()->archiveReports($idSite, 'day', '2024-01-01'); | ||
| $this->assertSame(1, $this->getMetricsCount(), 'Expected archiving_metrics to have 1 row after first archiveReports call.'); | ||
|
|
||
| CoreAdminHomeAPI::getInstance()->archiveReports($idSite, 'day', '2024-01-01'); | ||
| $this->assertSame(1, $this->getMetricsCount(), 'Expected archiving_metrics to still have 1 row after reusing the same DB archive.'); | ||
| } | ||
|
|
||
| private function getMetricsCount(): int | ||
| { | ||
| return (int) Db::fetchOne('SELECT COUNT(*) FROM ' . Common::prefixTable('archiving_metrics')); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it relevant for the current metric gathering if a single report was requested? For example, when a new custom report is being archived?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've decided now to skip for individual reports, i've left the condition at this level, is that going to be confusing do you think, that there is a decision here and internally in the timer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not mean to add any skip-check here, I would actually not. The event handler should take care of not doing work on anything it receives but does not want.
Phrasing my question differently:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now used and removed
$shouldRecordMetrics