Skip to content

Commit

Permalink
fix prometheus exporter parse metric name and label name bug (#753)
Browse files Browse the repository at this point in the history
* fix parse prometheus exporter text bug

* norm test

* update iotdb version V_1_00 -> V_1_0
  • Loading branch information
Ceilzcx authored Mar 21, 2023
1 parent 26241fd commit 34f2add
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down Expand Up @@ -42,6 +42,7 @@ void textToMetric() {
"# EOF";
ExporterParser parser = new ExporterParser();
Map<String, MetricFamily> 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());
}
}
2 changes: 1 addition & 1 deletion manager/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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代表永不过期)
Expand Down

0 comments on commit 34f2add

Please sign in to comment.