Skip to content

feat(search): metrics for search-cluster request failures - #31213

Merged
mohityadav766 merged 13 commits into
mainfrom
search-failure-visibility
Sep 4, 2026
Merged

mohityadav766 merged 13 commits into
mainfrom
search-failure-visibility

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

I added a Prometheus counter for every request the server sends to the search cluster, because today a cluster returning 503 all shards failed produces nothing but an application log line. The counter is emitted from a thin wrapper around the OpenSearch and Elasticsearch transports, which is the single point all search traffic (search, bulk, index management, generic; sync and async) funnels through, so no call site had to change. status carries the cluster's HTTP status (503) or, when no response ever came back, the exception type (SocketTimeoutException, ConnectException), keeping "cluster is erroring" distinguishable from "cluster is unreachable". Alert with sum(rate(search_client_requests_total{outcome="failure"}[5m])) by (cluster, status) > 0.

Type of change:

  • Improvement

High-level design:

Metric: search_client_requests_total{engine, method, outcome, status} on the existing Prometheus registry (Metrics.globalRegistry, scraped at admin:/prometheus). Tags are deliberately low-cardinality — no index name, because multi-index _search URLs would explode the label set, and the index is already in the existing error logs.

Where it hooks in. OpenSearchClient and ElasticSearchClient each build exactly one transport that every manager, the async clients, and the generic client are derived from. Wrapping that one object (MeteredOpenSearchTransport, MeteredElasticsearchTransport) covers 100% of search traffic including background reindexing, and keeps the diff to three touched lines of production wiring.

Alternatives rejected. (a) A counter in each catch (OpenSearchException …) block — 40+ sites, easy to miss one, and misses the paths that rethrow. (b) An HttpClient5 response interceptor — cannot see connect/read timeouts (no response object) and does not cover the AWS SigV4 (AwsSdk2Transport) path. (c) The Elasticsearch Instrumentation SPI — no OpenSearch equivalent, and OpenSearch is the engine that broke.

Compatibility. Additive; no config, no schema, no API change. One knock-on fix: ElasticSearchVectorService asserts client._transport() instanceof Rest5ClientTransport, so it now unwraps the decorator first (MeteredElasticsearchTransport.unwrap). The OpenSearchClient startup log likewise unwraps so it keeps naming the real transport (AWS vs HC5) rather than the wrapper.

Tests:

Use cases covered

  • Cluster returns 503 all shards failed for a search → counted as outcome="failure", status="503" (the exact Remitly scenario)
  • Cluster unreachable / read timeout → counted as status="SocketTimeoutException" / "ConnectException", not lumped in with 5xx
  • Successful search → counted as outcome="success", so a failure ratio can be alerted on, not just a raw count
  • Async (performRequestAsync) failures are counted once the future completes, not silently dropped
  • Vector search over Elasticsearch still resolves its low-level Rest5Client through the wrapper

Unit tests

  • I added unit tests for the new/changed logic.

  • Files added:

    • openmetadata-service/src/test/java/org/openmetadata/service/search/SearchRequestMetricsTest.java
    • openmetadata-service/src/test/java/org/openmetadata/service/search/opensearch/MeteredOpenSearchTransportTest.java
    • openmetadata-service/src/test/java/org/openmetadata/service/search/elasticsearch/MeteredElasticsearchTransportTest.java
  • 15 tests, all passing. Coverage on changed classes (mvn -P static-code-analysis … jacoco:report):

    Class Line coverage Branch coverage
    SearchRequestMetrics 13/13 — 100% 8/8
    MeteredOpenSearchTransport 33/34 — 97% 9/10
    MeteredElasticsearchTransport 33/34 — 97% 7/8

    (The one uncovered line in each decorator is the implicit no-arg path of the private constructor.)

  • Regression sweep on the classes this touches — *Vector*Test, SearchClientConfigurationTest, MicrometerBundleTest, MetricsDebugTest: 181 tests, 0 failures.

Backend integration tests

  • Not applicable — no REST API surface changed; this is an internal client wrapper plus a Prometheus meter.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

Not run against a live cluster. The 503 and timeout paths are exercised in unit tests with a stub transport that throws the real OpenSearchException(status=503, "all shards failed") and ElasticsearchException, asserted through a real SimpleMeterRegistry — i.e. the assertion is on the emitted metric, not on a mock. Worth a scrape of admin:/prometheus on a dev stack before rolling to SaaS to confirm the series name renders as expected for the Grafana alert.

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation> — no issue exists; see note at the top.
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: not applicable, no schema changed.
  • For UI changes: not applicable.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • I have added tests around the new logic.
  • For connector/ingestion changes: not applicable.

