Simplify prometheus metrics adapter (#1343)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
parent
2312932a76
commit
3ed3db3aa8
|
|
@ -105,18 +105,7 @@ final class MetricAdapter {
|
||||||
if (descriptor.getConstantLabels().size() != 0) {
|
if (descriptor.getConstantLabels().size() != 0) {
|
||||||
constLabelNames = new ArrayList<>(descriptor.getConstantLabels().size());
|
constLabelNames = new ArrayList<>(descriptor.getConstantLabels().size());
|
||||||
constLabelValues = new ArrayList<>(descriptor.getConstantLabels().size());
|
constLabelValues = new ArrayList<>(descriptor.getConstantLabels().size());
|
||||||
final List<String> finalConstLabelNames = constLabelNames;
|
descriptor.getConstantLabels().forEach(new Consumer(constLabelNames, constLabelValues));
|
||||||
final List<String> finalConstLabelValues = constLabelValues;
|
|
||||||
descriptor
|
|
||||||
.getConstantLabels()
|
|
||||||
.forEach(
|
|
||||||
new KeyValueConsumer<String>() {
|
|
||||||
@Override
|
|
||||||
public void consume(String key, String value) {
|
|
||||||
finalConstLabelNames.add(toLabelName(key));
|
|
||||||
finalConstLabelValues.add(value == null ? "" : value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Point point : points) {
|
for (Point point : points) {
|
||||||
|
|
@ -131,18 +120,7 @@ final class MetricAdapter {
|
||||||
labelValues.addAll(constLabelValues);
|
labelValues.addAll(constLabelValues);
|
||||||
|
|
||||||
// TODO: Use a cache(map) of converted label names to avoid sanitization multiple times
|
// TODO: Use a cache(map) of converted label names to avoid sanitization multiple times
|
||||||
final List<String> finalLabelNames = labelNames;
|
point.getLabels().forEach(new Consumer(labelNames, labelValues));
|
||||||
final List<String> finalLabelValues = labelValues;
|
|
||||||
point
|
|
||||||
.getLabels()
|
|
||||||
.forEach(
|
|
||||||
new KeyValueConsumer<String>() {
|
|
||||||
@Override
|
|
||||||
public void consume(String key, String value) {
|
|
||||||
finalLabelNames.add(toLabelName(key));
|
|
||||||
finalLabelValues.add(value == null ? "" : value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (descriptor.getType()) {
|
switch (descriptor.getType()) {
|
||||||
|
|
@ -169,6 +147,22 @@ final class MetricAdapter {
|
||||||
return Collector.sanitizeMetricName(labelKey);
|
return Collector.sanitizeMetricName(labelKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class Consumer implements KeyValueConsumer<String> {
|
||||||
|
final List<String> labelNames;
|
||||||
|
final List<String> labelValues;
|
||||||
|
|
||||||
|
private Consumer(List<String> labelNames, List<String> labelValues) {
|
||||||
|
this.labelNames = labelNames;
|
||||||
|
this.labelValues = labelValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void consume(String key, String value) {
|
||||||
|
labelNames.add(toLabelName(key));
|
||||||
|
labelValues.add(value == null ? "" : value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void addSummarySamples(
|
private static void addSummarySamples(
|
||||||
SummaryPoint summaryPoint,
|
SummaryPoint summaryPoint,
|
||||||
String name,
|
String name,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue