bigcyy commented on code in PR #3482:
URL: https://github.com/apache/hertzbeat/pull/3482#discussion_r2158167648
##########
hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/expr/AlertExpressionEvalVisitorTest.java:
##########
@@ -473,6 +473,116 @@ void testSqlAndPromqlCallExpr() {
assertEquals(80, result.get(0).get("__value__"));
}
+ @Test
+ void testAndOpPromql() {
+ String promql = "http_server_requests_seconds_count > 10 and
http_server_requests_seconds_max > 5";
+
+ Map<String, Object> countValue1 = new HashMap<>() {
+ {
+ put("exception", "none");
+ put("instance", "host.docker.internal:8989");
+ put("__value__", 1307);
+ put("method", "GET");
+ put("__name__", "http_server_requests_seconds_count");
+ put("__timestamp__", "1.750320922467E9");
+ put("error", "none");
+ put("job", "spring-boot-app");
+ put("uri", "/actuator/prometheus");
+ put("outcome", "SUCCESS");
+ put("status", "200");
+ }
+ };
+
+ Map<String, Object> countValue2 = new HashMap<>() {
+ {
+ put("exception", "none");
+ put("instance", "host.docker.internal:8989");
+ put("__value__", 16);
+ put("method", "GET");
+ put("__name__", "http_server_requests_seconds_count");
+ put("__timestamp__", "1.750320922467E9");
+ put("error", "none");
+ put("job", "spring-boot-app");
+ put("uri", "/**");
+ put("outcome", "SUCCESS");
+ put("status", "200");
+ }
+ };
+
+ Map<String, Object> countValue3 = new HashMap<>() {
+ {
+ put("exception", "none");
+ put("instance", "host.docker.internal:8989");
+ put("__value__", 7);
+ put("method", "GET");
+ put("__name__", "http_server_requests_seconds_count");
+ put("__timestamp__", "1.750320922467E9");
+ put("error", "none");
+ put("job", "spring-boot-app");
+ put("uri", "/actuator/health");
+ put("outcome", "SUCCESS");
+ put("status", "200");
+ }
+ };
+
+ Map<String, Object> maxValue1 = new HashMap<>() {
+ {
+ put("exception", "none");
+ put("instance", "host.docker.internal:8989");
+ put("__value__", 10.007799125);
+ put("method", "GET");
+ put("__name__", "http_server_requests_seconds_max");
+ put("__timestamp__", "1.750320922467E9");
+ put("error", "none");
+ put("job", "spring-boot-app");
+ put("uri", "/actuator/prometheus");
+ put("outcome", "SUCCESS");
+ put("status", "200");
+ }
+ };
+
+ Map<String, Object> maxValue2 = new HashMap<>() {
+ {
+ put("exception", "none");
+ put("instance", "host.docker.internal:8989");
+ put("__value__", 10);
+ put("method", "GET");
+ put("__name__", "http_server_requests_seconds_count");
+ put("__timestamp__", "1.750320922467E9");
+ put("error", "none");
+ put("job", "spring-boot-app");
+ put("uri", "/**");
+ put("outcome", "SUCCESS");
+ put("status", "200");
+ }
+ };
+
+ Map<String, Object> maxValue3 = new HashMap<>() {
+ {
+ put("exception", "none");
+ put("instance", "host.docker.internal:8989");
+ put("__value__", 0);
+ put("method", "GET");
+ put("__name__", "http_server_requests_seconds_count");
+ put("__timestamp__", "1.750320922467E9");
+ put("error", "none");
+ put("job", "spring-boot-app");
+ put("uri", "/actuator/health");
+ put("outcome", "SUCCESS");
+ put("status", "200");
+ }
+ };
+
+
when(mockExecutor.execute("http_server_requests_seconds_count")).thenReturn(List.of(countValue1,
countValue2, countValue3));
+
when(mockExecutor.execute("http_server_requests_seconds_max")).thenReturn(List.of(maxValue1,
maxValue2, maxValue3));
+ List<Map<String, Object>> result = evaluate(promql);
+ assertEquals(2, result.size());
+ assertEquals(1307, result.get(0).get("__value__"));
+ assertEquals(16, result.get(1).get("__value__"));
+ System.out.println();
Review Comment:
Hi, there's a tiny issue here. System.out.println(); Perhaps it would be
better to remove it.
--
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]