Add drop-in response-time measurement snippet for CB routes - #34
Open
datengraben wants to merge 5 commits into
Open
Add drop-in response-time measurement snippet for CB routes#34datengraben wants to merge 5 commits into
datengraben wants to merge 5 commits into
Conversation
- Cache::getCacheItem() now fires commonsbooking_cache_hit/_miss actions - response timer groups requests by route derived from URL/query (ajax action, REST path, or CPT context) instead of raw URL - switches default output to NDJSON written to a dedicated log file - drops the https-only gate so local/staging load tests are captured
- derive_payload(): generic sanitized snapshot of $_REQUEST (array values collapsed to counts, noise keys denylisted), so hot-route params (date range, item/location ids, ...) are captured without per-route parsing - derive_db_stats(): turns on $wpdb->save_queries at init and reads query_count/time_ms/slowest_ms/slowest_sql from $wpdb->queries at shutdown - the central point where SQL is actually emitted; slowest query SQL is literal-normalized for grouping and to avoid leaking data values into the log - both are filterable (cb_response_timer_payload_denylist, cb_response_timer_track_queries) and off by default overhead is documented in the file header
…h writes
- Adds a lazily-created {$wpdb->prefix}cb_response_timer table (dbDelta
+ versioned option, same pattern as BookingCodes::initBookingCodesTable)
with an essentials schema for segmentation: route, duration_ms,
cache_hits/misses, db_query_count/time_ms, and a payload JSON column
- The default sink now appends a trimmed row to a queue file per request
(cheap, same cost as before) instead of writing the full NDJSON record
- A WP-Cron job (cb_response_timer_flush, default every 300s) atomically
rotates the queue file and bulk-inserts pending rows in one multi-row
INSERT per chunk of 500, so no request pays for a synchronous DB write
- url/post_type/slowest_sql/slowest_ms are still computed and passed
through the cb_response_timer_measured action for custom listeners,
just dropped from the built-in SQL persistence layer
…xport
- Drops the file/cron queue entirely: each measured request now does one
direct $wpdb->insert() into {$wpdb->prefix}cb_response_timer - zero
setup, no dependency on WP-Cron actually firing (tradeoff vs the
earlier deferred-write design documented in the file header)
- Adds ip and user_agent columns; the IP is redacted (last octet for
IPv4, last colon-group for IPv6) before it's ever computed or stored -
the raw IP never exists outside $_SERVER
- Adds a CSV export at GET /cb-response-timer/{secret}/export.csv,
matched directly against the request path (no rewrite rule, nothing
to flush) and streamed in chunks so it scales with table size
- The secret is a plugin variable: define CB_RESPONSE_TIMER_SECRET in
wp-config.php, or let it auto-generate and persist as an option for
zero-setup use; overridable via cb_response_timer_export_secret
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.