use of com.linkedin.kafka.cruisecontrol.metricsreporter.metric.CruiseControlMetric 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.metricsreporter.metric.CruiseControlMetric in project cruise-control by linkedin.
the class CruiseControlMetricsProcessorTest method testMissingOtherBrokerMetrics.
@Test
public void testMissingOtherBrokerMetrics() throws TimeoutException, BrokerCapacityResolutionException {
CruiseControlMetricsProcessor processor = new CruiseControlMetricsProcessor(mockBrokerCapacityConfigResolver(), false);
Set<CruiseControlMetric> metrics = getCruiseControlMetrics();
Cluster cluster = getCluster();
for (CruiseControlMetric metric : metrics) {
if (metric.rawMetricType() == RawMetricType.BROKER_CONSUMER_FETCH_LOCAL_TIME_MS_MAX && metric.brokerId() == BROKER_ID_0) {
// Do nothing and skip the metric.
} else {
processor.addMetric(metric);
}
}
MetricSampler.Samples samples = processor.process(cluster, TEST_PARTITIONS, MetricSampler.SamplingMode.ALL);
assertEquals("Should have all 4 partition metrics.", 4, samples.partitionMetricSamples().size());
assertEquals("Should have ignored broker 0", 1, samples.brokerMetricSamples().size());
}
use of com.linkedin.kafka.cruisecontrol.metricsreporter.metric.CruiseControlMetric in project cruise-control by linkedin.
the class CruiseControlMetricsProcessorTest method testMissingBrokerCpuUtilization.
@Test
public void testMissingBrokerCpuUtilization() throws TimeoutException, BrokerCapacityResolutionException {
CruiseControlMetricsProcessor processor = new CruiseControlMetricsProcessor(mockBrokerCapacityConfigResolver(), false);
Set<CruiseControlMetric> metrics = getCruiseControlMetrics();
for (CruiseControlMetric metric : metrics) {
if (metric.rawMetricType() == RawMetricType.BROKER_CPU_UTIL && metric.brokerId() == BROKER_ID_0) {
// Do nothing and skip the metric.
} else {
processor.addMetric(metric);
}
}
Cluster cluster = getCluster();
MetricSampler.Samples samples = processor.process(cluster, TEST_PARTITIONS, MetricSampler.SamplingMode.ALL);
assertEquals("Should have ignored partitions on broker 0", 1, samples.partitionMetricSamples().size());
assertEquals("Should have ignored broker 0", 1, samples.brokerMetricSamples().size());
}
use of com.linkedin.kafka.cruisecontrol.metricsreporter.metric.CruiseControlMetric in project cruise-control by linkedin.
the class CruiseControlMetricsProcessorTest method testMissingPartitionSizeMetric.
@Test
public void testMissingPartitionSizeMetric() throws TimeoutException, BrokerCapacityResolutionException {
CruiseControlMetricsProcessor processor = new CruiseControlMetricsProcessor(mockBrokerCapacityConfigResolver(), false);
Set<CruiseControlMetric> metrics = getCruiseControlMetrics();
for (CruiseControlMetric metric : metrics) {
boolean shouldAdd = true;
if (metric.rawMetricType() == RawMetricType.PARTITION_SIZE) {
PartitionMetric pm = (PartitionMetric) metric;
if (pm.topic().equals(TOPIC1) && pm.partition() == P0) {
shouldAdd = false;
}
}
if (shouldAdd) {
processor.addMetric(metric);
}
}
Cluster cluster = getCluster();
MetricSampler.Samples samples = processor.process(cluster, TEST_PARTITIONS, MetricSampler.SamplingMode.ALL);
assertEquals("Should have ignored partition " + T1P0, 3, samples.partitionMetricSamples().size());
assertEquals("Should have reported both brokers", 2, samples.brokerMetricSamples().size());
}
use of com.linkedin.kafka.cruisecontrol.metricsreporter.metric.CruiseControlMetric in project cruise-control by linkedin.
the class CruiseControlMetricsProcessorTest method testBasic.
@Test
public void testBasic() throws TimeoutException, BrokerCapacityResolutionException {
CruiseControlMetricsProcessor processor = new CruiseControlMetricsProcessor(mockBrokerCapacityConfigResolver(), false);
Set<CruiseControlMetric> metrics = getCruiseControlMetrics();
Cluster cluster = getCluster();
metrics.forEach(processor::addMetric);
MetricSampler.Samples samples = processor.process(cluster, TEST_PARTITIONS, MetricSampler.SamplingMode.ALL);
for (Node node : cluster.nodes()) {
assertEquals(MOCK_NUM_CPU_CORES, (short) processor.cachedNumCoresByBroker().get(node.id()));
}
assertEquals(4, samples.partitionMetricSamples().size());
assertEquals(2, samples.brokerMetricSamples().size());
for (PartitionMetricSample sample : samples.partitionMetricSamples()) {
if (sample.entity().tp().equals(T1P0)) {
validatePartitionMetricSample(sample, _time.milliseconds() + 2, CPU_UTIL.get(T1P0), B0_TOPIC1_BYTES_IN, B0_TOPIC1_BYTES_OUT, T1P0_BYTES_SIZE);
} else if (sample.entity().tp().equals(T1P1)) {
validatePartitionMetricSample(sample, _time.milliseconds() + 2, CPU_UTIL.get(T1P1), B1_TOPIC1_BYTES_IN, B1_TOPIC1_BYTES_OUT, T1P1_BYTES_SIZE);
} else if (sample.entity().tp().equals(T2P0)) {
validatePartitionMetricSample(sample, _time.milliseconds() + 2, CPU_UTIL.get(T2P0), B0_TOPIC2_BYTES_IN / 2, B0_TOPIC2_BYTES_OUT / 2, T2P0_BYTES_SIZE);
} else if (sample.entity().tp().equals(T2P1)) {
validatePartitionMetricSample(sample, _time.milliseconds() + 2, CPU_UTIL.get(T2P1), B0_TOPIC2_BYTES_IN / 2, B0_TOPIC2_BYTES_OUT / 2, T2P1_BYTES_SIZE);
} else {
fail("Should never have partition " + sample.entity().tp());
}
}
for (BrokerMetricSample sample : samples.brokerMetricSamples()) {
if (sample.metricValue(CPU_USAGE) == B0_CPU) {
assertEquals(B0_TOPIC1_REPLICATION_BYTES_IN, sample.metricValue(REPLICATION_BYTES_IN_RATE), DELTA);
} else if (sample.metricValue(CPU_USAGE) == B1_CPU) {
assertEquals(B1_TOPIC1_REPLICATION_BYTES_IN + B1_TOPIC2_REPLICATION_BYTES_IN, sample.metricValue(REPLICATION_BYTES_IN_RATE), DELTA);
} else {
fail("Should never have broker cpu util " + sample.metricValue(CPU_USAGE));
}
}
assertFalse(samples.partitionMetricSamples().isEmpty());
}
Aggregations