Skip to content

Commit

Permalink
Log message for doc parsing errors includes index name (elastic#118347)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kkrik-es authored Dec 10, 2024
1 parent 43e298f commit 85f37ac
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.info("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 85f37ac

Please sign in to comment.