Search in sources :

Example 6 with ModelCompletenessRequirements

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

the class KafkaMetricSampleAggregatorTest method testNotEnoughSnapshots.

@Test
public void testNotEnoughSnapshots() {
    KafkaCruiseControlConfig config = new KafkaCruiseControlConfig(getLoadMonitorProperties());
    Metadata metadata = getMetadata(Collections.singleton(TP));
    KafkaMetricSampleAggregator metricSampleAggregator = new KafkaMetricSampleAggregator(config, metadata);
    populateSampleAggregator(NUM_WINDOWS + 1, MIN_SAMPLES_PER_WINDOW, metricSampleAggregator);
    try {
        // Only 4 snapshots has smaller timestamp than the timestamp we passed in.
        ModelCompletenessRequirements requirements = new ModelCompletenessRequirements(NUM_WINDOWS, 0.0, false);
        metricSampleAggregator.aggregate(clusterAndGeneration(metadata.fetch()), -1L, (NUM_WINDOWS - 1) * WINDOW_MS - 1, requirements, new OperationProgress());
        fail("Should throw NotEnoughValidWindowsException");
    } catch (NotEnoughValidWindowsException nse) {
    // let it go
    }
}
Also used : OperationProgress(com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress) Metadata(org.apache.kafka.clients.Metadata) KafkaCruiseControlConfig(com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig) ModelCompletenessRequirements(com.linkedin.kafka.cruisecontrol.monitor.ModelCompletenessRequirements) NotEnoughValidWindowsException(com.linkedin.cruisecontrol.exception.NotEnoughValidWindowsException) Test(org.junit.Test)

Example 7 with ModelCompletenessRequirements

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

the class KafkaCruiseControl method getOptimizationProposals.

/**
 * Optimize a cluster workload model.
 * @param goals a list of goals to optimize. When empty all goals will be used.
 * @param requirements the model completeness requirements to enforce when generating the propsoals.
 * @param operationProgress the progress of the job to report.
 * @return The optimization result.
 * @throws KafkaCruiseControlException
 */
public GoalOptimizer.OptimizerResult getOptimizationProposals(List<String> goals, ModelCompletenessRequirements requirements, OperationProgress operationProgress) throws KafkaCruiseControlException {
    GoalOptimizer.OptimizerResult result;
    Map<Integer, Goal> goalsByPriority = goalsByPriority(goals);
    ModelCompletenessRequirements modelCompletenessRequirements = modelCompletenessRequirements(goalsByPriority.values()).weaker(requirements);
    // There are a few cases that we cannot use the cached best proposals:
    // 1. When users specified goals.
    // 2. When provided requirements contains a weaker requirement than what is used by the cached proposal.
    ModelCompletenessRequirements requirementsForCache = _goalOptimizer.modelCompletenessRequirementsForPrecomputing();
    boolean hasWeakerRequirement = requirementsForCache.minMonitoredPartitionsPercentage() > modelCompletenessRequirements.minMonitoredPartitionsPercentage() || requirementsForCache.minRequiredNumWindows() > modelCompletenessRequirements.minRequiredNumWindows() || (requirementsForCache.includeAllTopics() && !modelCompletenessRequirements.includeAllTopics());
    if ((goals != null && !goals.isEmpty()) || hasWeakerRequirement) {
        try (AutoCloseable ignored = _loadMonitor.acquireForModelGeneration(operationProgress)) {
            // The cached proposals are computed with ignoreMinMonitoredPartitions = true. So if user provided a different
            // setting, we need to generate a new model.
            ClusterModel clusterModel = _loadMonitor.clusterModel(-1, _time.milliseconds(), modelCompletenessRequirements, operationProgress);
            result = getOptimizationProposals(clusterModel, goalsByPriority, operationProgress);
        } catch (KafkaCruiseControlException kcce) {
            throw kcce;
        } catch (Exception e) {
            throw new KafkaCruiseControlException(e);
        }
    } else {
        result = getOptimizationProposals(operationProgress);
    }
    return result;
}
Also used : ClusterModel(com.linkedin.kafka.cruisecontrol.model.ClusterModel) Goal(com.linkedin.kafka.cruisecontrol.analyzer.goals.Goal) GoalOptimizer(com.linkedin.kafka.cruisecontrol.analyzer.GoalOptimizer) KafkaCruiseControlException(com.linkedin.kafka.cruisecontrol.exception.KafkaCruiseControlException) ModelCompletenessRequirements(com.linkedin.kafka.cruisecontrol.monitor.ModelCompletenessRequirements) KafkaCruiseControlException(com.linkedin.kafka.cruisecontrol.exception.KafkaCruiseControlException)

Aggregations

ModelCompletenessRequirements (com.linkedin.kafka.cruisecontrol.monitor.ModelCompletenessRequirements)7 ClusterModel (com.linkedin.kafka.cruisecontrol.model.ClusterModel)5 GoalOptimizer (com.linkedin.kafka.cruisecontrol.analyzer.GoalOptimizer)4 Goal (com.linkedin.kafka.cruisecontrol.analyzer.goals.Goal)4 KafkaCruiseControlException (com.linkedin.kafka.cruisecontrol.exception.KafkaCruiseControlException)3 OperationProgress (com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress)2 KafkaCruiseControlConfig (com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 Cluster (org.apache.kafka.common.Cluster)2 TopicPartition (org.apache.kafka.common.TopicPartition)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1