Skip to content

Commit

Permalink
Chunked encoding for _cat APIs (#92022)
Browse files Browse the repository at this point in the history
Some of these APIs scale as O(#indices) or O(#shards) so it seems
worthwhile to use chunked encoding throughout.

Relates #89838
  • Loading branch information
DaveCTurner authored Dec 6, 2022
1 parent d94e695 commit b3a272e
Show file tree
Hide file tree
Showing 6 changed files with 342 additions and 351 deletions.
292 changes: 0 additions & 292 deletions server/src/main/java/org/elasticsearch/common/io/UTF8StreamWriter.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.common.Table;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.io.UTF8StreamWriter;
import org.elasticsearch.common.io.stream.BytesStream;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.RestStatus;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.Set;

import static org.elasticsearch.rest.action.cat.RestTable.buildHelpWidths;
Expand All @@ -39,17 +40,22 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
Table table = getTableWithHeader(request);
int[] width = buildHelpWidths(table, request);
BytesStream bytesOutput = Streams.flushOnCloseStream(channel.bytesOutput());
UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOutput);
for (Table.Cell cell : table.getHeaders()) {
// need to do left-align always, so create new cells
pad(new Table.Cell(cell.value), width[0], request, out);
out.append(" | ");
pad(new Table.Cell(cell.attr.containsKey("alias") ? cell.attr.get("alias") : ""), width[1], request, out);
out.append(" | ");
pad(new Table.Cell(cell.attr.containsKey("desc") ? cell.attr.get("desc") : "not available"), width[2], request, out);
out.append("\n");
try (var out = new OutputStreamWriter(bytesOutput, StandardCharsets.UTF_8)) {
for (Table.Cell cell : table.getHeaders()) {
// need to do left-align always, so create new cells
pad(new Table.Cell(cell.value), width[0], request, out);
out.append(" | ");
pad(new Table.Cell(cell.attr.containsKey("alias") ? cell.attr.get("alias") : ""), width[1], request, out);
out.append(" | ");
pad(
new Table.Cell(cell.attr.containsKey("desc") ? cell.attr.get("desc") : "not available"),
width[2],
request,
out
);
out.append("\n");
}
}
out.close();
channel.sendResponse(new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, bytesOutput.bytes()));
};
} else {
Expand Down
Loading

0 comments on commit b3a272e

Please sign in to comment.