From 34f2addfc74119dcaf7e03deb0699f8254399853 Mon Sep 17 00:00:00 2001 From: zcx <48920254+Ceilzcx@users.noreply.github.com> Date: Tue, 21 Mar 2023 17:21:38 +0800 Subject: [PATCH] fix prometheus exporter parse metric name and label name bug (#753) * fix parse prometheus exporter text bug * norm test * update iotdb version V_1_00 -> V_1_0 --- .../collect/http/promethus/exporter/ExporterParser.java | 4 +++- .../collect/http/promethus/exporter/ExporterParserTest.java | 5 +++-- manager/src/main/resources/application.yml | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/collector/src/main/java/com/usthe/collector/collect/http/promethus/exporter/ExporterParser.java b/collector/src/main/java/com/usthe/collector/collect/http/promethus/exporter/ExporterParser.java index f5d896f25a8..4f039e8f5a3 100644 --- a/collector/src/main/java/com/usthe/collector/collect/http/promethus/exporter/ExporterParser.java +++ b/collector/src/main/java/com/usthe/collector/collect/http/promethus/exporter/ExporterParser.java @@ -123,7 +123,7 @@ private void parseType(StrBuffer line) { private void parseMetric(StrBuffer buffer) { String metricName = this.readTokenAsMetricName(buffer); - if (StringUtils.isEmpty(metricName)) { + if (metricName.isEmpty()) { log.error("error parse metric, metric name is null, line: {}", buffer.toStr()); return; } @@ -311,6 +311,7 @@ private String readTokenUnitWhitespace(StrBuffer buffer) { * @return token name */ private String readTokenAsMetricName(StrBuffer buffer) { + buffer.skipBlankTabs(); StringBuilder builder = new StringBuilder(); if (this.isValidMetricNameStart(buffer.charAt(0))) { while (!buffer.isEmpty()) { @@ -333,6 +334,7 @@ private String readTokenAsMetricName(StrBuffer buffer) { * @return label name */ private String readTokenAsLabelName(StrBuffer buffer) { + buffer.skipBlankTabs(); StringBuilder builder = new StringBuilder(); char c = buffer.read(); if (this.isValidLabelNameStart(c)) { diff --git a/collector/src/test/java/com/usthe/collector/collect/http/promethus/exporter/ExporterParserTest.java b/collector/src/test/java/com/usthe/collector/collect/http/promethus/exporter/ExporterParserTest.java index 2dbc058e0ef..513465f48e8 100644 --- a/collector/src/test/java/com/usthe/collector/collect/http/promethus/exporter/ExporterParserTest.java +++ b/collector/src/test/java/com/usthe/collector/collect/http/promethus/exporter/ExporterParserTest.java @@ -14,7 +14,7 @@ class ExporterParserTest { @Test void textToMetric() { - String resp = "# HELP go_gc_cycles_automatic_gc_cycles_total Count of completed GC cycles generated by the Go runtime.\n" + + String resp = "# HELP go_gc_cycles_automatic_gc_cycles_total Count of completed GC cycles generated by the Go runtime.\n" + "# TYPE go_gc_cycles_automatic_gc_cycles_total counter\n" + "go_gc_cycles_automatic_gc_cycles_total 0\n" + "# HELP go_gc_cycles_forced_gc_cycles_total Count of completed GC cycles forced by the application.\n" + @@ -42,6 +42,7 @@ void textToMetric() { "# EOF"; ExporterParser parser = new ExporterParser(); Map metricFamilyMap = parser.textToMetric(resp); - assertEquals(metricFamilyMap.size(), 6); + assertEquals(6, metricFamilyMap.size()); + assertEquals(5, metricFamilyMap.get("go_gc_duration_seconds").getMetricList().get(0).getSummary().getQuantileList().size()); } } \ No newline at end of file diff --git a/manager/src/main/resources/application.yml b/manager/src/main/resources/application.yml index 50b7d91e6aa..ee3b348cb90 100644 --- a/manager/src/main/resources/application.yml +++ b/manager/src/main/resources/application.yml @@ -114,7 +114,7 @@ warehouse: rpc-port: 6667 username: root password: root - # com.usthe.warehouse.config.IotDbVersion: V_0_13 || V_1_00 + # com.usthe.warehouse.config.IotDbVersion: V_0_13 || V_1_0 version: V_0_13 query-timeout-in-ms: -1 # 数据存储时间:默认'7776000000'(90天,单位为毫秒,-1代表永不过期)