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
}
}
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;
}
Aggregations