Skip to content

Commit a099423

Browse files
committed
Updated estimate memory of a batch to log an error if one of any event fields is of unrecognized type
1 parent f42d0a4 commit a099423

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

logstash-core/src/main/java/org/logstash/ConvertedMap.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ private long estimateMemory(Object o) {
271271
return Double.BYTES;
272272
}
273273

274-
throw new RuntimeException("Unsupported type in estimating memory size of event: " + o.getClass());
274+
throw new IllegalArgumentException(
275+
"Unsupported type encountered in estimateMemory: " + o.getClass().getName() +
276+
". Please ensure all objects passed to estimateMemory are of supported types. " +
277+
"Refer to the ConvertedMap.estimateMemory method for the list of supported types."
278+
);
275279
}
276280
}

logstash-core/src/main/java/org/logstash/execution/QueueReadClientBatchMetrics.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.logstash.execution;
22

3+
import org.apache.logging.log4j.LogManager;
4+
import org.apache.logging.log4j.Logger;
35
import org.jruby.runtime.ThreadContext;
46
import org.logstash.ackedqueue.QueueFactoryExt;
57
import org.logstash.ext.JrubyEventExtLibrary;
@@ -11,6 +13,9 @@
1113
import static org.logstash.instrument.metrics.MetricKeys.*;
1214

1315
class QueueReadClientBatchMetrics {
16+
17+
private static final Logger LOG = LogManager.getLogger(QueueReadClientBatchMetrics.class);
18+
1419
private final QueueFactoryExt.BatchMetricMode batchMetricMode;
1520

1621
private LongCounter pipelineMetricBatchCount;
@@ -50,8 +55,12 @@ public void updateBatchMetrics(QueueBatch batch) {
5055

5156
private void updateBatchSizeMetric(QueueBatch batch) {
5257
long totalSize = 0L;
53-
for (JrubyEventExtLibrary.RubyEvent rubyEvent : batch.events()) {
54-
totalSize += rubyEvent.getEvent().estimateMemory();
58+
try {
59+
for (JrubyEventExtLibrary.RubyEvent rubyEvent : batch.events()) {
60+
totalSize += rubyEvent.getEvent().estimateMemory();
61+
}
62+
} catch (IllegalArgumentException e) {
63+
LOG.error("Failed to calculate batch byte size for metrics", e);
5564
}
5665
pipelineMetricBatchByteSize.increment(totalSize);
5766
}

0 commit comments

Comments
 (0)