wip
This commit is contained in:
parent
7eeb5538d2
commit
e5539f21b5
3 changed files with 21 additions and 20 deletions
|
@ -34,7 +34,6 @@ public final class PrometheusExpose {
|
|||
}
|
||||
|
||||
public static ResponseEntity<String> exposeAllMetrics(Map<String, Metrics> clustersMetrics) {
|
||||
System.out.println("Exposing metrics:" + clustersMetrics);
|
||||
return constructHttpsResponse(getMetricsForGlobalExpose(clustersMetrics));
|
||||
}
|
||||
|
||||
|
@ -95,4 +94,19 @@ public final class PrometheusExpose {
|
|||
.body(writer.toString());
|
||||
}
|
||||
|
||||
// copied from io.prometheus.client.exporter.common.TextFormat:writeEscapedLabelValue
|
||||
public static String escapedLabelValue(String s) {
|
||||
StringWriter writer = new StringWriter(s.length());
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
switch (c) {
|
||||
case '\\' -> writer.append("\\\\");
|
||||
case '\"' -> writer.append("\\\"");
|
||||
case '\n' -> writer.append("\\n");
|
||||
default -> writer.append(c);
|
||||
}
|
||||
}
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.provectus.kafka.ui.service.metrics.sink;
|
||||
|
||||
import static com.provectus.kafka.ui.service.MessagesService.*;
|
||||
import static com.provectus.kafka.ui.service.MessagesService.createProducer;
|
||||
import static com.provectus.kafka.ui.service.metrics.prometheus.PrometheusExpose.escapedLabelValue;
|
||||
import static io.prometheus.client.Collector.*;
|
||||
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
|
@ -54,7 +55,7 @@ class KafkaSink implements MetricsSink {
|
|||
var lbls = new LinkedHashMap<String, String>();
|
||||
lbls.put("__name__", sample.name);
|
||||
for (int i = 0; i < sample.labelNames.size(); i++) {
|
||||
lbls.put(sample.labelNames.get(i), sample.labelValues.get(i));
|
||||
lbls.put(sample.labelNames.get(i), escapedLabelValue(sample.labelValues.get(i)));
|
||||
}
|
||||
var km = new KafkaMetric(ts, doubleToGoString(sample.value), sample.name, lbls);
|
||||
return new ProducerRecord<>(topic, toJson(km));
|
||||
|
|
|
@ -5,9 +5,8 @@ import static prometheus.Types.Label;
|
|||
import static prometheus.Types.Sample;
|
||||
import static prometheus.Types.TimeSeries;
|
||||
|
||||
import com.provectus.kafka.ui.service.metrics.prometheus.PrometheusExpose;
|
||||
import com.provectus.kafka.ui.util.WebClientConfigurator;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URI;
|
||||
import java.util.stream.Stream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
@ -58,7 +57,7 @@ class PrometheusRemoteWriteSink implements MetricsSink {
|
|||
timeSeriesBuilder.addLabels(
|
||||
Label.newBuilder()
|
||||
.setName(sample.labelNames.get(i))
|
||||
.setValue(escapedLabelValue(sample.labelValues.get(i)))
|
||||
.setValue(PrometheusExpose.escapedLabelValue(sample.labelValues.get(i)))
|
||||
);
|
||||
}
|
||||
timeSeriesBuilder.addSamples(
|
||||
|
@ -69,22 +68,9 @@ class PrometheusRemoteWriteSink implements MetricsSink {
|
|||
request.addTimeseries(timeSeriesBuilder);
|
||||
}
|
||||
});
|
||||
//TODO: how to pass Metadata ???
|
||||
//TODO: pass Metadata
|
||||
return request.build();
|
||||
}
|
||||
|
||||
private static String escapedLabelValue(String s) {
|
||||
StringWriter writer = new StringWriter(s.length());
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
switch (c) {
|
||||
case '\\' -> writer.append("\\\\");
|
||||
case '\"' -> writer.append("\\\"");
|
||||
case '\n' -> writer.append("\\n");
|
||||
default -> writer.append(c);
|
||||
}
|
||||
}
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue