Search in sources :

Example 11 with PartitionEntity

use of com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity in project cruise-control by linkedin.

the class KafkaMetricSampleAggregatorTest method testExcludeInvalidMetricSample.

@Test
public void testExcludeInvalidMetricSample() throws NotEnoughValidWindowsException {
    KafkaCruiseControlConfig config = new KafkaCruiseControlConfig(getLoadMonitorProperties());
    Metadata metadata = getMetadata(Collections.singleton(TP));
    KafkaMetricSampleAggregator metricSampleAggregator = new KafkaMetricSampleAggregator(config, metadata);
    MetricDef metricDef = KafkaCruiseControlMetricDef.metricDef();
    populateSampleAggregator(NUM_WINDOWS + 1, MIN_SAMPLES_PER_WINDOW, metricSampleAggregator);
    // Set the leader to be node 1, which is different from the leader in the metadata.
    PartitionMetricSample sampleWithDifferentLeader = new PartitionMetricSample(1, TP);
    sampleWithDifferentLeader.record(metricDef.metricInfo(DISK_USAGE.name()), 10000);
    sampleWithDifferentLeader.record(metricDef.metricInfo(CPU_USAGE.name()), 10000);
    sampleWithDifferentLeader.record(metricDef.metricInfo(LEADER_BYTES_IN.name()), 10000);
    sampleWithDifferentLeader.record(metricDef.metricInfo(LEADER_BYTES_OUT.name()), 10000);
    sampleWithDifferentLeader.close(0);
    // Only populate the CPU metric
    PartitionMetricSample incompletePartitionMetricSample = new PartitionMetricSample(0, TP);
    incompletePartitionMetricSample.record(metricDef.metricInfo(CPU_USAGE.name()), 10000);
    incompletePartitionMetricSample.close(0);
    metricSampleAggregator.addSample(sampleWithDifferentLeader);
    metricSampleAggregator.addSample(incompletePartitionMetricSample);
    // Check the snapshot value and make sure the metric samples above are excluded.
    Map<PartitionEntity, ValuesAndExtrapolations> snapshotsForPartition = metricSampleAggregator.aggregate(clusterAndGeneration(metadata.fetch()), NUM_WINDOWS * WINDOW_MS, new OperationProgress()).valuesAndExtrapolations();
    ValuesAndExtrapolations snapshots = snapshotsForPartition.get(PE);
    for (Resource resource : Resource.values()) {
        int metricId = KafkaCruiseControlMetricDef.resourceToMetricId(resource);
        double expectedValue = resource == Resource.DISK ? MIN_SAMPLES_PER_WINDOW - 1 : (MIN_SAMPLES_PER_WINDOW - 1) / 2.0;
        assertEquals("The utilization for " + resource + " should be " + expectedValue, expectedValue, snapshots.metricValues().valuesFor(metricId).get(NUM_WINDOWS - 1), 0);
    }
}
Also used : ValuesAndExtrapolations(com.linkedin.cruisecontrol.monitor.sampling.aggregator.ValuesAndExtrapolations) OperationProgress(com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress) PartitionEntity(com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity) Metadata(org.apache.kafka.clients.Metadata) KafkaCruiseControlMetricDef(com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaCruiseControlMetricDef) MetricDef(com.linkedin.cruisecontrol.metricdef.MetricDef) Resource(com.linkedin.kafka.cruisecontrol.common.Resource) KafkaCruiseControlConfig(com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig) PartitionMetricSample(com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionMetricSample) Test(org.junit.Test)

Example 12 with PartitionEntity

use of com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity in project cruise-control by linkedin.

the class KafkaMetricSampleAggregatorTest method testTooManyFlaws.

@Test
public void testTooManyFlaws() throws NotEnoughValidWindowsException {
    KafkaCruiseControlConfig config = new KafkaCruiseControlConfig(getLoadMonitorProperties());
    Metadata metadata = getMetadata(Collections.singleton(TP));
    KafkaMetricSampleAggregator metricSampleAggregator = new KafkaMetricSampleAggregator(config, metadata);
    // Only give two samples to the aggregator.
    CruiseControlUnitTestUtils.populateSampleAggregator(NUM_WINDOWS - 2, MIN_SAMPLES_PER_WINDOW, metricSampleAggregator, PE, 3, WINDOW_MS, KafkaCruiseControlMetricDef.metricDef());
    MetricSampleAggregationResult<String, PartitionEntity> result = metricSampleAggregator.aggregate(clusterAndGeneration(metadata.fetch()), NUM_WINDOWS * WINDOW_MS, new OperationProgress());
    assertTrue(result.valuesAndExtrapolations().isEmpty());
}
Also used : OperationProgress(com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress) PartitionEntity(com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity) Metadata(org.apache.kafka.clients.Metadata) KafkaCruiseControlConfig(com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig) Test(org.junit.Test)

Example 13 with PartitionEntity

use of com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity in project cruise-control by linkedin.

the class KafkaMetricSampleAggregator method allPartitions.