🤖 Generated with Claude Code

Greptile Summary

The PR adds Micrometer counters around Elasticsearch and OpenSearch transport requests, recording request method, outcome, engine, and either HTTP status or exception type.

  • Wraps synchronous and asynchronous Elasticsearch/OpenSearch transport calls.
  • Preserves access to concrete delegate transports where existing code requires them.
  • Adds unit coverage for successful requests, HTTP failures, connectivity failures, asynchronous completion, unwrapping, and derived transports.

Confidence Score: 4/5

The PR is not yet safe to merge because Elasticsearch vector and raw low-level request failures remain invisible to the new search-cluster failure metric.

The vector service unwraps the decorated transport and sends requests directly through its low-level Rest5Client, bypassing the only methods that increment the new counter; the previously reported observability gap therefore remains.

Files Needing Attention: openmetadata-service/src/main/java/org/openmetadata/service/search/vector/ElasticSearchVectorService.java; openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/MeteredElasticsearchTransport.java

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRequestMetrics.java Defines the shared Micrometer counter and normalizes asynchronous exception wrappers.
openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/MeteredElasticsearchTransport.java Decorates Elasticsearch transport operations with success and failure counters while forwarding transport behavior.
openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/MeteredOpenSearchTransport.java Decorates OpenSearch transport operations and extracts HTTP statuses from supported exception types.
openmetadata-service/src/main/java/org/openmetadata/service/search/vector/ElasticSearchVectorService.java Adapts concrete transport extraction to work with the new Elasticsearch decorator.
openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java Installs the metered decorator around the Elasticsearch Java API transport.
openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java Installs the metered decorator for both standard and AWS OpenSearch transports.

Reviews (3): Last reviewed commit: "Merge branch 'main' into search-failure-..." | Re-trigger Greptile

Context used:

…table

When OpenSearch started returning `503 all shards failed` for a customer,
the only signal we had was an application log line — nobody was paged, and
we found out when the customer told us. There is no metric for requests the
server sends to the search cluster, so failures are invisible to Prometheus.

Wrap the OpenSearch and Elasticsearch transports — the single point all
search traffic funnels through, for both the sync and async paths — and emit
`search_client_requests_total{engine,method,outcome,status}`. `status` is the
cluster's HTTP status (503), or the exception type when no response ever came
back (SocketTimeoutException, ConnectException), so a cluster returning errors
stays distinguishable from a cluster we cannot reach.

Alert with:

    sum(rate(search_client_requests_total{outcome="failure"}[5m]))
      by (cluster, status) > 0

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings August 7, 2026 20:29
@mohityadav766
mohityadav766 requested a review from a team as a code owner August 7, 2026 20:29
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Aug 7, 2026

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 request-level Prometheus metrics for all traffic from OpenMetadata to the search cluster (OpenSearch + Elasticsearch) by wrapping the shared transport layer, enabling alerting on cluster-side failures (e.g., 503 all shards failed) and connectivity issues (timeouts, connection refused) without changing call sites.

Changes:

  • Introduces SearchRequestMetrics to record search_client_requests_total{engine,method,outcome,status} via Micrometer’s global registry.
  • Wraps OpenSearch and Elasticsearch transports (MeteredOpenSearchTransport, MeteredElasticsearchTransport) to emit success/failure counters for sync + async requests.
  • Updates Elasticsearch vector service and adds unit tests covering unwrapping and metric emission behavior.

Reviewed changes

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

