Skip to content

Rule based logging of Queries based on conditions - #464

Draft
kofrezo wants to merge 3 commits into
mainfrom
dk_conditional_query_log
Draft

Rule based logging of Queries based on conditions#464
kofrezo wants to merge 3 commits into
mainfrom
dk_conditional_query_log

Conversation

@kofrezo

@kofrezo kofrezo commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

This change allows to define rules with that contain one or more conditions to log some queries.

If, for example, one wants to log all queries of an application that query attribute X one can do so now.

There was no way to record what a serveradmin query looked for, how
long it took, or who ran it - only transient log lines, nothing
persisted. Adds an off-by-default, admin-configurable audit log for
serveradmin.api.views.dataset_query and
serveradmin.servershell.views.get_results.

QueryLoggingRule scopes logging to an Application and/or User with its
own expiry (enabled_until); a matching, active rule causes a QueryLog
row (query text, filters, duration, result count) to be written. Both
are managed and viewable in Django Admin.
Application/user targeting alone is often too coarse for debugging one
specific issue. Adds an optional trigger_query condition to
QueryLoggingRule, reusing the existing query DSL (parse_query, same
mechanism as AccessControlGroup.query) so a rule can require the
actual query's filters to match specific attribute/value conditions
before it gets logged. attr=All() triggers on mere attribute presence
regardless of value, reusing the filter library's own destiny()
mechanism. Blank (the default) preserves today's unrestricted behavior.
@kofrezo kofrezo self-assigned this Sep 4, 2026
Adds a second, independent optional condition to QueryLoggingRule: a
multi-select of attributes (real serverdb attributes plus the hostname/
servertype/object_id/intern_ip specials) that triggers logging when the
query's restrict list requests any of them. ANDed with trigger_query
when both are set; empty (the default) preserves current behavior.
Uses a JSONField (matching QueryLog's existing filters/restrict/order_by
convention) plus a custom admin form field with Django's own
FilteredSelectMultiple widget, since a plain ManyToManyField(Attribute)
can't represent the special attributes.
@kofrezo
kofrezo force-pushed the dk_conditional_query_log branch from 0724561 to 351ec04 Compare September 4, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant