use of com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigResolver in project cruise-control by linkedin.
the class PrometheusMetricSamplerTest method addCapacityConfig.
private void addCapacityConfig(Map<String, Object> config) throws IOException {
File capacityConfigFile = File.createTempFile("capacityConfig", "json");
FileOutputStream fileOutputStream = new FileOutputStream(capacityConfigFile);
try (OutputStreamWriter writer = new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8)) {
writer.write("{\n" + " \"brokerCapacities\":[\n" + " {\n" + " \"brokerId\": \"-1\",\n" + " \"capacity\": {\n" + " \"DISK\": \"100000\",\n" + " \"CPU\": {\"num.cores\": \"4\"},\n" + " \"NW_IN\": \"5000000\",\n" + " \"NW_OUT\": \"5000000\"\n" + " }\n" + " }\n" + " ]\n" + "}\n");
}
config.put("capacity.config.file", capacityConfigFile.getAbsolutePath());
BrokerCapacityConfigResolver brokerCapacityConfigResolver = new BrokerCapacityConfigFileResolver();
config.put("broker.capacity.config.resolver.object", brokerCapacityConfigResolver);
config.put("sampling.allow.cpu.capacity.estimation", true);
brokerCapacityConfigResolver.configure(config);
}
use of com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigResolver in project cruise-control by linkedin.
the class CruiseControlMetricsProcessorTest method testWithCpuCapacityEstimation.
@Test
public void testWithCpuCapacityEstimation() throws TimeoutException, BrokerCapacityResolutionException {
Set<CruiseControlMetric> metrics = getCruiseControlMetrics();
// All estimated.
BrokerCapacityConfigResolver brokerCapacityConfigResolverAllEstimated = EasyMock.mock(BrokerCapacityConfigResolver.class);
EasyMock.expect(brokerCapacityConfigResolverAllEstimated.capacityForBroker(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyInt(), EasyMock.anyLong(), EasyMock.eq(false))).andThrow(new BrokerCapacityResolutionException("Unable to resolve capacity.")).anyTimes();
EasyMock.replay(brokerCapacityConfigResolverAllEstimated);
CruiseControlMetricsProcessor processor = new CruiseControlMetricsProcessor(brokerCapacityConfigResolverAllEstimated, false);
for (CruiseControlMetric cruiseControlMetric : metrics) {
processor.addMetric(cruiseControlMetric);
}
Cluster cluster = getCluster();
processor.process(cluster, TEST_PARTITIONS, MetricSampler.SamplingMode.ALL);
for (Node node : cluster.nodes()) {
assertNull(processor.cachedNumCoresByBroker().get(node.id()));
}
// Capacity resolver unable to retrieve broker capacity.
BrokerCapacityConfigResolver brokerCapacityConfigResolverTimeout = EasyMock.mock(BrokerCapacityConfigResolver.class);
EasyMock.expect(brokerCapacityConfigResolverTimeout.capacityForBroker(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyInt(), EasyMock.anyLong(), EasyMock.anyBoolean())).andThrow(new TimeoutException("Unable to resolve capacity.")).anyTimes();
EasyMock.replay(brokerCapacityConfigResolverTimeout);
processor = new CruiseControlMetricsProcessor(brokerCapacityConfigResolverTimeout, false);
for (CruiseControlMetric cruiseControlMetric : metrics) {
processor.addMetric(cruiseControlMetric);
}
cluster = getCluster();
processor.process(cluster, TEST_PARTITIONS, MetricSampler.SamplingMode.ALL);
for (Node node : cluster.nodes()) {
assertNull(processor.cachedNumCoresByBroker().get(node.id()));
}
// Some estimated.
BrokerCapacityConfigResolver brokerCapacityConfigResolverSomeEstimated = EasyMock.mock(BrokerCapacityConfigResolver.class);
EasyMock.expect(brokerCapacityConfigResolverSomeEstimated.capacityForBroker(EasyMock.anyString(), EasyMock.anyString(), EasyMock.eq(BROKER_ID_1), EasyMock.anyLong(), EasyMock.anyBoolean())).andThrow(new TimeoutException("Unable to resolve capacity.")).anyTimes();
EasyMock.expect(brokerCapacityConfigResolverSomeEstimated.capacityForBroker(EasyMock.anyString(), EasyMock.anyString(), EasyMock.eq(BROKER_ID_0), EasyMock.anyLong(), EasyMock.anyBoolean())).andReturn(new BrokerCapacityInfo(EMPTY_BROKER_CAPACITY, Collections.emptyMap(), MOCK_NUM_CPU_CORES)).anyTimes();
EasyMock.replay(brokerCapacityConfigResolverSomeEstimated);
processor = new CruiseControlMetricsProcessor(brokerCapacityConfigResolverSomeEstimated, false);
for (CruiseControlMetric metric : metrics) {
processor.addMetric(metric);
}
processor.process(cluster, TEST_PARTITIONS, MetricSampler.SamplingMode.ALL);
assertEquals(MOCK_NUM_CPU_CORES, (short) processor.cachedNumCoresByBroker().get(BROKER_ID_0));
assertNull(processor.cachedNumCoresByBroker().get(BROKER_ID_1));
EasyMock.verify(brokerCapacityConfigResolverTimeout, brokerCapacityConfigResolverSomeEstimated, brokerCapacityConfigResolverAllEstimated);
}
use of com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigResolver in project cruise-control by linkedin.
the class AbstractMetricSampler method configure.
@Override
public void configure(Map<String, ?> configs) {
BrokerCapacityConfigResolver capacityResolver = (BrokerCapacityConfigResolver) validateNotNull(configs.get(BROKER_CAPACITY_CONFIG_RESOLVER_OBJECT_CONFIG), "Metrics reporter sampler configuration is missing broker capacity config resolver object.");
boolean allowCpuCapacityEstimation = (Boolean) configs.get(MonitorConfig.SAMPLING_ALLOW_CPU_CAPACITY_ESTIMATION_CONFIG);
_metricsProcessor = new CruiseControlMetricsProcessor(capacityResolver, allowCpuCapacityEstimation);
}
use of com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigResolver in project cruise-control by linkedin.
the class CruiseControlMetricsProcessorTest method testMissingBrokerCapacity.
@Test(expected = IllegalArgumentException.class)
public void testMissingBrokerCapacity() throws TimeoutException, BrokerCapacityResolutionException {
Set<CruiseControlMetric> metrics = getCruiseControlMetrics();
// All estimated.
BrokerCapacityConfigResolver brokerCapacityConfigResolver = EasyMock.mock(BrokerCapacityConfigResolver.class);
EasyMock.expect(brokerCapacityConfigResolver.capacityForBroker(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyInt(), EasyMock.anyLong(), EasyMock.anyBoolean())).andReturn(new BrokerCapacityInfo(Collections.emptyMap(), Collections.emptyMap(), MOCK_NUM_CPU_CORES)).anyTimes();
EasyMock.replay(brokerCapacityConfigResolver);
CruiseControlMetricsProcessor processor = new CruiseControlMetricsProcessor(brokerCapacityConfigResolver, false);
for (CruiseControlMetric cruiseControlMetric : metrics) {
processor.addMetric(cruiseControlMetric);
}
EasyMock.verify(brokerCapacityConfigResolver);
Cluster cluster = getCluster();
processor.process(cluster, TEST_PARTITIONS, MetricSampler.SamplingMode.ALL);
}
use of com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigResolver in project cruise-control by linkedin.
the class CruiseControlMetricsProcessorTest method mockBrokerCapacityConfigResolver.
private static BrokerCapacityConfigResolver mockBrokerCapacityConfigResolver() throws TimeoutException, BrokerCapacityResolutionException {
BrokerCapacityConfigResolver brokerCapacityConfigResolver = EasyMock.mock(BrokerCapacityConfigResolver.class);
EasyMock.expect(brokerCapacityConfigResolver.capacityForBroker(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyInt(), EasyMock.anyLong(), EasyMock.anyBoolean())).andReturn(new BrokerCapacityInfo(EMPTY_BROKER_CAPACITY, Collections.emptyMap(), MOCK_NUM_CPU_CORES)).anyTimes();
EasyMock.replay(brokerCapacityConfigResolver);
return brokerCapacityConfigResolver;
}
Aggregations