Closed (fixed)
Project:
Better Statistics
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
4 Jan 2013 at 09:00 UTC
Updated:
18 Feb 2013 at 20:30 UTC
Jump to comment: Most recent file
Comments
Comment #1
iamEAP commentedSo this would be global for all accesslog hits as opposed to on a field-by-field basis, is that correct?
Comment #2
mondrakeYes, that is the idea. Have a look at the patch attached.
Comment #3
iamEAP commentedI'm a little weary to include this type of functionality by default for a couple of reasons:
I toyed with the idea of integration with Context, but realized we'd run into similar issues we're having now with Drupal's incomplete bootstrap state on cached pages.
All of that being said, I recognize limiting statistics as a legitimate need in some cases. What if we added a hook like hook_statistics_skip(). Where by default, statistics will run on all pages, but if any function implementing hook_statistics_skip() returns true, it doesn't?
Comment #4
mondrakeNice idea.
This would also turn to be helpful for the other issue on optionally avoiding logging cached requests overall (point 4, comment 1, #1879512: API - Dealing with statistics data collection on cached page requests).
A hook calls for development though, whereas the patch above is for an admin to decide inclusions/exclusions. Do you fancy Better Statistics to include a basic implementation of such hook for, say, path-based and role-based inclusions/exclusions? And leave more sophisticated ones, like bots, to other modules?
Comment #5
iamEAP commentedSorry for the delayed response recently. Yes, I think I'd go for that.
Comment #6
mondrakeJust a question... will the hook be part of the plugin API? Just wondering, now the footprint of Better Statistics in the .module file of implementing modules is very limited (just hook_statistics_api), and all code can be put in the module.statistics.inc. Can this logic be kept so that this hook will be implemented there as well?
Comment #7
iamEAP commentedI think we'll need to refactor where the files are included, but that should definitely be the goal.
Is this something you'd be able to take on? Shall I do the work to add the hook and refactoring mentioned previously, and then from there you can port your work from #2 to use the hook?
Comment #8
mondrakeThis could work - when you're done I will
Comment #9
iamEAP commentedThis should pass tests; if it does, feel free to run with it. Also includes hook documentation to get you started on
hook_better_statistics_skip().Comment #10
iamEAP commentedBy the way, it'd be great if your path-based implementation could take some cues from how Drupal's default block configuration screen does it. E.g. checkbox for inclusive vs. exclusive (but no PHP filter option).
After you're done, I'll add tests for the role, path, and cached page stats skipping functionality.
Comment #11
mondrakeHere we go, a first attempt.
Note:
Cheers
Comment #13
mondrakeTest fails on cache hit with a ctools error:
can you help?
Comment #14
iamEAP commentedThe error I'm getting when running the tests locally is...
Fatal error: Call to undefined function truncate_utf8() in /path/to/better_statistics/better_statistics.statistics.inc on line 145Looks like there's a call to truncate_utf8 in your hook_better_statistics_skip() implementation before unicode.inc is loaded. If we move the session bootstrap and unicode.inc include before the hook invocation, we shouldn't see any problems. Updated patch attached. Have not reviewed any of the other code, though.
Comment #15
iamEAP commentedHere's a screenshot of the path-based configuration for blocks; we should continue that pattern to minimize confusion.
Comment #16
mondrakeThanks a lot.
I agree, the whole 'filters' fieldset as implemented in the patch is cluttering the Statistics configuration page too much...
One idea could be to move it to an independent 'Filtering' form, where cache-based, path-based, role-based can be separate tabs in a vertical tabs form - and where implementing modules might add their own tabs. Then, in the Statistics configuration page just put a link to the 'Filtering' form.
Thoughts?
Comment #17
iamEAP commentedHmm... Before we open it up to multiple admin pages/forms, I wonder how it would look if we created a separate fieldset (collapsed by default) for filtering? And maybe clarify the current "Better Statistics Settings" fieldset to read "Access Log Data Collection" or something.
Also, I might suggest using "Access Log Restrictions" instead of "filters." "Filter" implies to me that the data is still being collected, it's just not being shown (like in a View), and that if I 'unfilter" it, the data will be there all of a sudden.
Comment #18
mondrakeOK - simpler. I will update next week.
just to check, are you going to develop the better_statistics_cache_status() function as per comment 7.2 in #1879512: API - Dealing with statistics data collection on cached page requests? We will need it to finalise this one.
Comment #19
mondrakeHere we go.
Note I learnt tests a bit :) so I included some already - although definitely need review as I was not sure where you would like to put them in the code.
Cheers
Comment #20
iamEAP commentedThis looks excellent.
Couple of notes:
The tests look good to me. I think I'd like to add a couple of admin configuration page tests too (for example: the switching of cache enabled vs. cache disabled).
Getting closer!
Comment #21
iamEAP commentedThis still needs work, but just verifying Testbot still likes it.
Most importantly, I changed how the API will work. I think it makes more sense to mirror drupal_page_is_cacheable() with a better_statistics_request_is_loggable() and providing a hook_better_statistics_prelog() to allow modules to react and set it if necessary.
I also tried (but failed) to put a vertical tab inside of a fieldset. I'm definitely not in love with it. I also did not do any of the additional tests/block configuration form copying I noted above.
Comment #22
mondrakeThanks, I'll leave you lead the dance now :)
Few comments:
Invalid plugin module/type combination requested: module context and type pluginsin the watchdog (the main watchdog, not the watchdog of the test environment). I suspect sth related to low bootstrap phase on cached pages again. However, no errors in the tests themselves.Cheers
Comment #23
iamEAP commentedI cannot for the life of me get this to pass locally, even though it's working as expected. Checking to see what Testbot thinks.
Comment #25
mondrakeFor some strange reason, an access to the 'node' page was being logged in patch in #23 while accessing admin/config.
I repeated the truncate and drupalGet twice, and now it works for me.
Comment #26
iamEAP commentedThanks very much, mondrake! Must be an oddity of the test framework. I added one more test (for the cache enabled/disabled), and in doing so, discovered it was broken.
If everything is working on your end I'll go ahead and commit this and likely put out the next point release.
Comment #28
mondrake#26: better_statistics-conditionally_skip_stats_collection-1879726-26.patch queued for re-testing.
Comment #30
iamEAP commentedIt's possible d.o's tsetbot might need a $this->refreshVariables(); after changing those configurations...
Comment #31
mondrakeJust checking, will you post a new patch?
Comment #32
iamEAP commentedYes, shortly.
Comment #33
iamEAP commentedAh. Was checking for strings that only appear on the page when page cache is enabled.
Comment #34
mondrakeLooks all good here. Thanks!
Comment #35
iamEAP commentedGreat. Committed: http://drupalcode.org/project/better_statistics.git/commit/6460aaf
Thanks as always for your contribution, mondrake!
Per #1892876: META: 1.x Roadmap, I'll be releasing 7.x-1.2 shortly.
Comment #36
mondrakeHow unfortunate.
Sorry but I just came across a php notice
Notice: Trying to get property of non-object in drupal_lookup_path() (line 77 of /..../includes/path.inc).This is happening when serving a cached page, and you have specified page-based restrictions.
There is a drupal_get_path_alias() on line 147 of better_statistics.statistics.inc, which calls a drupal_lookup_path(), which in turns expects the global $language_url to be set - but with low bootstrap phase it looks like this is not defined, hence the notice.
Comment #37
iamEAP commentedAre the page-based restrictions still working and just barking a notice, or are they not working at all? Perhaps they're only broken in a multilingual site?
Comment #38
mondrakeHi,
nothing broken AFAICS. I updated the module on a live site where I applied the following restrictions:
- cache: enabled
- roles: only anon users
- pages: all but an excluded path
Everything gets logged as expected, but any time a page is served from cache, the php notice gets logged in the watchdog.
And yes, the site is multilingual, albeit URL detection is not enabled.
I just gave a try at raising the bootstrap phase to DRUPAL_BOOTSTRAP_LANGUAGE in the hook_exit implementation - which takes away the notice, but unfortunately is very late in the page processing request and raises some 'headers already sent' warnings, which is definitely worse.
Cheers
Comment #39
iamEAP commentedThanks for the report. For my sanity, I'm closing this and opening up a follow-up with your notes.
#1907684: Notice: Trying to get property of non-object in drupal_lookup_path()
Comment #40
mondrakeSure, thanks