use of org.opensearch.transport.TransportStats in project OpenSearch by opensearch-project.
the class NodeStatsTests method createNodeStats.
public static NodeStats createNodeStats() {
DiscoveryNode node = new DiscoveryNode("test_node", buildNewFakeTransportAddress(), emptyMap(), emptySet(), VersionUtils.randomVersion(random()));
OsStats osStats = null;
if (frequently()) {
double[] loadAverages = new double[3];
for (int i = 0; i < 3; i++) {
loadAverages[i] = randomBoolean() ? randomDouble() : -1;
}
long memTotal = randomNonNegativeLong();
long swapTotal = randomNonNegativeLong();
osStats = new OsStats(System.currentTimeMillis(), new OsStats.Cpu(randomShort(), loadAverages), new OsStats.Mem(memTotal, randomLongBetween(0, memTotal)), new OsStats.Swap(swapTotal, randomLongBetween(0, swapTotal)), new OsStats.Cgroup(randomAlphaOfLength(8), randomNonNegativeLong(), randomAlphaOfLength(8), randomNonNegativeLong(), randomNonNegativeLong(), new OsStats.Cgroup.CpuStat(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()), randomAlphaOfLength(8), Long.toString(randomNonNegativeLong()), Long.toString(randomNonNegativeLong())));
}
ProcessStats processStats = frequently() ? new ProcessStats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), new ProcessStats.Cpu(randomShort(), randomNonNegativeLong()), new ProcessStats.Mem(randomNonNegativeLong())) : null;
JvmStats jvmStats = null;
if (frequently()) {
int numMemoryPools = randomIntBetween(0, 10);
List<JvmStats.MemoryPool> memoryPools = new ArrayList<>(numMemoryPools);
for (int i = 0; i < numMemoryPools; i++) {
memoryPools.add(new JvmStats.MemoryPool(randomAlphaOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), new JvmStats.MemoryPoolGcStats(randomNonNegativeLong(), randomNonNegativeLong())));
}
JvmStats.Threads threads = new JvmStats.Threads(randomIntBetween(1, 1000), randomIntBetween(1, 1000));
int numGarbageCollectors = randomIntBetween(0, 10);
JvmStats.GarbageCollector[] garbageCollectorsArray = new JvmStats.GarbageCollector[numGarbageCollectors];
for (int i = 0; i < numGarbageCollectors; i++) {
garbageCollectorsArray[i] = new JvmStats.GarbageCollector(randomAlphaOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong());
}
JvmStats.GarbageCollectors garbageCollectors = new JvmStats.GarbageCollectors(garbageCollectorsArray);
int numBufferPools = randomIntBetween(0, 10);
List<JvmStats.BufferPool> bufferPoolList = new ArrayList<>();
for (int i = 0; i < numBufferPools; i++) {
bufferPoolList.add(new JvmStats.BufferPool(randomAlphaOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
}
JvmStats.Classes classes = new JvmStats.Classes(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
jvmStats = frequently() ? new JvmStats(randomNonNegativeLong(), randomNonNegativeLong(), new JvmStats.Mem(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), memoryPools), threads, garbageCollectors, randomBoolean() ? Collections.emptyList() : bufferPoolList, classes) : null;
}
ThreadPoolStats threadPoolStats = null;
if (frequently()) {
int numThreadPoolStats = randomIntBetween(0, 10);
List<ThreadPoolStats.Stats> threadPoolStatsList = new ArrayList<>();
for (int i = 0; i < numThreadPoolStats; i++) {
threadPoolStatsList.add(new ThreadPoolStats.Stats(randomAlphaOfLengthBetween(3, 10), randomIntBetween(1, 1000), randomIntBetween(1, 1000), randomIntBetween(1, 1000), randomNonNegativeLong(), randomIntBetween(1, 1000), randomIntBetween(1, 1000)));
}
threadPoolStats = new ThreadPoolStats(threadPoolStatsList);
}
FsInfo fsInfo = null;
if (frequently()) {
int numDeviceStats = randomIntBetween(0, 10);
FsInfo.DeviceStats[] deviceStatsArray = new FsInfo.DeviceStats[numDeviceStats];
for (int i = 0; i < numDeviceStats; i++) {
FsInfo.DeviceStats previousDeviceStats = randomBoolean() ? null : new FsInfo.DeviceStats(randomInt(), randomInt(), randomAlphaOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), null);
deviceStatsArray[i] = new FsInfo.DeviceStats(randomInt(), randomInt(), randomAlphaOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), previousDeviceStats);
}
FsInfo.IoStats ioStats = new FsInfo.IoStats(deviceStatsArray);
int numPaths = randomIntBetween(0, 10);
FsInfo.Path[] paths = new FsInfo.Path[numPaths];
for (int i = 0; i < numPaths; i++) {
paths[i] = new FsInfo.Path(randomAlphaOfLengthBetween(3, 10), randomBoolean() ? randomAlphaOfLengthBetween(3, 10) : null, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
}
fsInfo = new FsInfo(randomNonNegativeLong(), ioStats, paths);
}
TransportStats transportStats = frequently() ? new TransportStats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()) : null;
HttpStats httpStats = frequently() ? new HttpStats(randomNonNegativeLong(), randomNonNegativeLong()) : null;
AllCircuitBreakerStats allCircuitBreakerStats = null;
if (frequently()) {
int numCircuitBreakerStats = randomIntBetween(0, 10);
CircuitBreakerStats[] circuitBreakerStatsArray = new CircuitBreakerStats[numCircuitBreakerStats];
for (int i = 0; i < numCircuitBreakerStats; i++) {
circuitBreakerStatsArray[i] = new CircuitBreakerStats(randomAlphaOfLengthBetween(3, 10), randomNonNegativeLong(), randomNonNegativeLong(), randomDouble(), randomNonNegativeLong());
}
allCircuitBreakerStats = new AllCircuitBreakerStats(circuitBreakerStatsArray);
}
ScriptStats scriptStats = frequently() ? new ScriptStats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()) : null;
DiscoveryStats discoveryStats = frequently() ? new DiscoveryStats(randomBoolean() ? new PendingClusterStateStats(randomInt(), randomInt(), randomInt()) : null, randomBoolean() ? new PublishClusterStateStats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()) : null) : 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);
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())));
List<IngestStats.ProcessorStat> processorPerPipeline = new ArrayList<>(numProcessors);
for (int j = 0; j < numProcessors; j++) {
IngestStats.Stats processorStats = new IngestStats.Stats(randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
processorPerPipeline.add(new IngestStats.ProcessorStat(randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10), processorStats));
}
ingestProcessorStats.put(pipelineId, processorPerPipeline);
}
ingestStats = new IngestStats(totalStats, ingestPipelineStats, ingestProcessorStats);
}
AdaptiveSelectionStats adaptiveSelectionStats = null;
if (frequently()) {
int numNodes = randomIntBetween(0, 10);
Map<String, Long> nodeConnections = new HashMap<>();
Map<String, ResponseCollectorService.ComputedNodeStats> nodeStats = new HashMap<>();
for (int i = 0; i < numNodes; i++) {
String nodeId = randomAlphaOfLengthBetween(3, 10);
// add outgoing connection info
if (frequently()) {
nodeConnections.put(nodeId, randomLongBetween(0, 100));
}
// add node calculations
if (frequently()) {
ResponseCollectorService.ComputedNodeStats stats = new ResponseCollectorService.ComputedNodeStats(nodeId, randomIntBetween(1, 10), randomIntBetween(0, 2000), randomDoubleBetween(1.0, 10000000.0, true), randomDoubleBetween(1.0, 10000000.0, true));
nodeStats.put(nodeId, stats);
}
}
adaptiveSelectionStats = new AdaptiveSelectionStats(nodeConnections, nodeStats);
}
ScriptCacheStats scriptCacheStats = scriptStats != null ? scriptStats.toScriptCacheStats() : null;
// TODO NodeIndicesStats are not tested here, way too complicated to create, also they need to be migrated to Writeable yet
return new NodeStats(node, randomNonNegativeLong(), null, osStats, processStats, jvmStats, threadPoolStats, fsInfo, transportStats, httpStats, allCircuitBreakerStats, scriptStats, discoveryStats, ingestStats, adaptiveSelectionStats, scriptCacheStats, null, null);
}
Aggregations