Search in sources :

Example 1 with MetricDef

use of com.linkedin.cruisecontrol.metricdef.MetricDef in project cruise-control by linkedin.

the class PartitionMetricSampleTest method testSerde.

@Test
public void testSerde() throws UnknownVersionException {
    MetricDef metricDef = KafkaCruiseControlMetricDef.metricDef();
    PartitionMetricSample sample = new PartitionMetricSample(0, new TopicPartition("topic", 0));
    int i = 0;
    for (Resource r : Resource.values()) {
        sample.record(KafkaCruiseControlMetricDef.resourceToMetricInfo(r), i);
        i++;
    }
    sample.record(metricDef.metricInfo(PRODUCE_RATE.name()), (double) i++);
    sample.record(metricDef.metricInfo(FETCH_RATE.name()), (double) i++);
    sample.record(metricDef.metricInfo(MESSAGE_IN_RATE.name()), (double) i++);
    sample.record(metricDef.metricInfo(REPLICATION_BYTES_IN_RATE.name()), (double) i++);
    sample.record(metricDef.metricInfo(REPLICATION_BYTES_OUT_RATE.name()), (double) i);
    sample.close(10);
    byte[] bytes = sample.toBytes();
    PartitionMetricSample deserializedSample = PartitionMetricSample.fromBytes(bytes);
    assertEquals(sample.brokerId(), deserializedSample.brokerId());
    assertEquals(sample.entity().tp(), deserializedSample.entity().tp());
    assertEquals(sample.metricValue(KafkaCruiseControlMetricDef.resourceToMetricId(Resource.CPU)), deserializedSample.metricValue(KafkaCruiseControlMetricDef.resourceToMetricId(Resource.CPU)));
    assertEquals(sample.metricValue(KafkaCruiseControlMetricDef.resourceToMetricId(Resource.DISK)), deserializedSample.metricValue(KafkaCruiseControlMetricDef.resourceToMetricId(Resource.DISK)));
    assertEquals(sample.metricValue(KafkaCruiseControlMetricDef.resourceToMetricId(Resource.NW_IN)), deserializedSample.metricValue(KafkaCruiseControlMetricDef.resourceToMetricId(Resource.NW_IN)));
    assertEquals(sample.metricValue(KafkaCruiseControlMetricDef.resourceToMetricId(Resource.NW_OUT)), deserializedSample.metricValue(KafkaCruiseControlMetricDef.resourceToMetricId(Resource.NW_OUT)));
    assertEquals(sample.metricValue(metricDef.metricInfo(PRODUCE_RATE.name()).id()), deserializedSample.metricValue(metricDef.metricInfo(PRODUCE_RATE.name()).id()), EPSILON);
    assertEquals(sample.metricValue(metricDef.metricInfo(FETCH_RATE.name()).id()), deserializedSample.metricValue(metricDef.metricInfo(FETCH_RATE.name()).id()), EPSILON);
    assertEquals(sample.metricValue(metricDef.metricInfo(MESSAGE_IN_RATE.name()).id()), deserializedSample.metricValue(metricDef.metricInfo(MESSAGE_IN_RATE.name()).id()), EPSILON);
    assertEquals(sample.metricValue(metricDef.metricInfo(REPLICATION_BYTES_IN_RATE.name()).id()), deserializedSample.metricValue(metricDef.metricInfo(REPLICATION_BYTES_IN_RATE.name()).id()), EPSILON);
    assertEquals(sample.metricValue(metricDef.metricInfo(REPLICATION_BYTES_OUT_RATE.name()).id()), deserializedSample.metricValue(metricDef.metricInfo(REPLICATION_BYTES_OUT_RATE.name()).id()), EPSILON);
    assertEquals(sample.sampleTime(), deserializedSample.sampleTime());
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) MetricDef(com.linkedin.cruisecontrol.metricdef.MetricDef) KafkaCruiseControlMetricDef(com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaCruiseControlMetricDef) Resource(com.linkedin.kafka.cruisecontrol.common.Resource) Test(org.junit.Test)

Example 2 with MetricDef

use of com.linkedin.cruisecontrol.metricdef.MetricDef in project cruise-control by linkedin.

the class PartitionMetricSample method toString.

