Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix prometheus exporter parse metric name and label name bug #753

Merged
merged 3 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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