flask-track-usage icon indicating copy to clipboard operation
flask-track-usage copied to clipboard

double tracking

Open JohnAD opened this issue 6 years ago • 5 comments

I've not been able to hunt down the exact reason, but it appears that I'm getting "double" entries for every web query. Even using command-line wget on a specific page, it showing two entries in the tracking table and two calls into the library: one "extremely short" one. Usually with a speed of 0.04s or less. And one entry that is more representative of the actual time to download the page. This might be a quirk of Flask, but it is inflating the numbers.

Any ideas what might be causing this? Is the same procedure being called before and after the request?

JohnAD avatar Feb 10 '19 23:02 JohnAD

Off the top of my head no, but I'll take a quick gander and see if anything jumps out at me. Thanks for reporting it!

ashcrow avatar Feb 11 '19 15:02 ashcrow

Before I look, do you mind providing the flask version and the backends you've configured?

ashcrow avatar Feb 11 '19 15:02 ashcrow

I'm using mongoengine for storage (which I wrote for this repo, so it could easily be a bug of mine.)

Flask==0.12.1
flask-mongoengine==0.9.3
Flask-Track-Usage==2.0.0
mongoengine==0.13.0
pymongo==3.4.0

I've been observing it for a while on my various docker sites. An additional observation:

When ever an URL is "corrected" internally by Flask, instead of double-counting the visit, one count is applied to the original query and one count to the internal fix. For example, if a page is at "http://example.com/test/" and wget grabs "http://example.com/test", then one count is given to "http://example.com/test" and then one to "http://example.com/test/". No redirect is occurring, this is something internal to Flask.

It's almost like the wrapper is being applied prior to and after the view function.

Speaking of, I'm running with

app.config['TRACK_USAGE_USE_FREEGEOIP'] = False
app.config['TRACK_USAGE_INCLUDE_OR_EXCLUDE_VIEWS'] = 'exclude'
traffic_storage = MongoEngineStorage(hooks=[sumUrl, psTrackUsage])
t = TrackUsage(app, [traffic_storage])

"psTrackUsage" is a class I wrote. Removing it doesn't fix the problem.

If nothing jumps out, I'll start digging into this.

JohnAD avatar Feb 14 '19 21:02 JohnAD

I haven't been able to reproduce the issue with other storage backends. I tried Firefox and wget, same version of Flask and Flask-Track-Usage. I also upped to the latest release of Flask and couldn't reproduce it.

Did you try dropping sumUrl as well? While I don't have a specific reason to think it may be the culprit that was not something I was able to test with the SQLStorage with SQLite. That plus the use of mongoengine_document stood out to me, but I couldn't identify anything that was specifically out of place.

ashcrow avatar Feb 15 '19 21:02 ashcrow

I also notice this "double" behavior. Looking at the server log (below), there is an "OPTIONS" request before each of my REST request, which seems to be the preflight triggered by my Content-Type of application/json. I don't know if this is your case but want to share my experience.

127.0.0.1 - - [03/Jul/2021 18:15:42] "OPTIONS /users HTTP/1.1" 200 -
127.0.0.1 - - [03/Jul/2021 18:15:43] "POST /users HTTP/1.1" 201 -
127.0.0.1 - - [03/Jul/2021 18:15:43] "OPTIONS /users/email/[email protected] HTTP/1.1" 200 -
127.0.0.1 - - [03/Jul/2021 18:15:43] "GET /users/email/[email protected] HTTP/1.1" 200 -
127.0.0.1 - - [03/Jul/2021 18:15:43] "OPTIONS /users/access-token/a HTTP/1.1" 200 -
127.0.0.1 - - [03/Jul/2021 18:15:43] "GET /users/access-token/a HTTP/1.1" 200 -

ezcad-dev avatar Jul 03 '21 22:07 ezcad-dev