@Override
public String toString() {
    MetricDef metricDef = KafkaCruiseControlMetricDef.metricDef();
    StringBuilder builder = new StringBuilder().append("{");
    for (Map.Entry<Integer, Double> entry : _valuesByMetricId.entrySet()) {
        builder.append(metricDef.metricInfo(entry.getKey()).name()).append("=").append(entry.getValue().toString()).append(", ");
    }
    builder.delete(builder.length() - 2, builder.length()).append("}");
    return String.format("[brokerId: %d, Partition: %s, time: %s, metrics: %s]", _brokerId, entity().tp(), new Date(_sampleTime), builder.toString());
}
Also used : KafkaCruiseControlMetricDef(com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaCruiseControlMetricDef) MetricDef(com.linkedin.cruisecontrol.metricdef.MetricDef) Map(java.util.Map) Date(java.util.Date)

Example 3 with MetricDef

use of com.linkedin.cruisecontrol.metricdef.MetricDef in project cruise-control by linkedin.

the class KafkaMetricSampleAggregatorTest method testExcludeInvalidMetricSample.

@Test
public void testExcludeInvalidMetricSample() throws NotEnoughValidWindowsException {
    KafkaCruiseControlConfig config = new KafkaCruiseControlConfig(getLoadMonitorProperties());
    Metadata metadata = getMetadata(Collections.singleton(TP));
    KafkaMetricSampleAggregator metricSampleAggregator = new KafkaMetricSampleAggregator(config, metadata);
    MetricDef metricDef = KafkaCruiseControlMetricDef.metricDef();
    populateSampleAggregator(NUM_WINDOWS + 1, MIN_SAMPLES_PER_WINDOW, metricSampleAggregator);
    // Set the leader to be node 1, which is different from the leader in the metadata.
    PartitionMetricSample sampleWithDifferentLeader = new PartitionMetricSample(1, TP);
    sampleWithDifferentLeader.record(metricDef.metricInfo(DISK_USAGE.name()), 10000);
    sampleWithDifferentLeader.record(metricDef.metricInfo(CPU_USAGE.name()), 10000);
    sampleWithDifferentLeader.record(metricDef.metricInfo(LEADER_BYTES_IN.name()), 10000);
    sampleWithDifferentLeader.record(metricDef.metricInfo(LEADER_BYTES_OUT.name()), 10000);
    sampleWithDifferentLeader.close(0);
    // Only populate the CPU metric
    PartitionMetricSample incompletePartitionMetricSample = new PartitionMetricSample(0, TP);
    incompletePartitionMetricSample.record(metricDef.metricInfo(CPU_USAGE.name()), 10000);
    incompletePartitionMetricSample.close(0);
    metricSampleAggregator.addSample(sampleWithDifferentLeader);
    metricSampleAggregator.addSample(incompletePartitionMetricSample);
    // Check the snapshot value and make sure the metric samples above are excluded.
    Map<PartitionEntity, ValuesAndExtrapolations> snapshotsForPartition = metricSampleAggregator.aggregate(clusterAndGeneration(metadata.fetch()), NUM_WINDOWS * WINDOW_MS, new OperationProgress()).valuesAndExtrapolations();
    ValuesAndExtrapolations snapshots = snapshotsForPartition.get(PE);
    for (Resource resource : Resource.values()) {
        int metricId = KafkaCruiseControlMetricDef.resourceToMetricId(resource);
        double expectedValue = resource == Resource.DISK ? MIN_SAMPLES_PER_WINDOW - 1 : (MIN_SAMPLES_PER_WINDOW - 1) / 2.0;
        assertEquals("The utilization for " + resource + " should be " + expectedValue, expectedValue, snapshots.metricValues().valuesFor(metricId).get(NUM_WINDOWS - 1), 0);
    }
}
Also used : ValuesAndExtrapolations(com.linkedin.cruisecontrol.monitor.sampling.aggregator.ValuesAndExtrapolations) OperationProgress(com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress) PartitionEntity(com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity) Metadata(org.apache.kafka.clients.Metadata) KafkaCruiseControlMetricDef(com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaCruiseControlMetricDef) MetricDef(com.linkedin.cruisecontrol.metricdef.MetricDef) Resource(com.linkedin.kafka.cruisecontrol.common.Resource) KafkaCruiseControlConfig(com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig) PartitionMetricSample(com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionMetricSample) Test(org.junit.Test)

