marksilcox commented on code in PR #15558:
URL: https://github.com/apache/pulsar/pull/15558#discussion_r872496951
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/prometheus/TopicStats.java:
##########
@@ -382,77 +389,102 @@ static void metricType(SimpleTextOutputStream stream,
String name) {
}
- private static void metric(SimpleTextOutputStream stream, String cluster,
String namespace, String topic,
- String name, double value, boolean
splitTopicAndPartitionIndexLabel) {
- metricType(stream, name);
- appendRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel).write("\"} ");
- stream.write(value);
- appendEndings(stream);
+ private static void metric(Map<String, List<String>> metrics, String
cluster, String namespace, String topic,
+ String name, double value, boolean
splitTopicAndPartitionIndexLabel) {
+ writeMetric(metrics, name, stream -> {
+ writeRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel);
+ stream.write("\"} ")
+ .write(value);
+ writeEndings(stream);
+ });
}
- private static void metric(SimpleTextOutputStream stream, String cluster,
String namespace, String topic,
- String subscription, String name, long value, boolean
splitTopicAndPartitionIndexLabel) {
- metricType(stream, name);
- appendRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel)
- .write("\",subscription=\"").write(subscription).write("\"} ");
- stream.write(value);
- appendEndings(stream);
+ private static void metric(Map<String, List<String>> metrics, String
cluster, String namespace, String topic,
+ String subscription, String name, long value,
boolean splitTopicAndPartitionIndexLabel) {
+ writeMetric(metrics, name, stream -> {
+ writeRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel);
+ stream.write("\",subscription=\"").write(subscription)
+ .write("\"} ")
+ .write(value);
+ writeEndings(stream);
+ });
+ }
+
+ private static void metric(Map<String, List<String>> metrics, String
cluster, String namespace, String topic,
+ String producerName, long produceId, String
name, double value,
+ boolean splitTopicAndPartitionIndexLabel) {
+ writeMetric(metrics, name, stream -> {
+ writeRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel);
+ stream.write("\",producer_name=\"").write(producerName)
+ .write("\",producer_id=\"").write(produceId)
+ .write("\"} ")
+ .write(value);
+ writeEndings(stream);
+ });
}
- private static void metric(SimpleTextOutputStream stream, String cluster,
String namespace, String topic,
- String producerName, long produceId, String name, double value,
boolean splitTopicAndPartitionIndexLabel) {
- metricType(stream, name);
- appendRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel)
- .write("\",producer_name=\"").write(producerName)
- .write("\",producer_id=\"").write(produceId).write("\"} ");
- stream.write(value);
- appendEndings(stream);
+ private static void metric(Map<String, List<String>> metrics, String
cluster, String namespace, String topic,
+ String subscription, String name, double value,
+ boolean splitTopicAndPartitionIndexLabel) {
+ writeMetric(metrics, name, stream -> {
+ writeRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel);
+ stream.write("\",subscription=\"").write(subscription)
+ .write("\"} ")
+ .write(value);
+ writeEndings(stream);
+ });
}
- private static void metric(SimpleTextOutputStream stream, String cluster,
String namespace, String topic,
- String subscription, String name, double value, boolean
splitTopicAndPartitionIndexLabel) {
- metricType(stream, name);
- appendRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel)
- .write("\",subscription=\"").write(subscription).write("\"} ");
- stream.write(value);
- appendEndings(stream);
+ private static void metric(Map<String, List<String>> metrics, String
cluster, String namespace, String topic,
+ String subscription, String consumerName, long
consumerId, String name, long value,
+ boolean splitTopicAndPartitionIndexLabel) {
+ writeMetric(metrics, name, stream -> {
+ writeRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel);
+ stream.write("\",subscription=\"").write(subscription)
+
.write("\",consumer_name=\"").write(consumerName).write("\",consumer_id=\"").write(consumerId)
+ .write("\"} ")
+ .write(value);
+ writeEndings(stream);
+ });
}
- private static void metric(SimpleTextOutputStream stream, String cluster,
String namespace, String topic,
- String subscription, String consumerName, long consumerId, String
name, long value,
- boolean splitTopicAndPartitionIndexLabel) {
- metricType(stream, name);
- appendRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel)
- .write("\",subscription=\"").write(subscription)
-
.write("\",consumer_name=\"").write(consumerName).write("\",consumer_id=\"").write(consumerId)
- .write("\"} ");
- stream.write(value);
- appendEndings(stream);
+ private static void metric(Map<String, List<String>> metrics, String
cluster, String namespace, String topic,
+ String subscription, String consumerName, long
consumerId, String name, double value,
+ boolean splitTopicAndPartitionIndexLabel) {
+ writeMetric(metrics, name, stream -> {
+ writeRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel);
+ stream.write("\",subscription=\"").write(subscription)
+
.write("\",consumer_name=\"").write(consumerName).write("\",consumer_id=\"")
+ .write(consumerId).write("\"} ")
+ .write(value);
+ writeEndings(stream);
+ });
}
- private static void metric(SimpleTextOutputStream stream, String cluster,
String namespace, String topic,
- String subscription, String consumerName, long consumerId, String
name, double value,
- boolean splitTopicAndPartitionIndexLabel) {
- metricType(stream, name);
- appendRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel)
- .write("\",subscription=\"").write(subscription)
-
.write("\",consumer_name=\"").write(consumerName).write("\",consumer_id=\"")
- .write(consumerId).write("\"} ");
- stream.write(value);
- appendEndings(stream);
+ private static void metricWithRemoteCluster(Map<String, List<String>>
metrics, String cluster, String namespace,
+ String topic, String name,
String remoteCluster, double value,
+ boolean
splitTopicAndPartitionIndexLabel) {
+ writeMetric(metrics, name, stream -> {
+ writeRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel);
+
stream.write("\",remote_cluster=\"").write(remoteCluster).write("\"}
").write(value);
+ writeEndings(stream);
+ });
}
- private static void metricWithRemoteCluster(SimpleTextOutputStream stream,
String cluster, String namespace,
- String topic, String name, String remoteCluster, double value,
boolean splitTopicAndPartitionIndexLabel) {
- metricType(stream, name);
- appendRequiredLabels(stream, cluster, namespace, topic, name,
splitTopicAndPartitionIndexLabel)
- .write("\",remote_cluster=\"").write(remoteCluster).write("\"}
");
- stream.write(value);
- appendEndings(stream);
+ private static void writeMetric(Map<String, List<String>> metrics, String
name,
+ Consumer<SimpleTextOutputStream>
metricWriter) {
+ ByteBuf buf = ByteBufAllocator.DEFAULT.heapBuffer();
Review Comment:
agree - have updated to use prometheus' `Collector.MetricFamilySamples` with
only one `SimpleTextOutputStream` used when writing
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]