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

Display form submission statistics based on logs #5015

Merged

Conversation

sergei-maertens
Copy link
Member

@sergei-maertens sergei-maertens commented Jan 13, 2025

Closes #4931

Changes

  • Replaced the model + signals statistics with calculated stats based on log records
  • The admin class is customized quite a bit to display the aggregation data
  • Moved around the models and templates to replace the previous iteration

I'm a bit concerned about the heavy admin customization again 😒

On top of that - this will lose some historic data if organisations eagerly clean up their submissions - there's a best effort data migration to backfill this data, but it will take some time to get meaningful statistics over time.

⚠️ There don't appear to be any default groups that have permissions to view these statistics, @joeribekker - weren't we going to revisit this at some point? See #2933

Checklist

Check off the items that are completed or not relevant.

  • Impact on features

    • Checked copying a form
    • Checked import/export of a form
    • Config checks in the configuration overview admin page
    • Problem detection in the admin email digest is handled
  • Release management

    • I have labelled the PR as "needs-backport" accordingly
  • I have updated the translations assets (you do NOT need to provide translations)

    • Ran ./bin/makemessages_js.sh
    • Ran ./bin/compilemessages_js.sh
  • Dockerfile/scripts

    • Updated the Dockerfile with the necessary scripts from the ./bin folder
  • Commit hygiene

    • Commit messages refer to the relevant Github issue
    • Commit messages explain the "why" of change, not the how

Initial pass at displaying submissions statistics from timeline logs.

This doesn't take into account any aggregation yet, but allows for easy
filtering of the log records. The plan is to modify the changelist
template and to render the table markup manually, using an aggregation
queryset to provide the necessary data.

I'm a little bit concerned about customizing the admin for these kinds
of things again.
This allows filtering the submissions on a date range rather than
Django's predefined datetime field filters.
Add the extra snapshot data to existing form submission log records if
it's still available, otherwise we can't do anything.
The list view will render the aggregation results, rather than each
individual log record, so we override the entire result table and
mimic the django markup.

Note that the ordering options are not copied over/supported as this
looks quite complex in django itself. We might at some point maybe
support search fields on form name (or a list filter?) to narrow
down results if it becomes too unwieldly.
* Test the results are aggregated
* Test the search field searches through the form name
* Test the date range filter
Fixed the type annotation errors that were cluttering actual errors,
now we should not get any typing regressions anymore in the logevent
and models module in the logging app.
@sergei-maertens sergei-maertens force-pushed the feature/4931-submission-statistics-based-on-logs branch from ea7e4a9 to 6eb13d5 Compare January 13, 2025 20:38
There's no point anymore in keeping the model around and reacting
to submission events via signals - we can delete this code and let the
timeline-log-record-based approach replace it.
@sergei-maertens sergei-maertens force-pushed the feature/4931-submission-statistics-based-on-logs branch from 6eb13d5 to 67ebb7e Compare January 13, 2025 20:40
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 98.93617% with 1 line in your changes missing coverage. Please review.

Project coverage is 96.62%. Comparing base (f16d700) to head (950463d).
Report is 16 commits behind head on master.

Files with missing lines Patch % Lines
src/openforms/logging/models.py 95.23% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5015   +/-   ##
=======================================
  Coverage   96.62%   96.62%           
=======================================
  Files         761      761           
  Lines       25961    25989   +28     
  Branches     3394     3395    +1     
=======================================
+ Hits        25084    25112   +28     
  Misses        611      611           
  Partials      266      266           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sergei-maertens sergei-maertens changed the title Feature/4931 submission statistics based on logs Display form submission statistics based on logs Jan 14, 2025
Copy link
Contributor

@vaszig vaszig left a comment

Choose a reason for hiding this comment

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

  • Do we need a test for the data migration?
  • I see names in classes like FormSubmissionStatistics but the files are named as form_statistics for example. Has this been done on purpose?

src/openforms/logging/models.py Show resolved Hide resolved
@sergei-maertens
Copy link
Member Author

I shall add a test for the data migration! I forgor

@sergei-maertens sergei-maertens marked this pull request as draft January 14, 2025 10:25
@sergei-maertens
Copy link
Member Author

I shall add a test for the data migration! I forgor

Attempted this but it's a world of pain - the database can't be flushed because a table is supposed to be deleted but that goes in a later migration, GFK's make everything harder and swapping the order of migrations leads to django/testing tools not being able to resolve the model state in the migration graph :/

I ran it locally and it produced the results I expected.

@sergei-maertens sergei-maertens marked this pull request as ready for review January 14, 2025 11:16
This may be too confusing. It was decided with Joeri that we'll
remove these columns.
This makes it possible to make the numbers match from the admin page
with the aggregated results versus the number of records included
in the export file.
The total result count is based on the changelist, but we don't render
that, instead we render the aggregated/annotated queryset.
@sergei-maertens sergei-maertens force-pushed the feature/4931-submission-statistics-based-on-logs branch from a393bea to 950463d Compare January 14, 2025 11:18
@@ -0,0 +1,21 @@
{% load i18n static %}
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of overriding this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removing the item result count, as it shows the wrong number. See commit message 719dbb4 :)

@sergei-maertens sergei-maertens merged commit 134ee74 into master Jan 14, 2025
32 checks passed
@sergei-maertens sergei-maertens deleted the feature/4931-submission-statistics-based-on-logs branch January 14, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

As admin, I want to filter submission statistics based on their timestamp
2 participants