Show a summary per file
File Description
openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRequestMetrics.java Defines the counter + tagging strategy and unwrap logic for async exception wrappers.
openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/MeteredOpenSearchTransport.java Wraps OpenSearch transport to emit metrics for sync/async requests and extract HTTP status when available.
openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/MeteredElasticsearchTransport.java Wraps Elasticsearch transport to emit metrics for sync/async requests and extract HTTP status when available.
openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java Wraps the constructed OpenSearch transport and keeps startup logs reporting the underlying transport type.
openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java Wraps the Rest5 transport so all ES client calls flow through metered transport.
openmetadata-service/src/main/java/org/openmetadata/service/search/vector/ElasticSearchVectorService.java Unwraps the metered transport before asserting Rest5ClientTransport and extracting the low-level client.
openmetadata-service/src/test/java/org/openmetadata/service/search/SearchRequestMetricsTest.java Unit tests for unwrap behavior on CompletionException/ExecutionException.
openmetadata-service/src/test/java/org/openmetadata/service/search/opensearch/MeteredOpenSearchTransportTest.java Validates success/failure counting for OpenSearch, including async completion paths.
openmetadata-service/src/test/java/org/openmetadata/service/search/elasticsearch/MeteredElasticsearchTransportTest.java Validates success/failure counting for Elasticsearch, including async completion paths.

Comment on lines +89 to +92
@Override
public Transport withOptions(TransportOptions options) {
return delegate.withOptions(options);
}
@mohityadav766 mohityadav766 self-assigned this Aug 7, 2026
mohityadav766 and others added 2 commits August 8, 2026 02:05
MeteredElasticsearchTransport.withOptions returned the bare delegate, so any
client derived via withTransportOptions would silently stop counting requests.
No caller does that today, but it is a hole in the "count every request"
contract. Wrap the derived transport instead.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings August 7, 2026 20:38

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 9 out of 9 changed files in this pull request and generated no new comments.

@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit be450422faef0bf3b57f237c84f9251a80e8e6e1 in Playwright run 33614049501, attempt 1.

✅ 942 passed · ❌ 0 failed · 🟡 3 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 50m 20s

⏱️ Max setup 4m 33s · max shard execution 17m 24s · max shard-job elapsed before upload 20m 13s · reporting 7s

