-
Notifications
You must be signed in to change notification settings - Fork 25.6k
ESQL: Log partial failures #129164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+167
−0
Merged
ESQL: Log partial failures #129164
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
378595d
ESQL: Log partial failures
nik9000 523cae1
Words are good
nik9000 97c94b7
Update docs/changelog/129164.yaml
nik9000 586043e
With cluster
nik9000 eafc8de
Merge remote-tracking branch 'nik9000/report' into report
nik9000 98f85cb
It's optional
nik9000 d00adea
Merge branch 'main' into report
nik9000 91353f4
Different logger
nik9000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 129164 | ||
| summary: Log partial failures | ||
| area: ES|QL | ||
| type: feature | ||
| issues: [] |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
|
|
||
| import org.elasticsearch.ExceptionsHelper; | ||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.action.search.ShardSearchFailure; | ||
| import org.elasticsearch.core.Releasable; | ||
| import org.elasticsearch.core.Releasables; | ||
| import org.elasticsearch.core.TimeValue; | ||
|
|
@@ -30,6 +31,7 @@ | |
|
|
||
| import java.io.IOException; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Consumer; | ||
|
|
||
|
|
@@ -121,6 +123,7 @@ private EsqlResponseListener(RestChannel channel, RestRequest restRequest, Strin | |
|
|
||
| @Override | ||
| protected void processResponse(EsqlQueryResponse esqlQueryResponse) throws IOException { | ||
| logPartialFailures(channel.request().rawPath(), channel.request().params(), esqlQueryResponse.getExecutionInfo()); | ||
| channel.sendResponse(buildResponse(esqlQueryResponse)); | ||
| } | ||
|
|
||
|
|
@@ -229,4 +232,16 @@ private void checkDelimiter() { | |
| throw new IllegalArgumentException(message); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Log all partial request failures to the {@code rest.suppressed} logger | ||
| * so an operator can categorize them after the fact. | ||
| */ | ||
| static void logPartialFailures(String rawPath, Map<String, String> params, EsqlExecutionInfo exeuctionInfo) { | ||
| for (EsqlExecutionInfo.Cluster cluster : exeuctionInfo.getClusters().values()) { | ||
| for (ShardSearchFailure failure : cluster.getFailures()) { | ||
| RestResponse.logSuppressedError(org.apache.logging.log4j.Level.WARN, rawPath, params, RestStatus.OK, failure); | ||
|
||
| } | ||
| } | ||
| } | ||
| } | ||
101 changes: 101 additions & 0 deletions
101
...gin/esql/src/test/java/org/elasticsearch/xpack/esql/action/EsqlResponseListenerTests.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.esql.action; | ||
|
|
||
| import org.apache.logging.log4j.Level; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.apache.logging.log4j.core.LogEvent; | ||
| import org.apache.logging.log4j.core.appender.AbstractAppender; | ||
| import org.apache.logging.log4j.core.config.Configurator; | ||
| import org.apache.logging.log4j.core.filter.RegexFilter; | ||
| import org.elasticsearch.action.search.ShardSearchFailure; | ||
| import org.elasticsearch.common.logging.Loggers; | ||
| import org.elasticsearch.core.TimeValue; | ||
| import org.elasticsearch.index.shard.ShardId; | ||
| import org.elasticsearch.search.SearchShardTarget; | ||
| import org.elasticsearch.test.ESTestCase; | ||
| import org.elasticsearch.transport.RemoteClusterAware; | ||
| import org.junit.AfterClass; | ||
| import org.junit.BeforeClass; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| public class EsqlResponseListenerTests extends ESTestCase { | ||
| private final String LOCAL_CLUSTER_ALIAS = RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY; | ||
|
|
||
| private static MockAppender appender; | ||
| static Logger restSuppressedLogger = LogManager.getLogger("rest.suppressed"); | ||
|
|
||
| @BeforeClass | ||
| public static void init() throws IllegalAccessException { | ||
| appender = new MockAppender("testAppender"); | ||
| appender.start(); | ||
| Configurator.setLevel(restSuppressedLogger, Level.DEBUG); | ||
| Loggers.addAppender(restSuppressedLogger, appender); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void cleanup() { | ||
| appender.stop(); | ||
| Loggers.removeAppender(restSuppressedLogger, appender); | ||
| } | ||
|
|
||
| public void testLogPartialResponseErrors() { | ||
| EsqlExecutionInfo executionInfo = new EsqlExecutionInfo(false); | ||
| executionInfo.swapCluster( | ||
| LOCAL_CLUSTER_ALIAS, | ||
| (k, v) -> new EsqlExecutionInfo.Cluster( | ||
| LOCAL_CLUSTER_ALIAS, | ||
| "idx", | ||
| false, | ||
| EsqlExecutionInfo.Cluster.Status.SUCCESSFUL, | ||
| 10, | ||
| 10, | ||
| 3, | ||
| 0, | ||
| List.of( | ||
| new ShardSearchFailure(new Exception("dummy"), target(0)), | ||
| new ShardSearchFailure(new Exception("error"), target(1)) | ||
| ), | ||
| new TimeValue(4444L) | ||
| ) | ||
| ); | ||
| EsqlResponseListener.logPartialFailures("/_query", Map.of(), executionInfo); | ||
|
|
||
| LogEvent logEvent = appender.events.get(0); | ||
| assertThat(logEvent.getLevel(), equalTo(Level.WARN)); | ||
| assertThat(logEvent.getMessage().getFormattedMessage(), equalTo("path: /_query, params: {}, status: 200")); | ||
| assertThat(logEvent.getThrown().getCause().getMessage(), equalTo("dummy")); | ||
| logEvent = appender.events.get(1); | ||
| assertThat(logEvent.getLevel(), equalTo(Level.WARN)); | ||
| assertThat(logEvent.getMessage().getFormattedMessage(), equalTo("path: /_query, params: {}, status: 200")); | ||
| assertThat(logEvent.getThrown().getCause().getMessage(), equalTo("error")); | ||
| } | ||
|
|
||
| private SearchShardTarget target(int shardId) { | ||
| return new SearchShardTarget("node", new ShardId("idx", "uuid", 0), LOCAL_CLUSTER_ALIAS); | ||
| } | ||
|
|
||
| private static class MockAppender extends AbstractAppender { | ||
| public final List<LogEvent> events = new ArrayList<>(); | ||
|
|
||
| MockAppender(final String name) throws IllegalAccessException { | ||
| super(name, RegexFilter.createFilter(".*(\n.*)*", new String[0], false, null, null), null, false); | ||
| } | ||
|
|
||
| @Override | ||
| public void append(LogEvent event) { | ||
| events.add(event.toImmutable()); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure it's supposed to be
executionInfonotexeuctionInfo.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