-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chunked encoding for pending tasks API (#91929)
This response can reach a few MiB in size in an overwhelmed cluster, let's use chunking so as not to make things worse than they already are. Relates #89838
- Loading branch information
1 parent
2d74bb7
commit a88bea9
Showing
7 changed files
with
82 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...t/java/org/elasticsearch/action/admin/cluster/tasks/PendingClusterTasksResponseTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.tasks; | ||
|
||
import org.elasticsearch.cluster.service.PendingClusterTask; | ||
import org.elasticsearch.common.Priority; | ||
import org.elasticsearch.common.text.Text; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.xcontent.ToXContent; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder; | ||
|
||
public class PendingClusterTasksResponseTests extends ESTestCase { | ||
public void testPendingClusterTasksResponseChunking() throws IOException { | ||
final var tasks = new ArrayList<PendingClusterTask>(); | ||
for (int i = between(0, 10); i > 0; i--) { | ||
tasks.add( | ||
new PendingClusterTask( | ||
randomNonNegativeLong(), | ||
randomFrom(Priority.values()), | ||
new Text(randomAlphaOfLengthBetween(1, 10)), | ||
randomNonNegativeLong(), | ||
randomBoolean() | ||
) | ||
); | ||
} | ||
|
||
int chunkCount = 0; | ||
try (XContentBuilder builder = jsonBuilder()) { | ||
final var iterator = new PendingClusterTasksResponse(tasks).toXContentChunked(ToXContent.EMPTY_PARAMS); | ||
while (iterator.hasNext()) { | ||
iterator.next().toXContent(builder, ToXContent.EMPTY_PARAMS); | ||
chunkCount += 1; | ||
} | ||
} // closing the builder verifies that the XContent is well-formed | ||
|
||
assertEquals(tasks.size() + 2, chunkCount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters