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