Skip to content

Commit 9e56ea1

Browse files
throw custom exception with help text on parent circuit breaking exception (#24518)
* throw custom exception with help text on parent circuit breaking exception * add changelog * fix inconsistent naming --------- Co-authored-by: Patrick Mann <[email protected]> Co-authored-by: patrickmann <[email protected]>
1 parent 9699eef commit 9e56ea1

File tree

6 files changed

+101
-2
lines changed

6 files changed

+101
-2
lines changed

changelog/unreleased/pr-24518.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type = "a"
2+
message = "Throw custom exception with help text on parent circuit breaking exception."
3+
4+
issues = ["graylog-plugin-enterprise#7917"]
5+
pulls = ["24518"]

graylog-storage-elasticsearch7/src/main/java/org/graylog/storage/elasticsearch7/ElasticsearchClient.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.graylog2.indexer.InvalidWriteTargetException;
4646
import org.graylog2.indexer.MapperParsingException;
4747
import org.graylog2.indexer.MasterNotDiscoveredException;
48+
import org.graylog2.indexer.ParentCircuitBreakingException;
4849
import org.slf4j.Logger;
4950
import org.slf4j.LoggerFactory;
5051

@@ -202,6 +203,9 @@ public static RuntimeException exceptionFrom(Exception e, String errorMessage) {
202203
if (isMapperParsingExceptionException(elasticsearchException)) {
203204
return new MapperParsingException(elasticsearchException.getMessage());
204205
}
206+
if (isParentCircuitBreakingException(elasticsearchException)) {
207+
return new ParentCircuitBreakingException(elasticsearchException.getMessage());
208+
}
205209
} else if (e instanceof IOException && e.getCause() instanceof ContentTooLongException) {
206210
return new BatchSizeTooLargeException(e.getMessage());
207211
}
@@ -231,8 +235,8 @@ private static boolean isIndexNotFoundException(ElasticsearchException elasticse
231235
return elasticsearchException.getMessage().contains("index_not_found_exception");
232236
}
233237

234-
private static boolean isMapperParsingExceptionException(ElasticsearchException openSearchException) {
235-
return openSearchException.getMessage().contains("mapper_parsing_exception");
238+
private static boolean isMapperParsingExceptionException(ElasticsearchException elasticSearchException) {
239+
return elasticSearchException.getMessage().contains("mapper_parsing_exception");
236240
}
237241

238242
private static boolean isBatchSizeTooLargeException(ElasticsearchException elasticsearchException) {
@@ -254,6 +258,19 @@ private static boolean isBatchSizeTooLargeException(ElasticsearchException elast
254258
return false;
255259
}
256260

261+
private static boolean isParentCircuitBreakingException(ElasticsearchException elasticsearchException) {
262+
try {
263+
final ParsedElasticsearchException parsedException = ParsedElasticsearchException.from(elasticsearchException.getMessage());
264+
if (parsedException.type().equals("circuit_breaking_exception")) {
265+
ParsedElasticsearchException parsedCause = ParsedElasticsearchException.from(elasticsearchException.getRootCause().getMessage());
266+
return parsedCause.reason().contains("[parent] Data too large");
267+
}
268+
} catch (Exception e) {
269+
return false;
270+
}
271+
return false;
272+
}
273+
257274
public static RequestOptions withTimeout(RequestOptions requestOptions, Duration timeout) {
258275
final RequestConfig.Builder requestConfigBuilder = (requestOptions == null || requestOptions.getRequestConfig() == null)
259276
? RequestConfig.custom()

graylog-storage-opensearch2/src/main/java/org/graylog/storage/opensearch2/OpenSearchClient.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.graylog2.indexer.InvalidWriteTargetException;
4747
import org.graylog2.indexer.MapperParsingException;
4848
import org.graylog2.indexer.MasterNotDiscoveredException;
49+
import org.graylog2.indexer.ParentCircuitBreakingException;
4950
import org.slf4j.Logger;
5051
import org.slf4j.LoggerFactory;
5152

@@ -203,6 +204,9 @@ public static RuntimeException exceptionFrom(Exception e, String errorMessage) {
203204
if (isMapperParsingExceptionException(openSearchException)) {
204205
return new MapperParsingException(openSearchException.getMessage());
205206
}
207+
if (isParentCircuitBreakingException(openSearchException)) {
208+
return new ParentCircuitBreakingException(openSearchException.getMessage());
209+
}
206210
} else if (e instanceof IOException && e.getCause() instanceof ContentTooLongException) {
207211
return new BatchSizeTooLargeException(e.getMessage());
208212
}
@@ -255,6 +259,19 @@ private static boolean isBatchSizeTooLargeException(OpenSearchException openSear
255259
return false;
256260
}
257261

262+
private static boolean isParentCircuitBreakingException(OpenSearchException openSearchException) {
263+
try {
264+
final ParsedOpenSearchException parsedException = ParsedOpenSearchException.from(openSearchException.getMessage());
265+
if (parsedException.type().equals("circuit_breaking_exception")) {
266+
ParsedOpenSearchException parsedCause = ParsedOpenSearchException.from(openSearchException.getRootCause().getMessage());
267+
return parsedCause.reason().contains("[parent] Data too large");
268+
}
269+
} catch (Exception e) {
270+
return false;
271+
}
272+
return false;
273+
}
274+
258275
public static RequestOptions withTimeout(RequestOptions requestOptions, Duration timeout) {
259276
final RequestConfig.Builder requestConfigBuilder = (requestOptions == null || requestOptions.getRequestConfig() == null)
260277
? RequestConfig.custom()

graylog-storage-opensearch3/src/main/java/org/graylog/storage/opensearch3/OfficialOpensearchClient.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.graylog2.indexer.InvalidWriteTargetException;
2525
import org.graylog2.indexer.MapperParsingException;
2626
import org.graylog2.indexer.MasterNotDiscoveredException;
27+
import org.graylog2.indexer.ParentCircuitBreakingException;
2728
import org.opensearch.client.opensearch.OpenSearchAsyncClient;
2829
import org.opensearch.client.opensearch.OpenSearchClient;
2930
import org.opensearch.client.opensearch._types.ErrorCause;
@@ -145,6 +146,9 @@ public static RuntimeException mapException(Throwable t, String message) {
145146
if (isMapperParsingExceptionException(openSearchException)) {
146147
return new MapperParsingException(openSearchException.getMessage());
147148
}
149+
if (isParentCircuitBreakingException(openSearchException)) {
150+
return new ParentCircuitBreakingException(openSearchException.getMessage());
151+
}
148152
} else if (t instanceof ResponseException responseException) {
149153
if (responseException.status() == 429) {
150154
return new BatchSizeTooLargeException(t.getMessage());
@@ -194,4 +198,17 @@ private static boolean isBatchSizeTooLargeException(OpenSearchException openSear
194198
}
195199
return false;
196200
}
201+
202+
private static boolean isParentCircuitBreakingException(OpenSearchException openSearchException) {
203+
try {
204+
final ParsedOpenSearchException parsedException = ParsedOpenSearchException.from(openSearchException.getMessage());
205+
if (parsedException.type().equals("circuit_breaking_exception")) {
206+
ParsedOpenSearchException parsedCause = ParsedOpenSearchException.from(openSearchException.getCause().getMessage());
207+
return parsedCause.reason().contains("[parent] Data too large");
208+
}
209+
} catch (Exception e) {
210+
return false;
211+
}
212+
return false;
213+
}
197214
}

graylog-storage-opensearch3/src/main/java/org/graylog/storage/opensearch3/OpenSearchClient.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.graylog2.indexer.InvalidWriteTargetException;
4747
import org.graylog2.indexer.MapperParsingException;
4848
import org.graylog2.indexer.MasterNotDiscoveredException;
49+
import org.graylog2.indexer.ParentCircuitBreakingException;
4950
import org.slf4j.Logger;
5051
import org.slf4j.LoggerFactory;
5152

@@ -204,6 +205,9 @@ public static RuntimeException exceptionFrom(Exception e, String errorMessage) {
204205
if (isMapperParsingExceptionException(openSearchException)) {
205206
return new MapperParsingException(openSearchException.getMessage());
206207
}
208+
if (isParentCircuitBreakingException(openSearchException)) {
209+
return new ParentCircuitBreakingException(openSearchException.getMessage());
210+
}
207211
} else if (e instanceof IOException && e.getCause() instanceof ContentTooLongException) {
208212
return new BatchSizeTooLargeException(e.getMessage());
209213
}
@@ -256,6 +260,19 @@ private static boolean isBatchSizeTooLargeException(OpenSearchException openSear
256260
return false;
257261
}
258262

263+
private static boolean isParentCircuitBreakingException(OpenSearchException openSearchException) {
264+
try {
265+
final ParsedOpenSearchException parsedException = ParsedOpenSearchException.from(openSearchException.getMessage());
266+
if (parsedException.type().equals("circuit_breaking_exception")) {
267+
ParsedOpenSearchException parsedCause = ParsedOpenSearchException.from(openSearchException.getRootCause().getMessage());
268+
return parsedCause.reason().contains("[parent] Data too large");
269+
}
270+
} catch (Exception e) {
271+
return false;
272+
}
273+
return false;
274+
}
275+
259276
public static RequestOptions withTimeout(RequestOptions requestOptions, Duration timeout) {
260277
final RequestConfig.Builder requestConfigBuilder = (requestOptions == null || requestOptions.getRequestConfig() == null)
261278
? RequestConfig.custom()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (C) 2020 Graylog, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the Server Side Public License, version 1,
6+
* as published by MongoDB, Inc.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* Server Side Public License for more details.
12+
*
13+
* You should have received a copy of the Server Side Public License
14+
* along with this program. If not, see
15+
* <http://www.mongodb.com/licensing/server-side-public-license>.
16+
*/
17+
package org.graylog2.indexer;
18+
19+
public class ParentCircuitBreakingException extends ElasticsearchException {
20+
public static final String HELP_TEXT = "This error typically indicates that the Opensearch cluster is short on " +
21+
"JVM Heap, decrease load or increase the JVM Heap provision to resolve.";
22+
23+
public ParentCircuitBreakingException(String errorMessage) {
24+
super(("%s " + HELP_TEXT).formatted(errorMessage));
25+
}
26+
}

0 commit comments

Comments
 (0)