hertzbeat icon indicating copy to clipboard operation
hertzbeat copied to clipboard

[BUG] <title>instance why use id?

Open gavinage opened this issue 1 year ago • 15 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Current Behavior

defaultLabels.put(LABEL_KEY_INSTANCE, String.valueOf(metricsData.getId()));

指标的 instance标签为何使用 id赋值, 正常应该是 ip+端口 这里取instance 那么是不是就可以

如下的效果,不是很好 Image

Expected Behavior

No response

Steps To Reproduce

No response

Environment

HertzBeat version(v1.7.2  v1.7.3):

Debug logs

No response

Anything else?

No response

gavinage avatar Sep 12 '25 07:09 gavinage

@tomsun28 Hi! I was wondering if this issue has already been resolved in recent commits. If not, I’d like to give it a try.

Saramanda9988 avatar Sep 29 '25 15:09 Saramanda9988

@Saramanda9988 Hi, this is not be resolved, welcome. Could you describe your proposed approach before starting?

thefullgc avatar Oct 13 '25 16:10 thefullgc

@tomsun28 Sure! I believe the instance label should represent the actual monitored target. Using IP:Port makes the metrics easier to identify and correlate, and aligns well with Prometheus labeling conventions. I considered using instanceName, but since it may not always map directly to the actual target, I think IP:Port would be a more reliable choice. If this approach looks good to you, I’ll submit a PR soon. Please let me know if you have any suggestions or concerns!

Saramanda9988 avatar Oct 14 '25 15:10 Saramanda9988

Hi @tomsun28 and community,

I’ve been investigating this issue and found that the host value currently only includes the IP (e.g. 127.0.0.1), not the full IP:Port The MetricsData metadata contains only instancehost and instancename, without any port information.Each monitorTask has a globally unique id and name.

Image

Given this, there seem to be a few possible approaches:

  1. Modify host to include ip:port, so that the instance label directly matches Prometheus best practices. Or add a port field in metadata allowing ip:port to be reconstructed later — but these may introduce larger structural changes.
  2. Use instancename as the instance label, which requires minimal modification but doesn’t fully align with Prometheus conventions.

Before proceeding with a PR, I’d like to hear your thoughts, Any suggestions from the community would be greatly appreciated.

Saramanda9988 avatar Oct 27 '25 15:10 Saramanda9988

Hi, @Saramanda9988 sorry for slow response. the reason there's no port is because monitoring type like ping don't require a port number. I'll look into this and get back to you, because any changes to this will have a long-lasting impact. thanks and welcome to discuss.

thefullgc avatar Nov 06 '25 14:11 thefullgc

Thanks for the reply, @tomsun28 ! I’ll wait for your further thoughts on this and I’m happy to adjust my approach once you’ve reviewed it. Please let me know if there’s anything I can help test or verify!

Saramanda9988 avatar Nov 06 '25 14:11 Saramanda9988

hi, how about this refactor. In Monitor, change the host into instance, the instance value is host:port, the ping monitor's instance value is host. Because the monitor params also has the host value, so we can change Monitor host.

Image

Then change the metadata instancehost into instance, the value is from the monitor instance.

Image

The we can save the instance as promethues instance into TSDB like victormetrics or greptimedb. Also we need update the metrics query, from using the monitorId to match value to using the instance.

thefullgc avatar Nov 07 '25 14:11 thefullgc

Hi,I think the refactor makes sense. It is feasible and more maintainable in the long run. However, it might introduce some breaking changes — for example, existing users might need to perform data migration after upgrading.

In addition, some frontend code and test logic may also need corresponding updates.

Before I proceed to explore this direction further, I’d like to confirm: do you think it’s acceptable to make such structural adjustments at this stage of the project?

Saramanda9988 avatar Nov 08 '25 12:11 Saramanda9988

hi i think it's acceptable.

thefullgc avatar Nov 10 '25 13:11 thefullgc

Thanks! I’ll start the refactor and try to provide a PR soon, and also check changes during the process.

Saramanda9988 avatar Nov 10 '25 14:11 Saramanda9988

Hi, community

I’ve completed the initial development for this refactor and would like to provide an update, along with a few design questions that came up during the implementation. I hope to get your feedback.

  1. Originally, I planned to follow the proposed refactor and use instance as the main query field. However, in the current implementation, multiple monitors may point to the same instance, and the backend does not enforce uniqueness on the instance field. So using it as a lookup key could lead to ambiguous or duplicated results.For this reason, I kept using monitorId internally for querying to ensure deterministic behavior.I’d like to confirm whether monitorId for querying could be the intended design.

  2. During the implementation, I noticed differences among storage types: When using VictoriaMetrics, an additional host field which is returned to the frontend.

Image Image

When using GreptimeDB, there is no host field.

Image
  1. For the other five TSDB types, the meaning of “instance” is represented through labels, not the instance host like VictoriaMetrics or GreptimeDB.
Image

However, the frontend does not use labels for filtering, and the query parameters do not include an instance field.

Image

I’m unsure what the expected unified behavior should be. Should each datasource normalize its own label mappings, or do we want a unified abstraction? I would appreciate guidance on the intended direction here.

Saramanda9988 avatar Nov 21 '25 15:11 Saramanda9988

👍 Thanks for your work. I will take a look at the code then response.

thefullgc avatar Nov 24 '25 01:11 thefullgc

Hi, for the new design in the metrics data, the instance value is host:port , This doesn't seem to cause multiple monitors point to a single instance, but for historical data, it's unavoidable. However, short-term pain is better than long-term pain.😭 How about continue use the instance to query metrics data?

For each datasource its own label mappings, i think we want a unified abstraction.
Since we're already close to the Promethean ecosystem, using greptimedb for logs. Our future work will primarily focus on in-depth development of greptimedb, while compatibility with other storage methods. relate https://github.com/apache/hertzbeat/discussions/3845

thefullgc avatar Nov 24 '25 15:11 thefullgc

Hi @tomsun28 , thanks again for your patience.

Regarding duplicate monitoring: You're right, while it's technically possible to configure multiple monitors for a single instance

Image Image

It's possible to add validation rules to prevent this case, although in real-world usage I don't think users would intentionally configure it this way 😂

For now, continuing to use instance for querying historical metric data seems like the most pragmatic approach.

About the label mappings, I’d like to propose the following adjustments:

  1. Rename the current instance field (used for label strings) to metric_labels, which better reflects its actual meaning. The instance field, instead of monitorEd, will continue to represent the IP address and port of the monitored target.
  2. Remove the label-query logic for the other five TSDB implementations. For GreptimeDB and VictoriaMetrics datasource, this label field is not used for querying anyway.
  3. VictoriaMetrics datasource will no longer return the host (instance) to the frontend by metric_labels, matching the behavior of GreptimeDB.

Also, I noticed there isn’t any configuration or documentation regarding QuestDB and TDengine in the official docs.Are we still planning to maintain compatibility with these two data sources going forward?

Saramanda9988 avatar Nov 25 '25 14:11 Saramanda9988

hi @Saramanda9988 Thanks for your meticulous design; I completely agree with your adjustments about point 1, 2, 3. And as you know, the questDB, tdengine, iotdb are not in plan in the future, i think we do not need compatible with these. cc @zqr10159 @Calvin979 @bigcyy @zhangshenghang @Aias00 @Duansg @TJxiaobao

thefullgc avatar Nov 25 '25 14:11 thefullgc