Repository navigation
Add throttled VIP Search query observability - #7114
Conversation
There was a problem hiding this comment.
Pull request overview
Adds query observability to VIP Search by emitting throttled, deduplicated warnings for slow and/or structurally unbounded Elasticsearch _search queries after successful responses, along with a stable machine-readable warning contract and accompanying unit tests.
Changes:
- Introduces
Query_Classifierto derive a normalized “query family” structure and determine bounded vs unbounded scope. - Introduces
Query_Warningto throttle/dedupe warnings using persistent object cache and emit both technical + human-readable messages. - Wires warning emission into
Search::filter__ep_do_intercept_request()for successful_searchrequests and adds PHPUnit coverage for classifier and warning behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/search/includes/classes/test-class-search.php | Adds integration-style tests asserting warnings run only on successful _search requests and never affect the returned response. |
| tests/search/includes/classes/test-class-query-warning.php | Adds unit tests for message contract, sanitization, dedupe/window/budget behavior, and failure-closed cache behavior. |
| tests/search/includes/classes/test-class-query-classifier.php | Adds unit tests for scope classification and normalized family structure behavior. |
| search/search.php | Loads the new classifier + warning classes as part of the Search feature bootstrap. |
| search/includes/classes/class-search.php | Adds query_warning dependency and emits warnings on successful Elasticsearch _search responses. |
| search/includes/classes/class-query-warning.php | Implements throttled/deduplicated warning emission with stable IDs, sanitized source/origin detection, and message formatting. |
| search/includes/classes/class-query-classifier.php | Implements query scope detection and normalization for “query family” identity hashing. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #7114 +/- ##
=============================================
+ Coverage 36.69% 37.70% +1.00%
- Complexity 5302 5469 +167
=============================================
Files 300 303 +3
Lines 21475 21870 +395
=============================================
+ Hits 7881 8245 +364
- Misses 13594 13625 +31 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
| $host = preg_replace( '/[^A-Za-z0-9.\-:\[\]]/', '', wp_unslash( (string) $_SERVER['HTTP_HOST'] ) ); | ||
| // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Control characters are removed before esc_url_raw(). | ||
| $uri = preg_replace( '/[\x00-\x1F\x7F]/', '', wp_unslash( (string) $_SERVER['REQUEST_URI'] ) ); | ||
| $url = esc_url_raw( ( is_ssl() ? 'https' : 'http' ) . '://' . $host . $uri, [ 'http', 'https' ] ); |
There was a problem hiding this comment.
Shoulddd we also truncate the URL to limit log size for requests containing unusually long query args?
|
* feat: configure AI connectors with `vip config envvar` (#7177) * feat: configure AI connectors with `vip config envvar` * fix: keep SonarCloud happy * chore(deps-dev): Bump js-yaml in /search/search-dev-tools (#7169) Bumps [js-yaml](https://github.com/nodeca/js-yaml) from 4.2.0 to 4.3.1. - [Changelog](https://github.com/nodeca/js-yaml/blob/4.3.1/CHANGELOG.md) - [Commits](nodeca/js-yaml@4.2.0...4.3.1) --- updated-dependencies: - dependency-name: js-yaml dependency-version: 4.3.1 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): Bump js-yaml from 4.2.0 to 4.3.1 in /__tests__/e2e (#7168) Bumps [js-yaml](https://github.com/nodeca/js-yaml) from 4.2.0 to 4.3.1. - [Changelog](https://github.com/nodeca/js-yaml/blob/4.3.1/CHANGELOG.md) - [Commits](nodeca/js-yaml@4.2.0...4.3.1) --- updated-dependencies: - dependency-name: js-yaml dependency-version: 4.3.1 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Merge pull request #7178 from Automattic/update-rtc-version-constants-2026-08-17 Update RTC integration version constants * Add throttled VIP Search query observability (#7114) * Add VIP Search query classifier * Add throttled VIP Search query warnings * Surface expensive VIP Search queries * Harden VIP Search warning identity * Stabilize nested sort warning families * Fix VIP Search warning review regressions * Classify match_all searches as unbounded * Limit log entry url to 500 characters * Fix passing null to substr * chore(deps): Bump step-security/harden-runner from 2.20.1 to 2.21.0 (#7182) Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.20.1 to 2.21.0. - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](step-security/harden-runner@b09bb98...05e3151) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-version: 2.21.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): Bump github/codeql-action from 4.37.6 to 4.37.7 (#7181) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 4.37.6 to 4.37.7. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](github/codeql-action@v4.37.6...v4.37.7) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 4.37.7 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): Bump globals in /search/search-dev-tools (#7180) Bumps [globals](https://github.com/sindresorhus/globals) from 17.9.0 to 17.11.0. - [Release notes](https://github.com/sindresorhus/globals/releases) - [Commits](sindresorhus/globals@v17.9.0...v17.11.0) --- updated-dependencies: - dependency-name: globals dependency-version: 17.11.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): Bump johnpbloch/wordpress-core from 7.0.3 to 7.0.4 (#7179) Bumps [johnpbloch/wordpress-core](https://github.com/johnpbloch/wordpress-core) from 7.0.3 to 7.0.4. - [Commits](johnpbloch/wordpress-core@7.0.3...7.0.4) --- updated-dependencies: - dependency-name: johnpbloch/wordpress-core dependency-version: 7.0.4 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Tighten multisite upload path matching (#7186) * Prevent duplicate MCP adapter loading (#7185) * Merge pull request #7189 from Automattic/pltfrm-2723-ai-connectors-without-registered-providers-plugins-results fix(vip-helpers): fatal error when an AI provider is not set * chore(deps-dev): Bump brace-expansion in /__tests__/e2e (#7191) Bumps [brace-expansion](https://github.com/juliangruber/brace-expansion) from 1.1.14 to 1.1.18. - [Release notes](https://github.com/juliangruber/brace-expansion/releases) - [Commits](juliangruber/brace-expansion@v1.1.14...v1.1.18) --- updated-dependencies: - dependency-name: brace-expansion dependency-version: 1.1.18 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): Bump brace-expansion in /search/search-dev-tools (#7192) Bumps [brace-expansion](https://github.com/juliangruber/brace-expansion) from 1.1.12 to 1.1.18. - [Release notes](https://github.com/juliangruber/brace-expansion/releases) - [Commits](juliangruber/brace-expansion@v1.1.12...v1.1.18) --- updated-dependencies: - dependency-name: brace-expansion dependency-version: 1.1.18 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Merge pull request #7193 from szepeviktor/fix-typos chore: Fix typos * Update Jetpack to 16.1.2 (#7194) Co-authored-by: WordPress VIP Bot <no-reply@automattic.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Volodymyr Kolesnykov <volodymyr.kolesnykov@automattic.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Max Schmeling <max.schmeling@automattic.com> Co-authored-by: Rinat K <rinat@automattic.com> Co-authored-by: Rebecca Hum <rebecca.hum@automattic.com> Co-authored-by: Rebecca Hum <rebeccahum@gmail.com> Co-authored-by: Viktor Szépe <viktor@szepe.net> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: WordPress VIP Bot <no-reply@automattic.com>



Summary
Changelog description
Enterprise Search now emits throttled, customer-visible warnings after successful Elasticsearch requests when a query takes longer than 200 ms or does not contain a limiting condition. Each occurrence produces a stable machine-readable entry and a human-readable explanation containing the originating URL and customer-code location. Similar query families are deduplicated for five minutes, with up to five warning pairs emitted per site during that window.
The defaults can be adjusted with these filters:
vip_search_slow_query_threshold_ms: defaults to200; accepts1–5000.vip_search_query_warning_dedupe_window_s: defaults to300; accepts60–3600.vip_search_query_warning_budget: defaults to5; accepts1–100.Invalid or out-of-range values fall back to their defaults. Warnings require a persistent object cache so throttling can be enforced safely.
Testing
CI=1 ./bin/test.sh --filter '/Query_Classifier_Test|Query_Warning_Test|test__vip_search_query_warning/'— 45 tests, 91 assertionsCI=1 ./bin/test.sh --filter Search_Test— 196 tests, 272 assertions, one existing skipnpm run test:smokenpm run phplintNotes
Repository-wide
npm run phpcsstill reports the existingfinfo_close()deprecation infiles/class-api-client.phpand its existing.claude/worktreescopy. Neither file is changed by this PR.