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

Added new event Archiving.makeNewArchiverObject to allow customising plugin archiving #10366

Merged

Conversation

mgazdzik
Copy link
Contributor

@mgazdzik mgazdzik commented Aug 3, 2016

ref #10367

@@ -194,6 +195,14 @@ private static function getPluginArchiverClass($pluginName)
*/
protected function shouldProcessReportsForPlugin($pluginName)
{
$shouldPreventProcessing = false;

Piwik::postEvent('PluginsArchiver.shouldProcessReportsForPlugin',[$pluginName, $this->params, &$shouldPreventProcessing]);
Copy link
Member

Choose a reason for hiding this comment

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

[]-Array notation is not compatible with PHP 5.3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for catching that, fixed

@tsteur
Copy link
Member

tsteur commented Aug 3, 2016

Have you tested whether they will be still archived later eg when archiving everything via CLI and later requesting a report via UI? Have you tested what happens when browser archiving is disabled / enabled? To make this universally work we might need to add some more features as it might work for this specific use case but not in another use case

@tsteur tsteur added the Needs Review PRs that need a code review label Aug 3, 2016
@mgazdzik
Copy link
Contributor Author

mgazdzik commented Aug 4, 2016

Ok, I fixed code style notes.
As for side effect - my assumptions are that if plugin wants to change this behavior, it should take care of consequences of preventing single plugin archiving, and for second - only adding this hook shouldn't change anything.

I think that any plugins blocked from archiving with that hook will not be archived in future, as archive will be completed and closed, so only archive invalidation may bring a chagne here.
As it is this hook should not change anything. Only after some specific plugin hooks into it things may change, but again - plugin hooks into that event for a reason I guess.

If you see any specific cases needing attention right now, please let me know how to proceed with this addition?

@mattab
Copy link
Member

mattab commented Aug 16, 2016

Hi @mgazdzik

However for performance reasons it might be beneficial to prevent heavy plugin archiving under some circumstances to allow archiving run till the end (for ex. prevent actions plugin archiving, but allow remaining to process their data).

if your use case is to prevent heavy archiving of one plugin, when you skip a plugin archiving using this hook, how will you process this plugin's reports afterwards? Or do you not need the plugin's reports maybe?

@mattab mattab added this to the 2.16.x (LTS) milestone Aug 16, 2016
@tsteur
Copy link
Member

tsteur commented Aug 16, 2016

As for side effect - my assumptions are that if plugin wants to change this behavior, it should take care of consequences of preventing single plugin archiving, and for second - only adding this hook shouldn't change anything.

IMO the platform should take care of it and not a plugin developer as it will be basically impossible for developers to do this unless it's intention is really to never archive a report eg for a specific site. Then the event has some right to exist without tackling these issues. In such a case we should maybe rename the event so the consequences will be clear for a developer (that it won't be archived at any time unless custom work is done)

@mgazdzik
Copy link
Contributor Author

In my case it is not necessary to process those missing plugins after archive is completed. It's that at given time it is necessary to disable certain plugin archiving (for ex. only disable actions archiving for month period for one site) and it's acceptable that this data will simply be missing, unless period is re-archived. However higher goal here is to allow all other periods/sites to finish archiving of given plugin.

As for event name I'm totally up for renaming. Maybe something like PluginsArchiver.shouldSkipProcessingReportsForPluginAndParams would do the job? Or maybe you have something in mind?

@tsteur
Copy link
Member

tsteur commented Aug 19, 2016

I was more thinking of something like PluginsArchiver.shouldSkipProcessingReportsForPluginAndAcceptMissingData but that's not really usable either.

I think to make this event useful it would be good to have the possibility to exclude certain reports from processing during browser archiving but still execute it while running on the CLI or to still include it in the final archive of the day. Like a parameter "$isFinalArchivingForGivenPeriod" but I think we might not know when this is. It would be a nice feature to sometimes ignore archiving some archives eg when requesting "today" via browser. Then we could eg only archive some reports every hour while some others are archived every 150s. In every case it would be useful to have a report in the "final" archive for that period though. It's not in your case the case :) but it would be much more useful for others this way.

Do you actually need the event or can you not take care of this in the plugin archiver class? You get all the parameters there etc. and could make it even easier testable this way etc.

Otherwise maybe an event name like PluginsArchiver.shouldNeverArchiveParamsForPlugin or PluginsArchiver.shouldNotArchiveParamsForPlugin. Ideally it could be done in the plugin archiver class itself until there is a better use case.