Example 4 with MetricDef

use of com.linkedin.cruisecontrol.metricdef.MetricDef in project cruise-control by linkedin.

the class PartitionMetricSample method readV0.

private static PartitionMetricSample readV0(ByteBuffer buffer) {
    MetricDef metricDef = KafkaCruiseControlMetricDef.metricDef();
    int brokerId = buffer.getInt();
    int partition = buffer.getInt(45);
    String topic = new String(buffer.array(), 49, buffer.array().length - 49, UTF_8);
    PartitionMetricSample sample = new PartitionMetricSample(brokerId, new TopicPartition(topic, partition));
    sample.record(metricDef.metricInfo(CPU_USAGE.name()), buffer.getDouble());
    sample.record(metricDef.metricInfo(DISK_USAGE.name()), buffer.getDouble());
    sample.record(metricDef.metricInfo(LEADER_BYTES_IN.name()), buffer.getDouble());
    sample.record(metricDef.metricInfo(LEADER_BYTES_OUT.name()), buffer.getDouble());
    sample.close(buffer.getLong());
    return sample;
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) KafkaCruiseControlMetricDef(com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaCruiseControlMetricDef) MetricDef(com.linkedin.cruisecontrol.metricdef.MetricDef)

Example 5 with MetricDef

use of com.linkedin.cruisecontrol.metricdef.MetricDef in project cruise-control by linkedin.

the class PartitionMetricSample method readV1.

private static PartitionMetricSample readV1(ByteBuffer buffer) {
    MetricDef metricDef = KafkaCruiseControlMetricDef.metricDef();
    int brokerId = buffer.getInt();
    int partition = buffer.getInt(85);
    String topic = new String(buffer.array(), 89, buffer.array().length - 89, UTF_8);
    PartitionMetricSample sample = new PartitionMetricSample(brokerId, new TopicPartition(topic, partition));
    sample.record(metricDef.metricInfo(CPU_USAGE.name()), buffer.getDouble());
    sample.record(metricDef.metricInfo(DISK_USAGE.name()), buffer.getDouble());
    sample.record(metricDef.metricInfo(LEADER_BYTES_IN.name()), buffer.getDouble());
    sample.record(metricDef.metricInfo(LEADER_BYTES_OUT.name()), buffer.getDouble());
    sample.record(metricDef.metricInfo(PRODUCE_RATE.name()), buffer.getDouble());
    sample.record(metricDef.metricInfo(FETCH_RATE.name()), buffer.getDouble());
    sample.record(metricDef.metricInfo(MESSAGE_IN_RATE.name()), buffer.getDouble());
    sample.record(metricDef.metricInfo(REPLICATION_BYTES_IN_RATE.name()), buffer.getDouble());
    sample.record(metricDef.metricInfo(REPLICATION_BYTES_OUT_RATE.name()), buffer.getDouble());
    sample.close(buffer.getLong());
    return sample;
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) KafkaCruiseControlMetricDef(com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaCruiseControlMetricDef) MetricDef(com.linkedin.cruisecontrol.metricdef.MetricDef)

Aggregations

MetricDef (com.linkedin.cruisecontrol.metricdef.MetricDef)7 KafkaCruiseControlMetricDef (com.linkedin.kafka.cruisecontrol.monitor.metricdefinition.KafkaCruiseControlMetricDef)7 TopicPartition (org.apache.kafka.common.TopicPartition)3 Resource (com.linkedin.kafka.cruisecontrol.common.Resource)2 Test (org.junit.Test)2 MetricInfo (com.linkedin.cruisecontrol.metricdef.MetricInfo)1 AggregatedMetricValues (com.linkedin.cruisecontrol.monitor.sampling.aggregator.AggregatedMetricValues)1 MetricValues (com.linkedin.cruisecontrol.monitor.sampling.aggregator.MetricValues)1 ValuesAndExtrapolations (com.linkedin.cruisecontrol.monitor.sampling.aggregator.ValuesAndExtrapolations)1 OperationProgress (com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress)1 KafkaCruiseControlConfig (com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig)1 PartitionEntity (com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity)1 PartitionMetricSample (com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionMetricSample)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Metadata (org.apache.kafka.clients.Metadata)1