bigcyy opened a new issue, #3496: URL: https://github.com/apache/hertzbeat/issues/3496
### Question While recently reviewing the official Prometheus documentation, I noticed the behavior of PromQL comparison operators (>, <, ==, >=, <=, !=) and found two main inconsistencies when comparing it with the implementation in Hertzbeat. 1. Comparison Logic for Instant Vector vs. Scalar According to the [official Prometheus documentation](https://prometheus.io/docs/prometheus/latest/querying/operators/), when an instant vector is compared to a scalar, the operation acts as a filter. Specifically, PromQL iterates through each time series in the vector, performs the comparison, and any time series for which the expression is true is kept in the output. Series for which the result is false are removed. However, I noticed that the behavior demonstrated in the calculate1 test case in hertzbeat.warehouse.service.DataSourceServiceTest does not align with this standard. ```java void calculate1() { List<Map<String, Object>> prometheusData = List.of( new HashMap<>(Map.of("__value__", 100.0, "timestamp", 1343554, "instance", "node1")), new HashMap<>(Map.of("__value__", 200.0, "timestamp", 1343555, "instance", "node2")) ); QueryExecutor mockExecutor = Mockito.mock(QueryExecutor.class); Mockito.when(mockExecutor.support("promql")).thenReturn(true); Mockito.when(mockExecutor.execute(Mockito.anyString())).thenReturn(prometheusData); dataSourceService.setExecutors(List.of(mockExecutor)); List<Map<String, Object>> result = dataSourceService.calculate("promql", "node_cpu_seconds_total > 150"); assertEquals(2, result.size()); assertNull(result.get(0).get("__value__")); assertEquals(200.0, result.get(1).get("__value__")); } ``` Analysis: Input: An instant vector containing two time series with values 100.0 and 200.0. Query: node_cpu_seconds_total > 150. Expected PromQL Behavior: Only the series with the value 200.0 satisfies the condition. Therefore, the result should be a new vector containing only that single series, and its size should be 1. Behavior in Hertzbeat Test: The test asserts that result.size() is 2. Instead of filtering out the non-matching series (__value__ of 100.0), it keeps the series in the result set but sets its __value__ to null. Core Question: This "keep and nullify" behavior deviates from PromQL's standard filtering model. Is this an intentional design choice in Hertzbeat? My main question is whether the plan is to fully align with the Prometheus specification in this regard. If not, it could cause confusion for users familiar with standard PromQL. 2. Support for Comparison Operations on Range Vectors The Prometheus documentation clearly states that logical and comparison operators are only defined to work between instant vectors. They do not support range vectors. However, I noticed that DataSourceServiceTest contains test cases involving comparisons between a range vector and a scalar, such as: node_cpu_seconds_total{mode=\"user\"}[4m] <= 100 This is an invalid expression in standard PromQL. This seems to suggest that Hertzbeat is extending PromQL syntax to support comparisons on range vectors. @tomsun28 @MasamiYui @Duansg -- 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: notifications-unsubscr...@hertzbeat.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@hertzbeat.apache.org For additional commands, e-mail: notifications-h...@hertzbeat.apache.org