use of com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.PartitionEntity in project cruise-control by linkedin.
the class KafkaPartitionMetricSampleAggregatorTest method testFallbackToAvgAvailable.
@Test
public void testFallbackToAvgAvailable() throws NotEnoughValidWindowsException {
KafkaCruiseControlConfig config = new KafkaCruiseControlConfig(getLoadMonitorProperties());
Metadata metadata = getMetadata(Collections.singleton(TP));
KafkaPartitionMetricSampleAggregator metricSampleAggregator = new KafkaPartitionMetricSampleAggregator(config, metadata);
// Only give two sample to the aggregator.
CruiseControlUnitTestUtils.populateSampleAggregator(NUM_WINDOWS - 1, MIN_SAMPLES_PER_WINDOW, metricSampleAggregator, PE, 2, WINDOW_MS, KafkaMetricDef.commonMetricDef());
MetricSampleAggregationResult<String, PartitionEntity> result = metricSampleAggregator.aggregate(metadata.fetch(), NUM_WINDOWS * WINDOW_MS, new OperationProgress());
// Partition "topic-0" is expected to be a valid partition in result with valid sample values for window [3, NUM_WINDOWS].
assertEquals(NUM_WINDOWS - 2, result.valuesAndExtrapolations().get(PE).windows().size());
populateSampleAggregator(2, MIN_SAMPLES_PER_WINDOW - 2, metricSampleAggregator);
result = metricSampleAggregator.aggregate(metadata.fetch(), NUM_WINDOWS * WINDOW_MS, new OperationProgress());
int numWindows = result.valuesAndExtrapolations().get(PE).metricValues().length();
assertEquals(NUM_WINDOWS, numWindows);
int numExtrapolationss = 0;
for (Map.Entry<Integer, Extrapolation> entry : result.valuesAndExtrapolations().get(PE).extrapolations().entrySet()) {
assertEquals(Extrapolation.AVG_AVAILABLE, entry.getValue());
numExtrapolationss++;
}
assertEquals(2, numExtrapolationss);
}
use of com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.PartitionEntity in project cruise-control by linkedin.
the class KafkaPartitionMetricSampleAggregatorTest method testAggregateWithPartitionExtrapolations.
@Test
public void testAggregateWithPartitionExtrapolations() throws NotEnoughValidWindowsException {
KafkaCruiseControlConfig config = new KafkaCruiseControlConfig(getLoadMonitorProperties());
Metadata metadata = getMetadata(Collections.singleton(TP));
KafkaPartitionMetricSampleAggregator metricSampleAggregator = new KafkaPartitionMetricSampleAggregator(config, metadata);
TopicPartition tp1 = new TopicPartition(TOPIC0, 1);
Cluster cluster = getCluster(Arrays.asList(TP, tp1));
PartitionEntity pe1 = new PartitionEntity(tp1);
List<MetadataResponse.PartitionMetadata> partitionMetadata = Collections.singletonList(new MetadataResponse.PartitionMetadata(Errors.NONE, 1, NODE_0, Optional.of(RecordBatch.NO_PARTITION_LEADER_EPOCH), Arrays.asList(nodes()), Arrays.asList(nodes()), Collections.emptyList()));
List<MetadataResponse.TopicMetadata> topicMetadata = Collections.singletonList(new MetadataResponse.TopicMetadata(Errors.NONE, TOPIC0, false, partitionMetadata));
MetadataResponse metadataResponse = KafkaCruiseControlUtils.prepareMetadataResponse(cluster.nodes(), cluster.clusterResource().clusterId(), MetadataResponse.NO_CONTROLLER_ID, topicMetadata);
metadata.update(KafkaCruiseControlUtils.REQUEST_VERSION_UPDATE, metadataResponse, 1);
populateSampleAggregator(NUM_WINDOWS + 1, MIN_SAMPLES_PER_WINDOW, metricSampleAggregator);
// Populate partition 1 but leave 1 hole at NUM_WINDOWS'th window.
CruiseControlUnitTestUtils.populateSampleAggregator(NUM_WINDOWS - 2, MIN_SAMPLES_PER_WINDOW, metricSampleAggregator, pe1, 0, WINDOW_MS, KafkaMetricDef.commonMetricDef());
CruiseControlUnitTestUtils.populateSampleAggregator(2, MIN_SAMPLES_PER_WINDOW, metricSampleAggregator, pe1, NUM_WINDOWS - 1, WINDOW_MS, KafkaMetricDef.commonMetricDef());
MetricSampleAggregationResult<String, PartitionEntity> result = metricSampleAggregator.aggregate(cluster, Long.MAX_VALUE, new OperationProgress());
assertEquals(2, result.valuesAndExtrapolations().size());
assertTrue(result.valuesAndExtrapolations().get(PE).extrapolations().isEmpty());
assertEquals(1, result.valuesAndExtrapolations().get(pe1).extrapolations().size());
assertTrue(result.valuesAndExtrapolations().get(pe1).extrapolations().containsKey(1));
assertEquals((NUM_WINDOWS - 1) * WINDOW_MS, result.valuesAndExtrapolations().get(pe1).window(1));
assertEquals(Extrapolation.AVG_ADJACENT, result.valuesAndExtrapolations().get(pe1).extrapolations().get(1));
}
use of com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.PartitionEntity in project cruise-control by linkedin.
the class KafkaPartitionMetricSampleAggregatorTest method testTooManyFlaws.
@Test
public void testTooManyFlaws() throws NotEnoughValidWindowsException {
KafkaCruiseControlConfig config = new KafkaCruiseControlConfig(getLoadMonitorProperties());
Metadata metadata = getMetadata(Collections.singleton(TP));
KafkaPartitionMetricSampleAggregator metricSampleAggregator = new KafkaPartitionMetricSampleAggregator(config, metadata);
// Only give two samples to the aggregator.
CruiseControlUnitTestUtils.populateSampleAggregator(NUM_WINDOWS - 2, MIN_SAMPLES_PER_WINDOW, metricSampleAggregator, PE, 3, WINDOW_MS, KafkaMetricDef.commonMetricDef());
MetricSampleAggregationResult<String, PartitionEntity> result = metricSampleAggregator.aggregate(metadata.fetch(), NUM_WINDOWS * WINDOW_MS, new OperationProgress());
// Partition "topic-0" is expected to be a valid partition in result, with valid sample values collected for window [1, NUM_WINDOW - 3].
assertEquals(NUM_WINDOWS - 3, result.valuesAndExtrapolations().get(PE).windows().size());
}
Aggregations