Search in sources :

Example 1 with BrokerCapacityConfigResolver

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);
}
Also used : BrokerCapacityConfigFileResolver(com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigFileResolver) FileOutputStream(java.io.FileOutputStream) BrokerCapacityConfigResolver(com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigResolver) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Example 2 with BrokerCapacityConfigResolver

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);
}
Also used : BrokerCapacityResolutionException(com.linkedin.kafka.cruisecontrol.exception.BrokerCapacityResolutionException) CruiseControlMetric(com.linkedin.kafka.cruisecontrol.metricsreporter.metric.CruiseControlMetric) BrokerCapacityInfo(com.linkedin.kafka.cruisecontrol.config.BrokerCapacityInfo) BrokerCapacityConfigResolver(com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigResolver) Node(org.apache.kafka.common.Node) Cluster(org.apache.kafka.common.Cluster) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 3 with BrokerCapacityConfigResolver

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);
}
Also used : BrokerCapacityConfigResolver(com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigResolver)

Example 4 with BrokerCapacityConfigResolver

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);
}
Also used : CruiseControlMetric(com.linkedin.kafka.cruisecontrol.metricsreporter.metric.CruiseControlMetric) BrokerCapacityInfo(com.linkedin.kafka.cruisecontrol.config.BrokerCapacityInfo) BrokerCapacityConfigResolver(com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigResolver) Cluster(org.apache.kafka.common.Cluster) Test(org.junit.Test)

Example 5 with BrokerCapacityConfigResolver

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;
}
Also used : BrokerCapacityInfo(com.linkedin.kafka.cruisecontrol.config.BrokerCapacityInfo) BrokerCapacityConfigResolver(com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigResolver)

Aggregations

BrokerCapacityConfigResolver (com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigResolver)5 BrokerCapacityInfo (com.linkedin.kafka.cruisecontrol.config.BrokerCapacityInfo)3 CruiseControlMetric (com.linkedin.kafka.cruisecontrol.metricsreporter.metric.CruiseControlMetric)2 Cluster (org.apache.kafka.common.Cluster)2 Test (org.junit.Test)2 BrokerCapacityConfigFileResolver (com.linkedin.kafka.cruisecontrol.config.BrokerCapacityConfigFileResolver)1 BrokerCapacityResolutionException (com.linkedin.kafka.cruisecontrol.exception.BrokerCapacityResolutionException)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 TimeoutException (java.util.concurrent.TimeoutException)1 Node (org.apache.kafka.common.Node)1