Saramanda9988 opened a new issue, #3983:
URL: https://github.com/apache/hertzbeat/issues/3983

   ### Is there an existing issue for this?
   
   - [x] I have searched the existing issues
   
   ### Current Behavior
   
   When querying historical metrics data for a Prometheus-type monitor, the 
query returns empty results even though the data has been successfully stored. 
Consequently, historical data charts display "No Data."
   
   <img width="2559" height="1398" alt="Image" 
src="https://github.com/user-attachments/assets/d350f09c-5aa8-4e04-b989-46a7ea50f624";
 />
   
   The issue stems from an inconsistency in the app parameter value between the 
storage and query phases for Prometheus monitors.
   
   ### Expected Behavior
   
   _No response_
   
   ### Steps To Reproduce
   
   _No response_
   
   ### Environment
   
   ```markdown
   HertzBeat version(s):1.8.0
   ```
   
   ### Debug logs
   
   _No response_
   
   ### Anything else?
   
   At Storage (Monitor Creation/Modification): In MonitorServiceImpl.java:
   ```java
   if (CommonConstants.PROMETHEUS.equals(monitor.getApp())) {
       appDefine.setApp(CommonConstants.PROMETHEUS_APP_PREFIX + 
monitor.getName());
   }
   ```
   For Prometheus monitors, AppDefine.app is set to prometheus_{monitorName} 
(e.g., prometheus_my_monitor). This value is used to construct table names in 
storage engines.
   
   <img width="1218" height="390" alt="Image" 
src="https://github.com/user-attachments/assets/a518334d-47c0-4a69-8f78-44d8ece0dc7d";
 />
   
   At Storage Execution (using TdEngine as an example):
   
   - `String app = metricsData.getApp()` (retrieves the prefixed name from 
AppDefine).
   - Table name becomes `app + "_" + metrics + "_" + instance + "_v2"`, 
resulting in prometheus_my_monitor_metrics_instance_v2.
   
   <img width="2559" height="1527" alt="Image" 
src="https://github.com/user-attachments/assets/06fbe799-3b55-4592-bab2-6a60e51f0d55";
 />
   
   At Query (Frontend to Controller):
   
   - The frontend passes the app parameter from Monitor.getApp(), which is 
simply prometheus.
   - MetricsDataController.java: Extracts `app = names[0]` (resulting in 
prometheus).
   
   <img width="2559" height="1527" alt="Image" 
src="https://github.com/user-attachments/assets/30fab014-cdf6-4cd4-a71e-c3e593e66ce2";
 />
   
   When the query reaches the storage layer (e.g., 
TdEngineDataStorage.java:360), getTable(app, metrics, instance) uses the raw 
prometheus string instead of the prefixed prometheus_my_monitor, failing to 
locate the correct table.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to