private Set<PartitionEntity> allPartitions(Cluster cluster) {
    Set<PartitionEntity> allPartitions = new HashSet<>();
    for (Node node : cluster.nodes()) {
        for (PartitionInfo partitionInfo : cluster.partitionsForNode(node.id())) {
            TopicPartition tp = new TopicPartition(partitionInfo.topic(), partitionInfo.partition());
            PartitionEntity partitionEntity = new PartitionEntity(tp);
            allPartitions.add(_identityEntityMap.computeIfAbsent(partitionEntity, k -> partitionEntity));
        }
    }
    return allPartitions;
}
Also used : NotEnoughValidWindowsException(com.linkedin.cruisecontrol.exception.NotEnoughValidWindowsException) SortedSet(java.util.SortedSet) RetrievingMetrics(com.linkedin.kafka.cruisecontrol.async.progress.RetrievingMetrics) MetricSampleAggregator(com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricSampleAggregator) Metadata(org.apache.kafka.clients.Metadata) LoggerFactory(org.slf4j.LoggerFactory) MetricSampleAggregationResult(com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricSampleAggregationResult) KafkaCruiseControlMetricDef(com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaCruiseControlMetricDef) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) KafkaCruiseControlConfig(com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig) MetadataClient(com.linkedin.kafka.cruisecontrol.common.MetadataClient) Cluster(org.apache.kafka.common.Cluster) PartitionMetricSample(com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionMetricSample) TopicPartition(org.apache.kafka.common.TopicPartition) Logger(org.slf4j.Logger) Set(java.util.Set) PartitionInfo(org.apache.kafka.common.PartitionInfo) OperationProgress(com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress) AggregationOptions(com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregationOptions) MetricSampleCompleteness(com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricSampleCompleteness) TreeMap(java.util.TreeMap) PartitionEntity(com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity) Node(org.apache.kafka.common.Node) Collections(java.util.Collections) SortedMap(java.util.SortedMap) ModelCompletenessRequirements(com.linkedin.kafka.cruisecontrol.monitor.ModelCompletenessRequirements) PartitionEntity(com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity) TopicPartition(org.apache.kafka.common.TopicPartition) Node(org.apache.kafka.common.Node) PartitionInfo(org.apache.kafka.common.PartitionInfo) HashSet(java.util.HashSet)

Example 14 with PartitionEntity

use of com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity in project cruise-control by linkedin.

the class LoadMonitor method getMonitoredPartitionsPercentage.

private double getMonitoredPartitionsPercentage() {
    MetadataClient.ClusterAndGeneration clusterAndGeneration = _metadataClient.refreshMetadata();
    Cluster kafkaCluster = clusterAndGeneration.cluster();
    MetricSampleAggregationResult<String, PartitionEntity> metricSampleAggregationResult;
    try {
        metricSampleAggregationResult = _metricSampleAggregator.aggregate(clusterAndGeneration, System.currentTimeMillis(), new OperationProgress());
    } catch (NotEnoughValidWindowsException e) {
        return 0.0;
    }
    Map<PartitionEntity, ValuesAndExtrapolations> partitionLoads = metricSampleAggregationResult.valuesAndExtrapolations();
    AtomicInteger numPartitionsWithExtrapolations = new AtomicInteger(0);
    partitionLoads.values().forEach(valuesAndExtrapolations -> {
        if (!valuesAndExtrapolations.extrapolations().isEmpty()) {
            numPartitionsWithExtrapolations.incrementAndGet();
        }
    });
    _numPartitionsWithExtrapolations = numPartitionsWithExtrapolations.get();
    int totalNumPartitions = MonitorUtils.totalNumPartitions(kafkaCluster);
    return totalNumPartitions > 0 ? metricSampleAggregationResult.completeness().validEntityRatio() : 0.0;
}
Also used : MetadataClient(com.linkedin.kafka.cruisecontrol.common.MetadataClient) ValuesAndExtrapolations(com.linkedin.cruisecontrol.monitor.sampling.aggregator.ValuesAndExtrapolations) OperationProgress(com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionEntity(com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity) Cluster(org.apache.kafka.common.Cluster) NotEnoughValidWindowsException(com.linkedin.cruisecontrol.exception.NotEnoughValidWindowsException)

Aggregations

PartitionEntity (com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity)14 KafkaCruiseControlConfig (com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig)11 Metadata (org.apache.kafka.clients.Metadata)11 OperationProgress (com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress)9 TopicPartition (org.apache.kafka.common.TopicPartition)9 Test (org.junit.Test)7 ValuesAndExtrapolations (com.linkedin.cruisecontrol.monitor.sampling.aggregator.ValuesAndExtrapolations)6 Cluster (org.apache.kafka.common.Cluster)5 Extrapolation (com.linkedin.cruisecontrol.monitor.sampling.aggregator.Extrapolation)4 MetadataClient (com.linkedin.kafka.cruisecontrol.common.MetadataClient)4 NotEnoughValidWindowsException (com.linkedin.cruisecontrol.exception.NotEnoughValidWindowsException)3 Map (java.util.Map)3 Resource (com.linkedin.kafka.cruisecontrol.common.Resource)2 ModelCompletenessRequirements (com.linkedin.kafka.cruisecontrol.monitor.ModelCompletenessRequirements)2 KafkaCruiseControlMetricDef (com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaCruiseControlMetricDef)2 PartitionMetricSample (com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionMetricSample)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SortedMap (java.util.SortedMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2