Skip to content

Commit

Permalink
[7.13] Limit stats values in tests to prevent long overflow (#73216)
Browse files Browse the repository at this point in the history
  • Loading branch information
danhermann authored May 18, 2021
1 parent d977e96 commit 5276ec8
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,21 +480,34 @@ public static NodeStats createNodeStats() {
: null;
IngestStats ingestStats = null;
if (frequently()) {
IngestStats.Stats totalStats = new IngestStats.Stats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(),
randomNonNegativeLong());
int numPipelines = randomIntBetween(0, 10);
int numProcessors = randomIntBetween(0, 10);
long maxStatValue = Long.MAX_VALUE / Math.max(1, numPipelines) / Math.max(1, numProcessors);
IngestStats.Stats totalStats = new IngestStats.Stats(
randomLongBetween(0, maxStatValue),
randomLongBetween(0, maxStatValue),
randomLongBetween(0, maxStatValue),
randomLongBetween(0, maxStatValue)
);
List<IngestStats.PipelineStat> ingestPipelineStats = new ArrayList<>(numPipelines);
Map<String, List<IngestStats.ProcessorStat>> ingestProcessorStats = new HashMap<>(numPipelines);
for (int i = 0; i < numPipelines; i++) {
String pipelineId = randomAlphaOfLengthBetween(3, 10);
ingestPipelineStats.add(new IngestStats.PipelineStat(pipelineId, new IngestStats.Stats
(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong())));
ingestPipelineStats.add(new IngestStats.PipelineStat(pipelineId, new IngestStats.Stats(
randomLongBetween(0, maxStatValue),
randomLongBetween(0, maxStatValue),
randomLongBetween(0, maxStatValue),
randomLongBetween(0, maxStatValue))
));

List<IngestStats.ProcessorStat> processorPerPipeline = new ArrayList<>(numProcessors);
for (int j =0; j < numProcessors;j++) {
IngestStats.Stats processorStats = new IngestStats.Stats
(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
IngestStats.Stats processorStats = new IngestStats.Stats(
randomLongBetween(0, maxStatValue),
randomLongBetween(0, maxStatValue),
randomLongBetween(0, maxStatValue),
randomLongBetween(0, maxStatValue)
);
processorPerPipeline.add(new IngestStats.ProcessorStat(randomAlphaOfLengthBetween(3, 10),
randomAlphaOfLengthBetween(3, 10), processorStats));
}
Expand Down

0 comments on commit 5276ec8

Please sign in to comment.