FYI: Maybe we could consolidate a couple of archive events under the same namespace (for Piwik 3 or Piwik 4). It's confusing to have so many different namespaces there.

@mgazdzik
Copy link
Contributor Author

My case is strictly related to preventing other plugins from archiving under certain circumstances.
Case you described with excluding certain plugins seems also worth considering, but from my perspective it's still up to what logic will be implemented within plugin using that hook, not the hook itself.

As for my specific use case - I have a plugin doing something, and during this plugin working I want a controll over what other plugins will be archived. For ex. I want to prevent 'Actions' plugin from processing when certain plugin setting is defined in my plugin. However, I still want to archive Actions plugin for other cases (some idsites, some periods, etc.), in which plugin will not block archiving. Also I want Action reports and API to be still available, which rules out way of disabling plugin.

I hope it clarifies a bit of what is my intention with that specific event. Please let me know which way of proceeding do you find most generic for the platform?

@mattab
Copy link
Member

mattab commented Aug 22, 2016

Hi @mgazdzik
we spent some time thinking about this and here is our suggestion:


Index: core/ArchiveProcessor/PluginsArchiver.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/ArchiveProcessor/PluginsArchiver.php   (revision 7ca14d216ea95cbce881867a4cb953b367fb7d85)
+++ core/ArchiveProcessor/PluginsArchiver.php   (revision )
@@ -14,6 +14,7 @@
 use Piwik\DataAccess\LogAggregator;
 use Piwik\DataTable\Manager;
 use Piwik\Metrics;
+use Piwik\Piwik;
 use Piwik\Plugin\Archiver;
 use Piwik\Log;
 use Piwik\Timer;
@@ -50,6 +51,7 @@
     public function __construct(Parameters $params, $isTemporaryArchive)
     {
         $this->params = $params;
+        $this->isTemporaryArchive = $isTemporaryArchive;

         $this->archiveWriter = new ArchiveWriter($this->params, $isTemporaryArchive);
         $this->archiveWriter->initNewArchive();
@@ -106,7 +108,7 @@
             $latestUsedTableId = Manager::getInstance()->getMostRecentTableId();

             /** @var Archiver $archiver */
-            $archiver = new $archiverClass($this->archiveProcessor);
+            $archiver = $this->makeNewArchiverObject($archiverClass, $pluginName);

             if (!$archiver->isEnabled()) {
                 Log::debug("PluginsArchiver::%s: Skipping archiving for plugin '%s'.", __FUNCTION__, $pluginName);
@@ -235,5 +240,18 @@
         $toSum = Metrics::getVisitsMetricNames();
         $metrics = $this->archiveProcessor->aggregateNumericMetrics($toSum);
         return $metrics;
+    }
+
+    /**
+     * @param $archiverClass
+     * @return Archiver
+     */
+    private function makeNewArchiverObject($archiverClass, $pluginName)
+    {
+        $archiver = new $archiverClass($this->archiveProcessor);
+
+        Piwik::postEvent('Archiving.makeNewArchiverObject', array($archiver, $pluginName, $this->params, $this->isTemporaryArchive));
+
+        return $archiver;
     }
 }

Index: core/Plugin/Archiver.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/Plugin/Archiver.php    (revision 7ca14d216ea95cbce881867a4cb953b367fb7d85)
+++ core/Plugin/Archiver.php    (revision )
@@ -121,6 +121,11 @@
         return $this->getProcessor()->getLogAggregator();
     }

