Search in sources :

Example 11 with PartitionEntity

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);
}
Also used : Extrapolation(com.linkedin.cruisecontrol.monitor.sampling.aggregator.Extrapolation) OperationProgress(com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress) PartitionEntity(com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.PartitionEntity) MonitorUnitTestUtils.getMetadata(com.linkedin.kafka.cruisecontrol.monitor.MonitorUnitTestUtils.getMetadata) Metadata(org.apache.kafka.clients.Metadata) KafkaCruiseControlConfig(com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig) Map(java.util.Map) Test(org.junit.Test)

Example 12 with PartitionEntity

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));
}
Also used : OperationProgress(com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress) PartitionEntity(com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.PartitionEntity) MonitorUnitTestUtils.getMetadata(com.linkedin.kafka.cruisecontrol.monitor.MonitorUnitTestUtils.getMetadata) Metadata(org.apache.kafka.clients.Metadata) Cluster(org.apache.kafka.common.Cluster) MonitorUnitTestUtils.getCluster(com.linkedin.kafka.cruisecontrol.monitor.MonitorUnitTestUtils.getCluster) TopicPartition(org.apache.kafka.common.TopicPartition) MetadataResponse(org.apache.kafka.common.requests.MetadataResponse) KafkaCruiseControlConfig(com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig) Test(org.junit.Test)

Example 13 with PartitionEntity

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());
}
Also used : OperationProgress(com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress) PartitionEntity(com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.PartitionEntity) MonitorUnitTestUtils.getMetadata(com.linkedin.kafka.cruisecontrol.monitor.MonitorUnitTestUtils.getMetadata) Metadata(org.apache.kafka.clients.Metadata) KafkaCruiseControlConfig(com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig) Test(org.junit.Test)

Aggregations

PartitionEntity (com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.PartitionEntity)13 KafkaCruiseControlConfig (com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig)10 MonitorUnitTestUtils.getMetadata (com.linkedin.kafka.cruisecontrol.monitor.MonitorUnitTestUtils.getMetadata)10 Metadata (org.apache.kafka.clients.Metadata)10 OperationProgress (com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress)8 TopicPartition (org.apache.kafka.common.TopicPartition)8 Test (org.junit.Test)7 ValuesAndExtrapolations (com.linkedin.cruisecontrol.monitor.sampling.aggregator.ValuesAndExtrapolations)5 Cluster (org.apache.kafka.common.Cluster)4 Extrapolation (com.linkedin.cruisecontrol.monitor.sampling.aggregator.Extrapolation)3 MetadataClient (com.linkedin.kafka.cruisecontrol.common.MetadataClient)3 Map (java.util.Map)3 Resource (com.linkedin.kafka.cruisecontrol.common.Resource)2 MonitorUnitTestUtils.getCluster (com.linkedin.kafka.cruisecontrol.monitor.MonitorUnitTestUtils.getCluster)2 MetadataResponse (org.apache.kafka.common.requests.MetadataResponse)2 Timer (com.codahale.metrics.Timer)1 NotEnoughValidWindowsException (com.linkedin.cruisecontrol.exception.NotEnoughValidWindowsException)1 MetricDef (com.linkedin.cruisecontrol.metricdef.MetricDef)1 GeneratingClusterModel (com.linkedin.kafka.cruisecontrol.async.progress.GeneratingClusterModel)1 WaitingForClusterModel (com.linkedin.kafka.cruisecontrol.async.progress.WaitingForClusterModel)1