@Override public String toString() { return String.format("[%s,%s,time=%d,brokerId=%d,partition=%s,value=%.3f]", MetricClassId.PARTITION_METRIC, rawMetricType(), time(), brokerId(), new TopicPartition(topic(), partition()), value()); } }
private void recordMetric(CruiseControlMetric ccm) { RawMetricType rawMetricType = ccm.rawMetricType(); switch (rawMetricType.metricScope()) { case BROKER: _brokerMetrics.recordCruiseControlMetric(ccm); break; case TOPIC: TopicMetric tm = (TopicMetric) ccm; _dotHandledTopicMetrics.computeIfAbsent(tm.topic(), t -> new RawMetricsHolder()) .recordCruiseControlMetric(ccm); break; case PARTITION: PartitionMetric pm = (PartitionMetric) ccm; _dotHandledPartitionMetrics.computeIfAbsent(new TopicPartition(pm.topic(), pm.partition()), tp -> new RawMetricsHolder()) .recordCruiseControlMetric(ccm); _dotHandledTopicsWithPartitionSizeReported.add(pm.topic()); break; default: throw new IllegalStateException(String.format("Should never be here. Unrecognized metric scope %s", rawMetricType.metricScope())); } }
@Test public void testMissingPartitionSizeMetric() throws UnknownVersionException { CruiseControlMetricsProcessor processor = new CruiseControlMetricsProcessor(); 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); } } MetricSampler.Samples samples = processor.process(getCluster(), Arrays.asList(T1P0, T1P1, T2P0, T2P1), MetricSampler.SamplingMode.ALL); assertEquals("Should have ignored partition " + T1P0, 3, samples.partitionMetricSamples().size()); assertEquals("Should have reported both brokers", 2, samples.brokerMetricSamples().size()); }
@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); } }
@Override public String toString() { return String.format("[%s,%s,time=%d,brokerId=%d,partition=%s,value=%.3f]", MetricClassId.PARTITION_METRIC, rawMetricType(), time(), brokerId(), new TopicPartition(topic(), partition()), value()); } }