apache / apache/hugegraph

[Bug] Prometheus metrics format bug

Open Beginner friendly
#3,142 7 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
3.2k
Forks
636
Avg merge
3d 11h
Merged PRs (30d)
14

Description

### Bug Type (问题类型)

None

### Before submit

- [x] 我已经确认现有的 [Issues](https://github.com/apache/hugegraph/issues) 与 [FAQ](https://hugegraph.apache.org/docs/guides/faq/) 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)

### Environment (环境信息)

3 pd
3 server
5 store

### Expected & Actual behavior (期望与实际表现)

I pulled the latest version of the HugeGraph source code, compiled and deployed it, and then deployed a Prometheus + Grafana monitoring environment.

During the monitoring test, I found that the metrics exposed by `hugegraph-server` (`/metrics`) could not be scraped correctly by Prometheus. After checking the logs, I found that some metric names contained the illegal character `~`, which does not comply with the Prometheus metric naming specification. As a result, Prometheus failed to parse the metrics data, causing the server monitoring metrics collection to fail.

I located the issue in the metric name processing logic and modified the related code to correctly replace the illegal characters in metric names. After recompiling and redeploying HugeGraph Server, the metrics format was fixed, and Prometheus was able to successfully scrape the server monitoring metrics.

public static String replaceSlashInKey(String orgKey) {
return orgKey.replace("/", "_");
}
->
public static String replaceSlashInKey(String orgKey) {
return orgKey.replace("/", "_").replace("~", "_");
}

I also modified the following code section. However, I am not sure whether this change has any effect. What I can confirm is that the code above definitely needs to be modified, because I first modified the code below, recompiled and redeployed the project, but the issue still occurred. After modifying the code above, recompiling and redeploying HugeGraph Server successfully resolved the problem.

public static String replaceDotDashInKey(String orgKey) {
return orgKey.replace(".", "_").replace("-", "_").replace("/", "_").replace("$", "_");
}
->
public static String replaceDotDashInKey(String orgKey) {
return orgKey.replace(".", "_").replace("-", "_").replace("/", "_").replace("$", "_").replace("~", "_");
}

### Vertex/Edge example (问题点 / 边数据举例)

```javascript

```

### Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

```javascript

```

Contributor guide

Open the contributing guide

Research direction

Locate the metric-name processing methods replaceSlashInKey and replaceDotDashInKey shown in the issue, then trace where hugegraph-server builds the /metrics output. Reproduce a Prometheus scrape with a metric containing '~' and verify that the exposed names use valid characters and are parsed successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
grafana, java, prometheus
Domain
observability
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.