Repository navigation
feat(search): metrics for search-cluster request failures - #31213
Conversation
…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]>
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
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 |
There was a problem hiding this comment.
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
SearchRequestMetricsto recordsearch_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. |
| @Override | ||
| public Transport withOptions(TransportOptions options) { | ||
| return delegate.withOptions(options); | ||
| } |
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]>
✅ Playwright Results — workflow succeededValidated commit ✅ 942 passed · ❌ 0 failed · 🟡 3 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky PerformanceBlocking 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:
🟡 3 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
There was a problem hiding this comment.
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.
*/
There was a problem hiding this comment.
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.
*/
| 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()); |
| // 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)); |
There was a problem hiding this comment.
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
ElasticSearchVectorServiceunwraps the metered transport and then issues requests via the extracted low-levelRest5Client(executeGenericRequestusesrestClient.performRequest). Those low-level requests bypassMeteredElasticsearchTransport, so vector-search and other generic requests from this service won’t incrementsearch_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]>
There was a problem hiding this comment.
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
ElasticSearchVectorServiceextracts the underlyingRest5ClientTransport(viaMeteredElasticsearchTransport.unwrap) and then usesrest5.restClient()for requests (seeexecuteGenericRequestcallingrestClient.performRequest(...)). Those low-level requests bypassMeteredElasticsearchTransport, so vector/generic Elasticsearch requests won’t incrementsearch_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
createElasticSearchNewClientnow wraps the typed client’s transport inMeteredElasticsearchTransport, but this class (and other call sites viagetLowLevelClient()) still issues requests directly onlowLevelClient.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));
| * it are not counted in the search request metrics. | ||
| */ | ||
| @Override | ||
| public Object getLowLevelClient() { | ||
| return transport; | ||
| return MeteredOpenSearchTransport.unwrap(transport); |
Code Review 👍 Approved with suggestions 1 resolved / 2 findingsAdds 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 💡 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 ✅ 1 resolved✅ Quality: MeteredElasticsearchTransport.withOptions drops metering wrapper
🤖 Prompt for agentsOptionsDisplay: compact → Showing less information. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
There was a problem hiding this comment.
🟡 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
| /** | ||
| * 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}}. | ||
| */ |
| /** | ||
| * 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. | ||
| */ |
| /** | ||
| * 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. | ||
| */ |
🚦 Removed from the merge queue —
|
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 failedproduces 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.statuscarries 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 withsum(rate(search_client_requests_total{outcome="failure"}[5m])) by (cluster, status) > 0.Type of change:
High-level design:
Metric:
search_client_requests_total{engine, method, outcome, status}on the existing Prometheus registry (Metrics.globalRegistry, scraped atadmin:/prometheus). Tags are deliberately low-cardinality — no index name, because multi-index_searchURLs would explode the label set, and the index is already in the existing error logs.Where it hooks in.
OpenSearchClientandElasticSearchClienteach 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 ElasticsearchInstrumentationSPI — no OpenSearch equivalent, and OpenSearch is the engine that broke.Compatibility. Additive; no config, no schema, no API change. One knock-on fix:
ElasticSearchVectorServiceassertsclient._transport() instanceof Rest5ClientTransport, so it now unwraps the decorator first (MeteredElasticsearchTransport.unwrap). TheOpenSearchClientstartup log likewise unwraps so it keeps naming the real transport (AWS vs HC5) rather than the wrapper.Tests:
Use cases covered
503 all shards failedfor a search → counted asoutcome="failure", status="503"(the exact Remitly scenario)status="SocketTimeoutException"/"ConnectException", not lumped in with 5xxoutcome="success", so a failure ratio can be alerted on, not just a raw countperformRequestAsync) failures are counted once the future completes, not silently droppedRest5Clientthrough the wrapperUnit tests
I added unit tests for the new/changed logic.
Files added:
openmetadata-service/src/test/java/org/openmetadata/service/search/SearchRequestMetricsTest.javaopenmetadata-service/src/test/java/org/openmetadata/service/search/opensearch/MeteredOpenSearchTransportTest.javaopenmetadata-service/src/test/java/org/openmetadata/service/search/elasticsearch/MeteredElasticsearchTransportTest.java15 tests, all passing. Coverage on changed classes (
mvn -P static-code-analysis … jacoco:report):SearchRequestMetricsMeteredOpenSearchTransportMeteredElasticsearchTransport(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
Ingestion integration tests
Playwright (UI) tests
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")andElasticsearchException, asserted through a realSimpleMeterRegistry— i.e. the assertion is on the emitted metric, not on a mock. Worth a scrape ofadmin:/prometheuson 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:
Fixes <issue-number>: <short explanation>— no issue exists; see note at the top.Fixes #<issue-number>above.🤖 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.
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
Reviews (3): Last reviewed commit: "Merge branch 'main' into search-failure-..." | Re-trigger Greptile
Context used: