[BUG] <title>instance why use id?
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 那么是不是就可以
如下的效果,不是很好
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
@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 Hi, this is not be resolved, welcome. Could you describe your proposed approach before starting?
@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!
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.
Given this, there seem to be a few possible approaches:
- 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.
- 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.
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.
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!
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.
Then change the metadata instancehost into instance, the value is from the monitor instance.
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.
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?
hi i think it's acceptable.
Thanks! I’ll start the refactor and try to provide a PR soon, and also check changes during the process.
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.
-
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.
-
During the implementation, I noticed differences among storage types: When using VictoriaMetrics, an additional host field which is returned to the frontend.
When using GreptimeDB, there is no host field.
- For the other five TSDB types, the meaning of “instance” is represented through labels, not the instance host like VictoriaMetrics or GreptimeDB.
However, the frontend does not use labels for filtering, and the query parameters do not include an instance field.
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.
👍 Thanks for your work. I will take a look at the code then response.
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
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
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:
- Rename the current
instancefield (used for label strings) tometric_labels, which better reflects its actual meaning. Theinstancefield, instead ofmonitorEd, will continue to represent the IP address and port of the monitored target. - 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.
- 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?
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