Skip to content

Commit

Permalink
Log message for doc parsing errors includes index name (#118347) (#11…
Browse files Browse the repository at this point in the history
…8416)

* Throttled doc parsing error logging

* add test

* move throttler to separate class

* small changes

* refactor unittest

* fix test

* Log message for doc parsing errors includes index name

(cherry picked from commit 85f37ac)

# Conflicts:
#	server/src/main/java/org/elasticsearch/index/mapper/DocumentMapper.java
  • Loading branch information
kkrik-es authored Dec 11, 2024
1 parent 3491312 commit 20f7919
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class DocumentMapper {
private final MapperMetrics mapperMetrics;
private final IndexVersion indexVersion;
private final Logger logger;
private final String indexName;

/**
* Create a new {@link DocumentMapper} that holds empty mappings.
Expand Down Expand Up @@ -67,16 +68,17 @@ public static DocumentMapper createEmpty(MapperService mapperService) {
this.mapperMetrics = mapperMetrics;
this.indexVersion = version;
this.logger = Loggers.getLogger(getClass(), indexName);
this.indexName = indexName;

assert mapping.toCompressedXContent().equals(source) || isSyntheticSourceMalformed(source, version)
: "provided source [" + source + "] differs from mapping [" + mapping.toCompressedXContent() + "]";
}

private void maybeLog(Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug("Error while parsing document: " + ex.getMessage(), ex);
logger.debug("Error while parsing document for index [" + indexName + "]: " + ex.getMessage(), ex);
} else if (IntervalThrottler.DOCUMENT_PARSING_FAILURE.accept()) {
logger.error("Error while parsing document: " + ex.getMessage(), ex);
logger.info("Error while parsing document for index [" + indexName + "]: " + ex.getMessage(), ex);
}
}

Expand Down

0 comments on commit 20f7919

Please sign in to comment.