From a901aeef86c23de223bb4d66303418d3b9054478 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Fri, 13 Nov 2015 12:40:43 +0100 Subject: [PATCH] Marvel: reset buffer in HttpExporter The BytesStreamOutput buffer is not reset when exporting multiple documents. It causes the same marvel doc to be indexed many times and it creates very large bulk requests. Bug introduced in elastic/x-pack@8575fd91c48999e1cbeb56c3046184662b626b4a Original commit: elastic/x-pack-elasticsearch@adac96677dd1b6b713a3740e6d34ae429bc07bfc --- .../marvel/agent/exporter/http/HttpExporter.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporter.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporter.java index ff64d8d18c7..9ac016d8c63 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporter.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporter.java @@ -670,10 +670,13 @@ public class HttpExporter extends Exporter { // because the renderer might close the outputstream (ex: XContentBuilder) try (BytesStreamOutput buffer = new BytesStreamOutput()) { for (MarvelDoc marvelDoc : docs) { - render(marvelDoc, buffer); - - // write the result to the connection - out.write(buffer.bytes().toBytes()); + try { + render(marvelDoc, buffer); + // write the result to the connection + out.write(buffer.bytes().toBytes()); + } finally { + buffer.reset(); + } } } }