+    public function disable()
+    {
+        // add flag 
+    }
+
     /**
      * Whether this Archiver should be used or not.
      *

we reuse the namespace Archiving http://developer.piwik.org/api-reference/events#archiving - and we let plugin developers either overwrite the object completely, or hook into and call ->disable() on the plugin archiver.

In the patch above we should also implement the disable() method (and add the flag in isEnabled()

And also document the event similarly to http://developer.piwik.org/api-reference/events#trackermakenewvisitobject etc.

If it sounds good to you please update PR and we'll get this merged for next release 👍

@mattab mattab added the Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. label Aug 23, 2016
@mattab mattab modified the milestones: 2.16.3, 2.16.x (LTS) Aug 23, 2016
@tsteur tsteur changed the base branch from master to 2.x-dev September 1, 2016 06:37
@mgazdzik
Copy link
Contributor Author

@mattab - I gave a thought to idea you described. So if I understand correctly, I should use that new hook in plugin and if logic fits - just call ->disable() on archiver object and Core will skip running it.
If that's correct, then I'm ok with that solution.

@mattab
Copy link
Member

mattab commented Sep 19, 2016

@mgazdzik Yes that's what we meant 👍 could you add a comment for the Event so the Event doc will appear automatically like on http://developer.piwik.org/api-reference/events#trackermakenewvisitobject

@mgazdzik
Copy link
Contributor Author

@mattab sure, I've just added phpdoc. Please let me know should I improve anything in phpdoc or is it ok?

@mattab
Copy link
Member

mattab commented Sep 20, 2016

@mgazdzik made minor suggestions in mgazdzik#1 - can you merge and then i'll merge this

@mattab mattab changed the title Added hook that alllows plugin archiving prevention based on custom logic Added new event Archiving.makeNewArchiverObject to allow customising plugin archiving Sep 20, 2016
Event description more consistent
@mgazdzik
Copy link
Contributor Author

@mattab PR merged, thanks for docs suggestions

@mattab mattab merged commit abdf56a into matomo-org:2.x-dev Sep 21, 2016
mattab added a commit that referenced this pull request Sep 26, 2016
* Fix Scheduled Reports sent one hour late in daylight saving timezones (#10443)

* convert hour to send report to/from UTC, to ensure it isn't affected by daylight savings

* adds update script to change existing scheduled reports to use utc time

* code improvement

* adds missing param

* Added new event Archiving.makeNewArchiverObject to  allow customising plugin archiving  (#10366)

* added hook to alllow plugin archiving prevention

* cr code style notes

* reworked PR to fit CR suggestions

* added PHPDoc for hook

* Event description more consistent

* UI tests: minor changes

* Adds test checking if all screenshots are stored in lfs

* removed screenshots not stored in lfs

* readds screenshots to lfs

* 2.16.3-b4
mattab added a commit that referenced this pull request Sep 29, 2016
* Fix depraction test: use assertDeprecatedMethodIsRemovedInPiwik3

* Fix Scheduled Reports sent one hour late in daylight saving timezones (#10443)

* convert hour to send report to/from UTC, to ensure it isn't affected by daylight savings

* adds update script to change existing scheduled reports to use utc time

* code improvement

* adds missing param

* Added new event Archiving.makeNewArchiverObject to  allow customising plugin archiving  (#10366)

* added hook to alllow plugin archiving prevention

* cr code style notes

* reworked PR to fit CR suggestions

* added PHPDoc for hook

* Event description more consistent

* UI tests: minor changes

* Comment out Visitor Log UI tests refs #10536

* Adds test checking if all screenshots are stored in lfs

* removed screenshots not stored in lfs

* readds screenshots to lfs

* 2.16.3-b4

* Issue translation updates against 2.x-dev

* language update

* Fix bug in widget list remove where the JSON object becomes array

* 2.16.3-rc1

* console command custom-piwik-js:update should work when directory is writable and file does not exist yet (#10576)

* followup #10449

* Fix test
(cherry picked from commit fac3d63)

* Prevent chmod(): No such file or directory

* Automatically update all marketplace plugins when updating Piwik (#10527)

* update plugins and piwik at the same time

* make sure plugins are updated with piwik

* use only one try/catch

* reload plugin information once it has been installed

* make sure to clear caches after an update

* fix ui tests

* make sure to use correct php version without any extras

* Additional informations passed in the hook "isExcludedVisit" (issue #10415) (#10564)

* Additional informations passed in the hook "isExcludedVisit" (issue #10415)

* Added better description to the new parameters

* Update VisitExcluded.php

* Remove two parameters not needed as better to use the Request object

* Update VisitExcluded.php

* remove extra two parameters in VisitExcluded constructor to prevent confusion (#10593)

* Update our libs to latest #10526

* Update composer libraries to latest #10526

* Update log analytics to latest

* When updating the config file failed (or when any other file is not writable...), the Updater (for core or plugins) will now automatically throw an error and cancel the update (#10423)

* When updating the config file failed (or when any other file is not writable...), the Updater (for core or plugins) will now automatically throw an error and cancel the update

* add integration test to check the correct exception is thrown when config not writabel

* New integration test for updater

* Make test better

* When opening the visitor profile, do not apply the segment (#10533)

* When opening the visitor profile, do not apply the segment

* added ui test for profile but does work for me

* next try to make ui test work

* add expected screenshot

* added missing doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants