Skip to content

Add throttled VIP Search query observability - #7114

Merged
rinatkhaziev merged 9 commits into
developfrom
codex/vip-search-query-observability
Aug 18, 2026
Merged

rinatkhaziev merged 9 commits into
developfrom
codex/vip-search-query-observability

Conversation

@rinatkhaziev

@rinatkhaziev rinatkhaziev commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Surface customer-visible warnings for slow and unbounded VIP Search queries after successful backend search requests.
  • Emit a stable machine-readable warning followed by a human-readable explanation with sanitized URL or process source and customer-code origin.
  • Deduplicate using the full normalized query-family hash and violation set, with configurable threshold, window, and site budget plus fail-closed persistent-cache throttling.
  • Keep runtime values out of family identity while preserving query operators, searched fields, structural options, and ordered sort behavior.

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:

add_filter( 'vip_search_slow_query_threshold_ms', static fn(): int => 300 );
add_filter( 'vip_search_query_warning_dedupe_window_s', static fn(): int => 600 );
add_filter( 'vip_search_query_warning_budget', static fn(): int => 10 );
  • vip_search_slow_query_threshold_ms: defaults to 200; accepts 1–5000.
  • vip_search_query_warning_dedupe_window_s: defaults to 300; accepts 60–3600.
  • vip_search_query_warning_budget: defaults to 5; accepts 1–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 assertions
  • CI=1 ./bin/test.sh --filter Search_Test — 196 tests, 272 assertions, one existing skip
  • npm run test:smoke
  • npm run phplint
  • PHPCS on all changed PHP files

Notes

Repository-wide npm run phpcs still reports the existing finfo_close() deprecation in files/class-api-client.php and its existing .claude/worktrees copy. Neither file is changed by this PR.

@rinatkhaziev
rinatkhaziev requested a review from a team as a code owner July 17, 2026 02:46
Copilot AI review requested due to automatic review settings July 17, 2026 02:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_Classifier to derive a normalized “query family” structure and determine bounded vs unbounded scope.
  • Introduces Query_Warning to 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 _search requests 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.

Comment thread search/includes/classes/class-search.php Outdated
Comment thread search/includes/classes/class-query-warning.php Outdated
@codecov

codecov Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.69628% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.70%. Comparing base (3485e35) to head (3a3532f).
⚠️ Report is 67 commits behind head on develop.

Files with missing lines Patch % Lines
search/includes/classes/class-query-classifier.php 92.18% 10 Missing ⚠️
search/includes/classes/class-query-warning.php 95.26% 10 Missing ⚠️
search/search.php 0.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread search/includes/classes/class-query-classifier.php
@sonarqubecloud

Copy link
Copy Markdown

$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' ] );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shoulddd we also truncate the URL to limit log size for requests containing unusually long query args?

@sonarqubecloud

Copy link
Copy Markdown

@rinatkhaziev
rinatkhaziev merged commit 58f936e into develop Aug 18, 2026
36 of 46 checks passed
@rinatkhaziev
rinatkhaziev deleted the codex/vip-search-query-observability branch August 18, 2026 16:58
rebeccahum added a commit that referenced this pull request Aug 25, 2026
* 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>
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.

4 participants