CDLUC3 / ezid

CDLUC3 ezid
MIT License
11 stars 4 forks source link

Changes to get matomo tracking for API working #561

Closed sfisher closed 7 months ago

sfisher commented 8 months ago

IDK we may want to do some more testing on dev/stage servers with this before merging, just to verify it's doing as we think.

A lot of the code changes are in the other repository for the middleware. This was a lot of config to get them working.

Celery is a task runner for sending updates to Matomo asynchonously and uses some database tables to track the tasks.

I'm testing this on the dev machine right now but will put it on stage, also.

You can hit urls like curl -i https://ezid-dev.cdlib.org//id/ark:/88122/kgjw0052 and it should insert them into Matomo.

I think I have stopped it from double-logging items that have HTML since the Javascript widget already tracks those. I'll do some more checking to see if there are things I've forgotten to exclude. You can look at what it tracks at https://matomo.cdlib.org/ under the dev site right now.

It doesn't look like very much but it took me a long time to figure out all the pieces since the original repo didn't give a lot of information about how to set it up or requirements to really get it working and the error messages didn't help.

sfisher commented 8 months ago

I changed the target merge branch to develop.

sfisher commented 7 months ago

I'm going to have to make some more config changes since I think we need to configure and install CeleryBeat which allows scheduled tasks. Apparently with a database backend, it has to be installed and then runs periodically to clean up old tasks. This was super poorly documented, but this seems to be the case according to a stack overflow question. https://stackoverflow.com/questions/13147581/celery-task-clean-up-with-db-backend I also haven't seen it clean up yet since I installed things last week and we don't want the database tables to grow out of control.

sfisher commented 7 months ago

I've now added a cleanup task since Celery isn't cleaning up the kombu_messages table as I thought the CELERY_TASK_RESULT_EXPIRES would do. I waited over a day for cleanup and it never happened.

I based my cleanup code on https://github.com/mozilla/ichnaea/issues/22 but had to change a few things (to duplicate some functions and update code to use the new API for the database since their code didn't work correctly with current versions).

The easiest way to test is by deploying to dev, but for local testing, then follow this procedure: