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

double tracking #50

Open
JohnAD opened this issue Feb 10, 2019 · 5 comments
Open

double tracking #50

JohnAD opened this issue Feb 10, 2019 · 5 comments
Assignees
Labels

Comments

@JohnAD
Copy link
Contributor

JohnAD commented Feb 10, 2019

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?

@ashcrow
Copy link
Owner

ashcrow commented Feb 11, 2019

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 ashcrow self-assigned this Feb 11, 2019
@ashcrow ashcrow added the bug label Feb 11, 2019
@ashcrow
Copy link
Owner

ashcrow commented Feb 11, 2019

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

@JohnAD
Copy link
Contributor Author

JohnAD commented Feb 14, 2019

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.

@ashcrow
Copy link
Owner

ashcrow commented Feb 15, 2019

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.

@ezcad-dev
Copy link

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/test1@ezcad.org HTTP/1.1" 200 -
127.0.0.1 - - [03/Jul/2021 18:15:43] "GET /users/email/test1@ezcad.org 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 -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants