@Override public ByteBuffer toBuffer(int headerPos) { ByteBuffer buffer = ByteBuffer.allocate(headerPos + 1 /* version */ + 1 /* raw metric type */ + Long.BYTES /* time */ + Integer.BYTES /* broker id */ + Double.BYTES /* value */); buffer.position(headerPos); buffer.put(METRIC_VERSION); buffer.put(rawMetricType().id()); buffer.putLong(time()); buffer.putInt(brokerId()); buffer.putDouble(value()); return buffer; }
public ByteBuffer toBuffer(int headerPos) { byte[] topic = _topic.getBytes(StandardCharsets.UTF_8); ByteBuffer buffer = ByteBuffer.allocate(headerPos + 1 /* version */ + 1 /* raw metric type */ + Long.BYTES /* time */ + Integer.BYTES /* broker id */ + Integer.BYTES /* topic length */ + topic.length /* topic */ + Double.BYTES /* value */); buffer.position(headerPos); buffer.put(METRIC_VERSION); buffer.put(rawMetricType().id()); buffer.putLong(time()); buffer.putInt(brokerId()); buffer.putInt(topic.length); buffer.put(topic); buffer.putDouble(value()); return buffer; }
public ByteBuffer toBuffer(int headerPos) { byte[] topic = topic().getBytes(StandardCharsets.UTF_8); ByteBuffer buffer = ByteBuffer.allocate(headerPos + 1 /* version */ + 1 /* metric type */ + Long.BYTES /* time */ + Integer.BYTES /* broker id */ + Integer.BYTES /* topic length */ + topic.length /* topic */ + Integer.BYTES /* partition */ + Double.BYTES /* value */); buffer.position(headerPos); buffer.put(METRIC_VERSION); buffer.put(rawMetricType().id()); buffer.putLong(time()); buffer.putInt(brokerId()); buffer.putInt(topic.length); buffer.put(topic); buffer.putInt(_partition); buffer.putDouble(value()); return buffer; }
HashSet<Integer> expectedMetricTypes = new HashSet<>(Arrays.asList((int) ALL_TOPIC_BYTES_IN.id(), (int) ALL_TOPIC_BYTES_OUT.id(), (int) TOPIC_BYTES_IN.id(), (int) TOPIC_BYTES_OUT.id(), (int) PARTITION_SIZE.id(), (int) BROKER_CPU_UTIL.id(), (int) ALL_TOPIC_REPLICATION_BYTES_IN.id(), (int) ALL_TOPIC_REPLICATION_BYTES_OUT.id(), (int) ALL_TOPIC_PRODUCE_REQUEST_RATE.id(), (int) ALL_TOPIC_FETCH_REQUEST_RATE.id(), (int) ALL_TOPIC_MESSAGES_IN_PER_SEC.id(), (int) TOPIC_PRODUCE_REQUEST_RATE.id(), (int) TOPIC_FETCH_REQUEST_RATE.id(), (int) TOPIC_MESSAGES_IN_PER_SEC.id(), (int) BROKER_PRODUCE_REQUEST_RATE.id(), (int) BROKER_CONSUMER_FETCH_REQUEST_RATE.id(), (int) BROKER_FOLLOWER_FETCH_REQUEST_RATE.id(), (int) BROKER_REQUEST_HANDLER_AVG_IDLE_PERCENT.id(), (int) BROKER_REQUEST_QUEUE_SIZE.id(), (int) BROKER_RESPONSE_QUEUE_SIZE.id(), (int) BROKER_PRODUCE_REQUEST_QUEUE_TIME_MS_MAX.id(), (int) BROKER_PRODUCE_REQUEST_QUEUE_TIME_MS_MEAN.id(), (int) BROKER_CONSUMER_FETCH_REQUEST_QUEUE_TIME_MS_MAX.id(), (int) BROKER_CONSUMER_FETCH_REQUEST_QUEUE_TIME_MS_MEAN.id(), (int) BROKER_FOLLOWER_FETCH_REQUEST_QUEUE_TIME_MS_MAX.id(), (int) BROKER_FOLLOWER_FETCH_REQUEST_QUEUE_TIME_MS_MEAN.id(), (int) BROKER_PRODUCE_TOTAL_TIME_MS_MAX.id(), (int) BROKER_PRODUCE_TOTAL_TIME_MS_MEAN.id(), (int) BROKER_CONSUMER_FETCH_TOTAL_TIME_MS_MAX.id(),
@Test public void testBrokerMetricSerde() throws UnknownVersionException { BrokerMetric brokerMetric = new BrokerMetric(RawMetricType.ALL_TOPIC_BYTES_IN, 123L, 0, 0.1); CruiseControlMetric deserialized = MetricSerde.fromBytes(MetricSerde.toBytes(brokerMetric)); assertEquals(CruiseControlMetric.MetricClassId.BROKER_METRIC.id(), deserialized.metricClassId().id()); assertEquals(RawMetricType.ALL_TOPIC_BYTES_IN.id(), deserialized.rawMetricType().id()); assertEquals(TIME, deserialized.time()); assertEquals(BROKER_ID, deserialized.brokerId()); assertEquals(VALUE, deserialized.value(), 0.000001); }
@Test public void testTopicMetricSerde() throws UnknownVersionException { TopicMetric topicMetric = new TopicMetric(RawMetricType.TOPIC_BYTES_IN, 123L, 0, TOPIC, 0.1); CruiseControlMetric deserialized = MetricSerde.fromBytes(MetricSerde.toBytes(topicMetric)); assertEquals(CruiseControlMetric.MetricClassId.TOPIC_METRIC.id(), deserialized.metricClassId().id()); assertEquals(RawMetricType.TOPIC_BYTES_IN.id(), deserialized.rawMetricType().id()); assertEquals(TIME, deserialized.time()); assertEquals(BROKER_ID, deserialized.brokerId()); assertEquals(TOPIC, ((TopicMetric) deserialized).topic()); assertEquals(VALUE, deserialized.value(), 0.000001); }
@Test public void testPartitionMetricSerde() throws UnknownVersionException { PartitionMetric partitionMetric = new PartitionMetric(RawMetricType.PARTITION_SIZE, 123L, 0, TOPIC, PARTITION, 0.1); CruiseControlMetric deserialized = MetricSerde.fromBytes(MetricSerde.toBytes(partitionMetric)); assertEquals(CruiseControlMetric.MetricClassId.PARTITION_METRIC.id(), deserialized.metricClassId().id()); assertEquals(RawMetricType.PARTITION_SIZE.id(), deserialized.rawMetricType().id()); assertEquals(TIME, deserialized.time()); assertEquals(BROKER_ID, deserialized.brokerId()); assertEquals(TOPIC, ((PartitionMetric) deserialized).topic()); assertEquals(PARTITION, ((PartitionMetric) deserialized).partition()); assertEquals(VALUE, deserialized.value(), 0.000001); } }
public ByteBuffer toBuffer(int headerPos) { byte[] topic = _topic.getBytes(StandardCharsets.UTF_8); ByteBuffer buffer = ByteBuffer.allocate(headerPos + 1 /* version */ + 1 /* raw metric type */ + Long.BYTES /* time */ + Integer.BYTES /* broker id */ + Integer.BYTES /* topic length */ + topic.length /* topic */ + Double.BYTES /* value */); buffer.position(headerPos); buffer.put(METRIC_VERSION); buffer.put(rawMetricType().id()); buffer.putLong(time()); buffer.putInt(brokerId()); buffer.putInt(topic.length); buffer.put(topic); buffer.putDouble(value()); return buffer; }
@Override public ByteBuffer toBuffer(int headerPos) { ByteBuffer buffer = ByteBuffer.allocate(headerPos + 1 /* version */ + 1 /* raw metric type */ + Long.BYTES /* time */ + Integer.BYTES /* broker id */ + Double.BYTES /* value */); buffer.position(headerPos); buffer.put(METRIC_VERSION); buffer.put(rawMetricType().id()); buffer.putLong(time()); buffer.putInt(brokerId()); buffer.putDouble(value()); return buffer; }
public ByteBuffer toBuffer(int headerPos) { byte[] topic = topic().getBytes(StandardCharsets.UTF_8); ByteBuffer buffer = ByteBuffer.allocate(headerPos + 1 /* version */ + 1 /* metric type */ + Long.BYTES /* time */ + Integer.BYTES /* broker id */ + Integer.BYTES /* topic length */ + topic.length /* topic */ + Integer.BYTES /* partition */ + Double.BYTES /* value */); buffer.position(headerPos); buffer.put(METRIC_VERSION); buffer.put(rawMetricType().id()); buffer.putLong(time()); buffer.putInt(brokerId()); buffer.putInt(topic.length); buffer.put(topic); buffer.putInt(_partition); buffer.putDouble(value()); return buffer; }