🌐 204.51 requests/attempt · 2.39 app boots/UI scenario · 32.76% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 32.76% (convergence target: at most 15%).
  • Browser traffic was 204.51 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.39 per UI scenario (2317 boots / 969 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 160 0 0 0 0 0
🟡 Shard chromium-02 154 0 1 0 0 0
✅ Shard chromium-03 155 0 0 0 0 0
🟡 Shard chromium-04 151 0 1 0 0 0
🟡 Shard chromium-05 131 0 1 0 0 0
✅ Shard data-asset-rules-01 63 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard import-export-01 7 0 0 0 0 0
✅ Shard ingestion-01 2 0 0 0 0 0
✅ Shard reindex-01 28 0 0 0 0 0
✅ Shard search-01 12 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 3 flaky test(s) (passed on retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard chromium-02, 1 retry)
  • Flow/MetricListSearch.spec.ts › typing in the search box filters the metric list server-side (shard chromium-04, 1 retry)
  • Pages/Glossary.spec.ts › Approve and reject glossary term from Glossary Listing (shard chromium-05, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

Copilot AI review requested due to automatic review settings August 17, 2026 07:34

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 9 out of 9 changed files in this pull request and generated no new comments.

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 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (3)

openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java:189

  • This wiring only meters requests that go through the Java API client's transport. The same client instance still issues some requests directly via the low-level Rest5Client (e.g., rawSearchRequest calls lowLevelClient.performRequest(...)), which will bypass MeteredElasticsearchTransport and keep those failures invisible to the new search_client_requests_total alert.
      // Create transport - the Rest5ClientTransport handles content-type headers automatically
      Rest5ClientTransport transport =
          new Rest5ClientTransport(lowLevelClient, new JacksonJsonpMapper());
      ElasticsearchClient newClient =
          new ElasticsearchClient(new MeteredElasticsearchTransport(transport));

openmetadata-service/src/main/java/org/openmetadata/service/search/vector/ElasticSearchVectorService.java:63

  • Unwrapping the transport here is necessary to reach Rest5ClientTransport, but it also highlights that ElasticSearchVectorService executes requests via Rest5Client.performRequest(...), which bypasses MeteredElasticsearchTransport and won’t increment search_client_requests_total. If the goal is to alert on all search-cluster request failures, this path needs equivalent metering.
    ElasticsearchTransport transport = MeteredElasticsearchTransport.unwrap(client._transport());
    if (!(transport instanceof Rest5ClientTransport rest5)) {
      throw new IllegalArgumentException(
          "ElasticSearchVectorService requires Rest5ClientTransport, got: "
              + transport.getClass().getName());

openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/MeteredElasticsearchTransport.java:32

  • The class-level Javadoc claims this is “the single point all Elasticsearch traffic funnels through”, but the codebase still has low-level Rest5Client request paths (e.g., rawSearchRequest / vector generic requests) that bypass the transport entirely. Either adjust the doc to match the actual coverage, or extend instrumentation to cover those low-level requests too.
/**
 * Wraps the Elasticsearch transport so that every request the server sends to the cluster — search,
 * bulk, index management — is counted in {@link SearchRequestMetrics}. This is the single point all
 * Elasticsearch traffic funnels through.
 */

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 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (2)

openmetadata-service/src/main/java/org/openmetadata/service/search/vector/ElasticSearchVectorService.java:63

  • ElasticSearchVectorService unwraps the metered transport to reach Rest5Client, but all vector operations then go through restClient.performRequest(...) directly (executeGenericRequest), bypassing MeteredElasticsearchTransport and therefore not incrementing search.client.requests. This creates a blind spot for the exact alert this PR is adding (cluster 5xx / connectivity failures on vector-search paths). Consider recording SearchRequestMetrics around executeGenericRequest (success + failure with HTTP status / exception type), or routing these requests through the ElasticsearchTransport instead of the low-level Rest5Client.
    ElasticsearchTransport transport = MeteredElasticsearchTransport.unwrap(client._transport());
    if (!(transport instanceof Rest5ClientTransport rest5)) {
      throw new IllegalArgumentException(
          "ElasticSearchVectorService requires Rest5ClientTransport, got: "
              + transport.getClass().getName());

openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/MeteredElasticsearchTransport.java:32

  • The class-level Javadoc says this transport wrapper is the single point all Elasticsearch traffic funnels through, but there are Elasticsearch code paths that issue requests via the low-level Rest5Client directly (e.g., ElasticSearchVectorService.executeGenericRequest and ElasticSearchDataInsightsClient.performRequest). Those requests will bypass this wrapper and won’t be counted in search.client.requests, which can undermine alert coverage for search-cluster failures. Either adjust the wording to reflect the actual scope, or instrument those low-level Rest5Client call sites (or refactor them to use the metered ElasticsearchTransport) so the metric truly covers all cluster requests.
/**
 * Wraps the Elasticsearch transport so that every request the server sends to the cluster — search,
 * bulk, index management — is counted in {@link SearchRequestMetrics}. This is the single point all
 * Elasticsearch traffic funnels through.
 */

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 9 out of 9 changed files in this pull request and generated 2 comments.

Comment on lines +59 to +63
ElasticsearchTransport transport = MeteredElasticsearchTransport.unwrap(client._transport());
if (!(transport instanceof Rest5ClientTransport rest5)) {
throw new IllegalArgumentException(
"ElasticSearchVectorService requires Rest5ClientTransport, got: "
+ client._transport().getClass().getName());
+ transport.getClass().getName());
Comment on lines 182 to +186
// Create transport - the Rest5ClientTransport handles content-type headers automatically
Rest5ClientTransport transport =
new Rest5ClientTransport(lowLevelClient, new JacksonJsonpMapper());
ElasticsearchClient newClient = new ElasticsearchClient(transport);
ElasticsearchClient newClient =
new ElasticsearchClient(new MeteredElasticsearchTransport(transport));

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 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (1)

openmetadata-service/src/main/java/org/openmetadata/service/search/vector/ElasticSearchVectorService.java:63

  • ElasticSearchVectorService unwraps the metered transport and then issues requests via the extracted low-level Rest5Client (executeGenericRequest uses restClient.performRequest). Those low-level requests bypass MeteredElasticsearchTransport, so vector-search and other generic requests from this service won’t increment search_client_requests_total, leaving a gap in the “all search-cluster request failures are alertable” goal described in the PR.

To make vector/generic requests observable too, either (a) instrument executeGenericRequest (and any other restClient.performRequest* usage) to call SearchRequestMetrics.recordSuccess/recordFailure based on status/exception, or (b) introduce a metered Rest5Client wrapper returned from extractRestClient so all low-level requests are counted consistently.

  private static Rest5Client extractRestClient(ElasticsearchClient client) {
    ElasticsearchTransport transport = MeteredElasticsearchTransport.unwrap(client._transport());
    if (!(transport instanceof Rest5ClientTransport rest5)) {
      throw new IllegalArgumentException(
          "ElasticSearchVectorService requires Rest5ClientTransport, got: "
              + transport.getClass().getName());

Wrapping the OpenSearch transport made getLowLevelClient() return the metering
decorator, which broke OpensearchHC5ReactorReproIT with a ClassCastException —
it casts to ApacheHttpClient5Transport to assert the SafeResponseConsumer
wiring. Callers use this accessor precisely to reach engine internals the typed
client hides, so unwrap there rather than teach every caller about the
decorator. All traffic through the typed clients stays metered.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

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 9 out of 9 changed files in this pull request and generated 1 comment.

Suppressed comments (2)

openmetadata-service/src/main/java/org/openmetadata/service/search/vector/ElasticSearchVectorService.java:62

  • ElasticSearchVectorService extracts the underlying Rest5ClientTransport (via MeteredElasticsearchTransport.unwrap) and then uses rest5.restClient() for requests (see executeGenericRequest calling restClient.performRequest(...)). Those low-level requests bypass MeteredElasticsearchTransport, so vector/generic Elasticsearch requests won’t increment search_client_requests_total, which contradicts the PR’s stated goal of counting every server→search-cluster request.
  private static Rest5Client extractRestClient(ElasticsearchClient client) {
    ElasticsearchTransport transport = MeteredElasticsearchTransport.unwrap(client._transport());
    if (!(transport instanceof Rest5ClientTransport rest5)) {
      throw new IllegalArgumentException(
          "ElasticSearchVectorService requires Rest5ClientTransport, got: "

openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java:186

  • createElasticSearchNewClient now wraps the typed client’s transport in MeteredElasticsearchTransport, but this class (and other call sites via getLowLevelClient()) still issues requests directly on lowLevelClient.performRequest(...) (e.g., rawSearchRequest). Those low-level requests bypass the transport wrapper, so the new metric will miss a non-trivial slice of Elasticsearch traffic/failures.
      // Create transport - the Rest5ClientTransport handles content-type headers automatically
      Rest5ClientTransport transport =
          new Rest5ClientTransport(lowLevelClient, new JacksonJsonpMapper());
      ElasticsearchClient newClient =
          new ElasticsearchClient(new MeteredElasticsearchTransport(transport));

Comment on lines +224 to +228
* it are not counted in the search request metrics.
*/
@Override
public Object getLowLevelClient() {
return transport;
return MeteredOpenSearchTransport.unwrap(transport);
@gitar-bot

gitar-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 1 resolved / 2 findings

Adds Prometheus counters for search-cluster request failures, capturing HTTP status and exception types across all OpenSearch and Elasticsearch traffic through a thin transport wrapper. Comprehensive unit tests cover the 503 scenario, timeouts, async completion, and vector service integration, with 97–100% code coverage.

In buildPageHierarchySortOptions, a request to sort by fullyQualifiedName descending is silently forced to ascending because the primary-sort branch is skipped when the sort field matches FIELD_FULLY_QUALIFIED_NAME. Honor the requested sort order—either by building the tiebreaker with the caller's order or by only appending the ascending tiebreaker when the primary field differs from FQN.

💡 Bug: Descending sort on fullyQualifiedName silently forced to ascending

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java:1230-1244 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java:1203-1217

In buildPageHierarchySortOptions, when the caller requests sorting on fullyQualifiedName itself with sortType="desc", the primary-sort branch is skipped (guarded by !FIELD_FULLY_QUALIFIED_NAME.equals(sortField)) and only the hardcoded FQN-ascending tiebreaker is appended. The result is that a requested descending FQN sort is silently rendered as ascending. Fix by honoring the requested order when the sort field is fullyQualifiedName (e.g. build the tiebreaker with the requested order when sortField==FQN, or only append the Asc tiebreaker when the primary sort field differs from FQN).

✅ 1 resolved
✅ Quality: MeteredElasticsearchTransport.withOptions drops metering wrapper

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/MeteredElasticsearchTransport.java:89-92
withOptions() returns delegate.withOptions(options), i.e. the bare (unmetered) delegate transport rather than a new MeteredElasticsearchTransport. Any ElasticsearchClient derived via withTransportOptions(...) would silently stop counting requests, defeating the goal of metering 100% of traffic. It is currently harmless because no caller uses withTransportOptions (verified via grep), but it is a latent hole; wrap the result: return new MeteredElasticsearchTransport(delegate.withOptions(options)). Note the OpenSearch variant does not override withOptions (that interface lacks it), so only the ES side is affected.

🤖 Prompt for agents
Code Review: Adds Prometheus counters for search-cluster request failures, capturing HTTP status and exception types across all OpenSearch and Elasticsearch traffic through a thin transport wrapper. Comprehensive unit tests cover the 503 scenario, timeouts, async completion, and vector service integration, with 97–100% code coverage.
  
  In `buildPageHierarchySortOptions`, a request to sort by `fullyQualifiedName` descending is silently forced to ascending because the primary-sort branch is skipped when the sort field matches `FIELD_FULLY_QUALIFIED_NAME`. Honor the requested sort order—either by building the tiebreaker with the caller's order or by only appending the ascending tiebreaker when the primary field differs from FQN.

1. 💡 Bug: Descending sort on fullyQualifiedName silently forced to ascending
   Files: openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java:1230-1244, openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java:1203-1217

   In buildPageHierarchySortOptions, when the caller requests sorting on fullyQualifiedName itself with sortType="desc", the primary-sort branch is skipped (guarded by `!FIELD_FULLY_QUALIFIED_NAME.equals(sortField)`) and only the hardcoded FQN-ascending tiebreaker is appended. The result is that a requested descending FQN sort is silently rendered as ascending. Fix by honoring the requested order when the sort field is fullyQualifiedName (e.g. build the tiebreaker with the requested order when sortField==FQN, or only append the Asc tiebreaker when the primary sort field differs from FQN).

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

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.

🟡 Changes recommended

The new metric does not cover several existing low-level Elasticsearch Rest5Client request paths (e.g., vector/generic requests and raw requests), which leaves meaningful search-cluster failures uncounted relative to the stated intent.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (2)

openmetadata-service/src/main/java/org/openmetadata/service/search/vector/ElasticSearchVectorService.java:66

  • ElasticSearchVectorService extracts the underlying Rest5Client and later executes requests via restClient.performRequest(...) (see executeGenericRequest). Those low-level requests bypass MeteredElasticsearchTransport, so vector-search and generic-request failures against Elasticsearch won’t be captured by SearchRequestMetrics even though the PR’s metric is intended for alerting on search-cluster request failures.
  private static Rest5Client extractRestClient(ElasticsearchClient client) {
    ElasticsearchTransport transport = MeteredElasticsearchTransport.unwrap(client._transport());
    if (!(transport instanceof Rest5ClientTransport rest5)) {
      throw new IllegalArgumentException(
          "ElasticSearchVectorService requires Rest5ClientTransport, got: "
              + transport.getClass().getName());
    }
    return rest5.restClient();
  }

openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java:187

  • Only the Java API client transport is wrapped with MeteredElasticsearchTransport here. The class still exposes and uses the low-level Rest5Client directly (getLowLevelClient, rawSearchRequest), which means some Elasticsearch request failures remain invisible to the new search_client_requests_total metric (notably any code paths using rawSearchRequest / Rest5Client directly).
      // Create transport - the Rest5ClientTransport handles content-type headers automatically
      Rest5ClientTransport transport =
          new Rest5ClientTransport(lowLevelClient, new JacksonJsonpMapper());
      ElasticsearchClient newClient =
          new ElasticsearchClient(new MeteredElasticsearchTransport(transport));

  • Files reviewed: 9/9 changed files
  • Comments generated: 3
  • Review effort level: Lite

Comment on lines +20 to +26
/**
* Counts every request the server sends to the search cluster, so that cluster-side failures are
* alertable from Prometheus instead of only being discoverable in application logs after a user
* reports broken search.
*
* <p>Exposed as {@code search_client_requests_total{engine,method,outcome,status}}.
*/
Comment on lines +28 to +32
/**
* Wraps the Elasticsearch transport so that every request the server sends to the cluster — search,
* bulk, index management — is counted in {@link SearchRequestMetrics}. This is the single point all
* Elasticsearch traffic funnels through.
*/
Comment on lines +27 to +31
/**
* Wraps the OpenSearch transport so that every request the server sends to the cluster — search,
* bulk, index management, generic — is counted in {@link SearchRequestMetrics}. This is the single
* point all OpenSearch traffic funnels through.
*/
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — manual (2026-09-03T21:26:47Z)

Blocked the queue: integration-tests-postgres-opensearch

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

Status: Done ✅

Development

Successfully merging this pull request may close these issues.

4 participants