diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md index 5e1e11e593bf..5d171cf08ef4 100644 --- a/docs/en/changes/changes.md +++ b/docs/en/changes/changes.md @@ -44,6 +44,8 @@ * Add protection for dynamic config change propagate chain. * Add Ruby component IDs. * Add component ID(160) for Caffeine. +* Alarm: Support store and query the metrics snapshot when the alarm is triggered. +* Alarm: Remove unused `Alarm Trend` query. #### UI diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/MQEVisitorBase.java b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/MQEVisitorBase.java index 2f9a4fafb08a..fcc41dc19474 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/MQEVisitorBase.java +++ b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/MQEVisitorBase.java @@ -35,11 +35,11 @@ import org.apache.skywalking.mqe.rt.operation.SortLabelValuesOp; import org.apache.skywalking.mqe.rt.operation.SortValuesOp; import org.apache.skywalking.mqe.rt.operation.TrendOp; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; -import org.apache.skywalking.mqe.rt.type.MQEValue; -import org.apache.skywalking.mqe.rt.type.MQEValues; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValue; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValues; import org.apache.skywalking.oap.server.core.Const; import org.apache.skywalking.oap.server.core.query.enumeration.Step; import org.apache.skywalking.oap.server.core.query.type.KeyValue; diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/AggregateLabelsOp.java b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/AggregateLabelsOp.java index e9b8144142c3..2567982e8917 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/AggregateLabelsOp.java +++ b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/AggregateLabelsOp.java @@ -22,9 +22,9 @@ import java.util.List; import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; import org.apache.skywalking.mqe.rt.grammar.MQEParser; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.MQEValue; -import org.apache.skywalking.mqe.rt.type.MQEValues; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValue; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValues; import org.apache.skywalking.mqe.rt.operation.aggregatelabels.AggregateLabelsFunc; import org.apache.skywalking.mqe.rt.operation.aggregatelabels.AggregateLabelsFuncFactory; import org.apache.skywalking.mqe.rt.operation.aggregatelabels.AvgAggregateLabelsFunc; diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/AggregationOp.java b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/AggregationOp.java index aa034c27bf3d..b02487fb7b09 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/AggregationOp.java +++ b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/AggregationOp.java @@ -27,11 +27,11 @@ import java.util.function.Function; import java.util.stream.DoubleStream; import org.apache.skywalking.mqe.rt.grammar.MQEParser; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; -import org.apache.skywalking.mqe.rt.type.MQEValue; -import org.apache.skywalking.mqe.rt.type.MQEValues; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValue; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValues; public class AggregationOp { public static ExpressionResult doAggregationOp(ExpressionResult result, diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/BinaryOp.java b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/BinaryOp.java index 0c84aaf98391..cf114286474a 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/BinaryOp.java +++ b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/BinaryOp.java @@ -20,7 +20,7 @@ import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; import org.apache.skywalking.mqe.rt.grammar.MQEParser; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; public class BinaryOp { public static ExpressionResult doBinaryOp(ExpressionResult left, diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/CompareOp.java b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/CompareOp.java index 030f3174fde8..b1e8ef6fb97d 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/CompareOp.java +++ b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/CompareOp.java @@ -20,7 +20,7 @@ import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; import org.apache.skywalking.mqe.rt.grammar.MQEParser; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; public class CompareOp { public static ExpressionResult doCompareOP(ExpressionResult left, diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/LROp.java b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/LROp.java index 4254b59898aa..3dfc489d9c14 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/LROp.java +++ b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/LROp.java @@ -24,10 +24,10 @@ import java.util.Map; import java.util.Set; import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; -import org.apache.skywalking.mqe.rt.type.MQEValue; -import org.apache.skywalking.mqe.rt.type.MQEValues; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValue; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValues; import org.apache.skywalking.oap.server.core.query.type.KeyValue; @FunctionalInterface diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/LogicalFunctionOp.java b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/LogicalFunctionOp.java index 912e6cf9256e..eedd93fab78b 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/LogicalFunctionOp.java +++ b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/LogicalFunctionOp.java @@ -21,10 +21,10 @@ import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; import org.apache.skywalking.mqe.rt.grammar.MQEParser; import org.apache.skywalking.mqe.rt.grammar.MQEParserBaseVisitor; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; -import org.apache.skywalking.mqe.rt.type.MQEValue; -import org.apache.skywalking.mqe.rt.type.MQEValues; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValue; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValues; import org.apache.skywalking.oap.server.library.util.CollectionUtils; import java.util.Objects; diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/MathematicalFunctionOp.java b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/MathematicalFunctionOp.java index 12e28a83d2f5..bd467e2654e4 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/MathematicalFunctionOp.java +++ b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/MathematicalFunctionOp.java @@ -23,7 +23,7 @@ import java.util.function.Function; import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; import org.apache.skywalking.mqe.rt.grammar.MQEParser; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; public class MathematicalFunctionOp { public static ExpressionResult doFunction0Op(ExpressionResult expResult, diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/SortLabelValuesOp.java b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/SortLabelValuesOp.java index 828e5e84a55e..97c09fb85f41 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/SortLabelValuesOp.java +++ b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/SortLabelValuesOp.java @@ -25,8 +25,8 @@ import lombok.extern.slf4j.Slf4j; import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; import org.apache.skywalking.mqe.rt.grammar.MQEParser; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.MQEValues; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValues; import org.apache.skywalking.oap.server.core.query.type.KeyValue; import org.apache.skywalking.oap.server.library.util.CollectionUtils; diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/SortValuesOp.java b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/SortValuesOp.java index 44053555f994..e6dc6baecf11 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/SortValuesOp.java +++ b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/SortValuesOp.java @@ -24,8 +24,8 @@ import java.util.stream.Collectors; import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; import org.apache.skywalking.mqe.rt.grammar.MQEParser; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.MQEValue; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValue; public class SortValuesOp { public static ExpressionResult doSortValuesOp(ExpressionResult expResult, diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/TrendOp.java b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/TrendOp.java index 60c0887be363..ec5bfc4abbf4 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/TrendOp.java +++ b/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/TrendOp.java @@ -22,8 +22,8 @@ import java.util.List; import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; import org.apache.skywalking.mqe.rt.grammar.MQEParser; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.MQEValue; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValue; import org.apache.skywalking.oap.server.core.query.enumeration.Step; public class TrendOp { diff --git a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/AggregateLabelsOpTest.java b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/AggregateLabelsOpTest.java index 690cc4ee22ac..429eae818197 100644 --- a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/AggregateLabelsOpTest.java +++ b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/AggregateLabelsOpTest.java @@ -22,8 +22,8 @@ import java.util.List; import org.apache.skywalking.mqe.rt.grammar.MQEParser; import org.apache.skywalking.mqe.rt.operation.AggregateLabelsOp; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/AggregationOpTest.java b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/AggregationOpTest.java index a0fd9f80fb1c..e56042630700 100644 --- a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/AggregationOpTest.java +++ b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/AggregationOpTest.java @@ -20,8 +20,8 @@ import org.apache.skywalking.mqe.rt.grammar.MQEParser; import org.apache.skywalking.mqe.rt.operation.AggregationOp; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/BinaryOpTest.java b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/BinaryOpTest.java index ea5e3d56f349..30bbb63a043b 100644 --- a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/BinaryOpTest.java +++ b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/BinaryOpTest.java @@ -21,8 +21,8 @@ import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; import org.apache.skywalking.mqe.rt.grammar.MQEParser; import org.apache.skywalking.mqe.rt.operation.BinaryOp; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/CompareOPTest.java b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/CompareOPTest.java index b112cd9ce10d..d25643363390 100644 --- a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/CompareOPTest.java +++ b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/CompareOPTest.java @@ -21,8 +21,8 @@ import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; import org.apache.skywalking.mqe.rt.grammar.MQEParser; import org.apache.skywalking.mqe.rt.operation.CompareOp; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/LogicalFunctionOpTest.java b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/LogicalFunctionOpTest.java index e174afe2bfe9..88dceeda4d02 100644 --- a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/LogicalFunctionOpTest.java +++ b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/LogicalFunctionOpTest.java @@ -21,7 +21,7 @@ import org.apache.skywalking.mqe.rt.grammar.MQEParser; import org.apache.skywalking.mqe.rt.grammar.MQEParserBaseVisitor; import org.apache.skywalking.mqe.rt.operation.LogicalFunctionOp; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; diff --git a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/MathematicalFunctionOpTest.java b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/MathematicalFunctionOpTest.java index e63f6a96801d..6986b9d15ad3 100644 --- a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/MathematicalFunctionOpTest.java +++ b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/MathematicalFunctionOpTest.java @@ -20,8 +20,8 @@ import org.apache.skywalking.mqe.rt.grammar.MQEParser; import org.apache.skywalking.mqe.rt.operation.MathematicalFunctionOp; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/MockData.java b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/MockData.java index ff25c1e9974c..941f8a9cc8e4 100644 --- a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/MockData.java +++ b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/MockData.java @@ -18,11 +18,11 @@ package org.apache.skywalking.mqe.rt; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; -import org.apache.skywalking.mqe.rt.type.MQEValue; -import org.apache.skywalking.mqe.rt.type.MQEValues; -import org.apache.skywalking.mqe.rt.type.Metadata; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValue; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValues; +import org.apache.skywalking.oap.server.core.query.mqe.Metadata; import org.apache.skywalking.oap.server.core.query.type.KeyValue; public class MockData { diff --git a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/SortLabelValuesOpTest.java b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/SortLabelValuesOpTest.java index 61ab428bccec..fcba56142564 100644 --- a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/SortLabelValuesOpTest.java +++ b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/SortLabelValuesOpTest.java @@ -22,7 +22,7 @@ import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; import org.apache.skywalking.mqe.rt.grammar.MQEParser; import org.apache.skywalking.mqe.rt.operation.SortLabelValuesOp; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/SortValuesOpTest.java b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/SortValuesOpTest.java index fd964b266650..0360f09fbe66 100644 --- a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/SortValuesOpTest.java +++ b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/SortValuesOpTest.java @@ -22,7 +22,7 @@ import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; import org.apache.skywalking.mqe.rt.grammar.MQEParser; import org.apache.skywalking.mqe.rt.operation.SortValuesOp; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/TrendOpTest.java b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/TrendOpTest.java index 3c5514123837..eb8c7b337801 100644 --- a/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/TrendOpTest.java +++ b/oap-server/mqe-rt/src/test/java/org/apache/skywalking/mqe/rt/TrendOpTest.java @@ -20,8 +20,8 @@ import org.apache.skywalking.mqe.rt.grammar.MQEParser; import org.apache.skywalking.mqe.rt.operation.TrendOp; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; import org.apache.skywalking.oap.server.core.query.enumeration.Step; import org.junit.jupiter.api.Test; diff --git a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmRule.java b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmRule.java index ab8b3643813b..1e7da460ff1c 100644 --- a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmRule.java +++ b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmRule.java @@ -35,8 +35,8 @@ import org.apache.skywalking.mqe.rt.exception.ParseErrorListener; import org.apache.skywalking.mqe.rt.grammar.MQELexer; import org.apache.skywalking.mqe.rt.grammar.MQEParser; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; import org.apache.skywalking.oap.server.core.alarm.provider.expr.rt.AlarmMQEVerifyVisitor; import org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingTraceContext; import org.apache.skywalking.oap.server.core.storage.annotation.ValueColumnMetadata; diff --git a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmRulesWatcher.java b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmRulesWatcher.java index 07a30d5ce79d..9bf584899742 100644 --- a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmRulesWatcher.java +++ b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/AlarmRulesWatcher.java @@ -131,7 +131,7 @@ public void notify(Rules newRules) { this.runningContext = newRunningContext; this.alarmRuleRunningRuleMap = newAlarmRuleRunningRuleMap; this.exprMetricsMap = newExprMetricsMap; - log.info("Update alarm rules to {}", rules); + log.debug("Update alarm rules to {}", rules); } @Override diff --git a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/RunningRule.java b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/RunningRule.java index f7dc2b89efec..aa3de66d7d25 100644 --- a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/RunningRule.java +++ b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/RunningRule.java @@ -18,6 +18,7 @@ package org.apache.skywalking.oap.server.core.alarm.provider; +import com.google.gson.JsonObject; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; @@ -39,9 +40,9 @@ import org.apache.skywalking.mqe.rt.exception.ParseErrorListener; import org.apache.skywalking.mqe.rt.grammar.MQELexer; import org.apache.skywalking.mqe.rt.grammar.MQEParser; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; -import org.apache.skywalking.mqe.rt.type.MQEValues; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValues; import org.apache.skywalking.oap.server.core.alarm.provider.expr.rt.AlarmMQEVisitor; import org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingTraceContext; import org.apache.skywalking.oap.server.library.util.StringUtil; @@ -224,6 +225,8 @@ public List check() { alarmMessage.setPeriod(this.period); alarmMessage.setTags(this.tags); alarmMessage.setHooks(this.hooks); + alarmMessage.setExpression(expression); + alarmMessage.setMqeMetricsSnapshot(window.mqeMetricsSnapshot); alarmMessageList.add(alarmMessage); } }); @@ -243,6 +246,7 @@ public class Window { private int silenceCountdown; private LinkedList> values; private ReentrantLock lock = new ReentrantLock(); + private JsonObject mqeMetricsSnapshot; public Window(int period, int additionalPeriod) { this.additionalPeriod = additionalPeriod; @@ -395,6 +399,7 @@ private boolean isMatch() { if (log.isTraceEnabled()) { log.trace("Match expression is {}", expression); } + this.mqeMetricsSnapshot = visitor.getMqeMetricsSnapshot(); return isMatch == 1; } finally { TRACE_CONTEXT.remove(); diff --git a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/expr/rt/AlarmMQEVerifyVisitor.java b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/expr/rt/AlarmMQEVerifyVisitor.java index df4989949abe..e9482c4e6fe4 100644 --- a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/expr/rt/AlarmMQEVerifyVisitor.java +++ b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/expr/rt/AlarmMQEVerifyVisitor.java @@ -25,10 +25,10 @@ import lombok.extern.slf4j.Slf4j; import org.apache.skywalking.mqe.rt.MQEVisitorBase; import org.apache.skywalking.mqe.rt.grammar.MQEParser; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; -import org.apache.skywalking.mqe.rt.type.MQEValue; -import org.apache.skywalking.mqe.rt.type.MQEValues; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValue; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValues; import org.apache.skywalking.oap.server.core.query.enumeration.Step; import org.apache.skywalking.oap.server.core.storage.annotation.Column; import org.apache.skywalking.oap.server.core.storage.annotation.ValueColumnMetadata; diff --git a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/expr/rt/AlarmMQEVisitor.java b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/expr/rt/AlarmMQEVisitor.java index ed8c82b3b61c..3b8f07b1643c 100644 --- a/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/expr/rt/AlarmMQEVisitor.java +++ b/oap-server/server-alarm-plugin/src/main/java/org/apache/skywalking/oap/server/core/alarm/provider/expr/rt/AlarmMQEVisitor.java @@ -18,6 +18,8 @@ package org.apache.skywalking.oap.server.core.alarm.provider.expr.rt; +import com.google.gson.Gson; +import com.google.gson.JsonObject; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; @@ -25,12 +27,13 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.skywalking.mqe.rt.grammar.MQEParser; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; -import org.apache.skywalking.mqe.rt.type.MQEValue; -import org.apache.skywalking.mqe.rt.type.MQEValues; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValue; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValues; import org.apache.skywalking.oap.server.core.analysis.metrics.DataLabel; import org.apache.skywalking.oap.server.core.analysis.metrics.DataTable; import org.apache.skywalking.oap.server.core.analysis.metrics.DoubleValueHolder; @@ -57,6 +60,12 @@ public class AlarmMQEVisitor extends MQEVisitorBase { private final LocalDateTime endTime; private final ArrayList windowTimes; private final int maxTrendRange; + /** + * The snapshot of metrics values. + */ + @Getter + private final JsonObject mqeMetricsSnapshot; + private final static Gson GSON = new Gson(); public AlarmMQEVisitor(final LinkedList> metricsValues, final LocalDateTime endTime, @@ -69,6 +78,7 @@ public AlarmMQEVisitor(final LinkedList> metricsValues, this.windowSize = metricsValues.size(); this.windowTimes = initWindowTimes(); this.maxTrendRange = maxTrendRange; + this.mqeMetricsSnapshot = new JsonObject(); this.initMetricsValues(); } @@ -119,6 +129,7 @@ public ExpressionResult visitMetric(MQEParser.MetricContext ctx) { } result.setResults(mqeValuesList); result.setType(ExpressionResultType.TIME_SERIES_VALUES); + this.mqeMetricsSnapshot.addProperty(metricName, GSON.toJson(mqeValuesList)); return result; } @@ -222,13 +233,13 @@ private List buildLabledMqeValuesList(Map timeValu } else { mqeValue.setEmptyValue(true); } - DataLabel dataLabel = new DataLabel(); - dataLabel.put(labelCondition); - for (Map.Entry label : dataLabel.entrySet()) { - mqeValues.getMetric().getLabels().add(new KeyValue(label.getKey(), label.getValue())); - } mqeValues.getValues().add(mqeValue); } + DataLabel dataLabel = new DataLabel(); + dataLabel.put(labelCondition); + for (Map.Entry label : dataLabel.entrySet()) { + mqeValues.getMetric().getLabels().add(new KeyValue(label.getKey(), label.getValue())); + } //Sort labels by key in natural order by default mqeValues.getMetric().sortLabelsByKey(Comparator.naturalOrder()); mqeValuesList.add(mqeValues); diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmMessage.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmMessage.java index a2e25e2e42fd..e644eb93062b 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmMessage.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmMessage.java @@ -18,12 +18,12 @@ package org.apache.skywalking.oap.server.core.alarm; +import com.google.gson.JsonObject; import java.util.HashSet; import java.util.Set; import lombok.Getter; import lombok.Setter; import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.Tag; - import java.util.List; /** @@ -43,4 +43,6 @@ public class AlarmMessage { private long startTime; private transient int period; private Set hooks = new HashSet<>(); + private String expression; + private JsonObject mqeMetricsSnapshot; } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmRecord.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmRecord.java index a79a0b44ed3a..c15c3afb7e64 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmRecord.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmRecord.java @@ -18,6 +18,7 @@ package org.apache.skywalking.oap.server.core.alarm; +import com.google.gson.Gson; import lombok.Getter; import lombok.Setter; import org.apache.skywalking.oap.server.core.analysis.Stream; @@ -34,9 +35,7 @@ import org.apache.skywalking.oap.server.core.storage.type.Convert2Entity; import org.apache.skywalking.oap.server.core.storage.type.Convert2Storage; import org.apache.skywalking.oap.server.core.storage.type.StorageBuilder; - import java.util.List; - import static org.apache.skywalking.oap.server.core.storage.StorageData.TIME_BUCKET; import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ALARM; @@ -47,7 +46,7 @@ @SQLDatabase.ExtraColumn4AdditionalEntity(additionalTable = AlarmRecord.ADDITIONAL_TAG_TABLE, parentColumn = TIME_BUCKET) @BanyanDB.TimestampColumn(AlarmRecord.START_TIME) public class AlarmRecord extends Record { - + private static final Gson GSON = new Gson(); public static final String INDEX_NAME = "alarm_record"; public static final String ADDITIONAL_TAG_TABLE = "alarm_record_tag"; public static final String SCOPE = "scope"; @@ -59,6 +58,7 @@ public class AlarmRecord extends Record { public static final String RULE_NAME = "rule_name"; public static final String TAGS = "tags"; public static final String TAGS_RAW_DATA = "tags_raw_data"; + public static final String SNAPSHOT = "snapshot"; @Override public StorageID id() { @@ -92,6 +92,8 @@ public StorageID id() { private List tagsInString; @Column(name = TAGS_RAW_DATA, storageOnly = true, length = Tag.TAG_LENGTH) private byte[] tagsRawData; + @Column(name = SNAPSHOT, storageOnly = true, length = 50000) + private String snapshot; public static class Builder implements StorageBuilder { @Override @@ -106,6 +108,7 @@ public AlarmRecord storage2Entity(final Convert2Entity converter) { record.setTimeBucket(((Number) converter.get(TIME_BUCKET)).longValue()); record.setRuleName((String) converter.get(RULE_NAME)); record.setTagsRawData(converter.getBytes(TAGS_RAW_DATA)); + record.setSnapshot((String) converter.get(SNAPSHOT)); // Don't read the TAGS as they are only for query. return record; } @@ -122,6 +125,7 @@ public void entity2Storage(final AlarmRecord storageData, final Convert2Storage converter.accept(RULE_NAME, storageData.getRuleName()); converter.accept(TAGS_RAW_DATA, storageData.getTagsRawData()); converter.accept(TAGS, storageData.getTagsInString()); + converter.accept(SNAPSHOT, storageData.getSnapshot()); } } } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmSnapshotRecord.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmSnapshotRecord.java new file mode 100644 index 000000000000..f09a6551c900 --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmSnapshotRecord.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.skywalking.oap.server.core.alarm; + +import com.google.gson.JsonObject; +import lombok.Data; + +@Data +public class AlarmSnapshotRecord { + private String expression; + private JsonObject metrics; +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmStandardPersistence.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmStandardPersistence.java index 0e1b17fd8925..3851ba81a0ed 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmStandardPersistence.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmStandardPersistence.java @@ -31,7 +31,6 @@ import org.apache.skywalking.oap.server.library.module.ModuleManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -71,6 +70,10 @@ public void doAlarm(List alarmMessage) { addAutocompleteTags(tags, TimeBucket.getMinuteTimeBucket(message.getStartTime())); record.setTagsRawData(gson.toJson(message.getTags()).getBytes(Charsets.UTF_8)); record.setTagsInString(Tag.Util.toStringList(new ArrayList<>(tags))); + AlarmSnapshotRecord snapshot = new AlarmSnapshotRecord(); + snapshot.setExpression(message.getExpression()); + snapshot.setMetrics(message.getMqeMetricsSnapshot()); + record.setSnapshot(gson.toJson(snapshot)); RecordStreamProcessor.getInstance().in(record); }); } diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/ExpressionResult.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/ExpressionResult.java similarity index 95% rename from oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/ExpressionResult.java rename to oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/ExpressionResult.java index 350e1fd7fe34..92b0fd26cd9e 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/ExpressionResult.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/ExpressionResult.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.skywalking.mqe.rt.type; +package org.apache.skywalking.oap.server.core.query.mqe; import java.util.ArrayList; import java.util.List; diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/ExpressionResultType.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/ExpressionResultType.java similarity index 95% rename from oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/ExpressionResultType.java rename to oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/ExpressionResultType.java index cb72e903cacf..1d4d478ea65f 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/ExpressionResultType.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/ExpressionResultType.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.skywalking.mqe.rt.type; +package org.apache.skywalking.oap.server.core.query.mqe; public enum ExpressionResultType { diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/MQEMetric.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/MQEMetric.java new file mode 100644 index 000000000000..1b52ce8805ef --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/MQEMetric.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.skywalking.oap.server.core.query.mqe; + +import java.util.List; +import lombok.Data; + +@Data +public class MQEMetric { + private String name; + private List results; +} diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/MQEValue.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/MQEValue.java similarity index 95% rename from oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/MQEValue.java rename to oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/MQEValue.java index 2147323bb355..a3acbfe5423c 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/MQEValue.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/MQEValue.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.skywalking.mqe.rt.type; +package org.apache.skywalking.oap.server.core.query.mqe; import lombok.Data; import org.apache.skywalking.oap.server.core.query.type.Owner; diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/MQEValues.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/MQEValues.java similarity index 94% rename from oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/MQEValues.java rename to oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/MQEValues.java index b98ed487f7e4..7c234994122f 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/MQEValues.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/MQEValues.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.skywalking.mqe.rt.type; +package org.apache.skywalking.oap.server.core.query.mqe; import java.util.ArrayList; import java.util.List; diff --git a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/Metadata.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/Metadata.java similarity index 95% rename from oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/Metadata.java rename to oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/Metadata.java index 49592646cc5f..c1be33a0efc2 100644 --- a/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/type/Metadata.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/mqe/Metadata.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.skywalking.mqe.rt.type; +package org.apache.skywalking.oap.server.core.query.mqe; import java.util.ArrayList; import java.util.Comparator; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/AlarmMessage.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/AlarmMessage.java index 8608c86ef023..7ff8e5306ccd 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/AlarmMessage.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/AlarmMessage.java @@ -32,11 +32,13 @@ public class AlarmMessage { private Scope scope; private int scopeId; private String id; + private String name; private String message; private Long startTime; private transient String id1; private final List tags; private List events = new ArrayList<>(2); + private AlarmSnapshot snapshot = new AlarmSnapshot(); public AlarmMessage() { tags = new ArrayList<>(); diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/AlarmSnapshot.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/AlarmSnapshot.java new file mode 100644 index 000000000000..841df9f6c538 --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/AlarmSnapshot.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.skywalking.oap.server.core.query.type; + +import java.util.ArrayList; +import java.util.List; +import lombok.Data; +import org.apache.skywalking.oap.server.core.query.mqe.MQEMetric; + +@Data +public class AlarmSnapshot { + private String expression; + private List metrics = new ArrayList<>(); +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/AlarmTrend.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/AlarmTrend.java deleted file mode 100644 index b0c27fdb476f..000000000000 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/type/AlarmTrend.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.skywalking.oap.server.core.query.type; - -import java.util.ArrayList; -import java.util.List; -import lombok.Getter; - -@Getter -public class AlarmTrend { - - private final List numOfAlarm; - - public AlarmTrend() { - this.numOfAlarm = new ArrayList<>(); - } -} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IAlarmQueryDAO.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IAlarmQueryDAO.java index 6f61226a5b2a..f59fb1cd1564 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IAlarmQueryDAO.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IAlarmQueryDAO.java @@ -18,6 +18,7 @@ package org.apache.skywalking.oap.server.core.storage.query; +import com.google.gson.JsonObject; import java.io.IOException; import java.util.Base64; import java.util.List; @@ -25,11 +26,19 @@ import com.google.common.base.Charsets; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import org.apache.skywalking.oap.server.core.alarm.AlarmRecord; +import org.apache.skywalking.oap.server.core.alarm.AlarmSnapshotRecord; import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.Tag; +import org.apache.skywalking.oap.server.core.query.enumeration.Scope; import org.apache.skywalking.oap.server.core.query.input.Duration; +import org.apache.skywalking.oap.server.core.query.mqe.MQEMetric; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValues; +import org.apache.skywalking.oap.server.core.query.type.AlarmMessage; +import org.apache.skywalking.oap.server.core.query.type.AlarmSnapshot; import org.apache.skywalking.oap.server.core.query.type.Alarms; import org.apache.skywalking.oap.server.core.query.type.KeyValue; import org.apache.skywalking.oap.server.core.storage.DAO; +import org.apache.skywalking.oap.server.library.util.StringUtil; public interface IAlarmQueryDAO extends DAO { @@ -39,18 +48,54 @@ Alarms getAlarm(final Integer scopeId, final String keyword, final int limit, fi final Duration duration, final List tags) throws IOException; /** - * Parser the raw tags. + * Parse the raw tags. */ - default void parserDataBinaryBase64(String dataBinaryBase64, List tags) { - parserDataBinary(Base64.getDecoder().decode(dataBinaryBase64), tags); + default void parseDataBinaryBase64(String dataBinaryBase64, List tags) { + parseDataBinary(Base64.getDecoder().decode(dataBinaryBase64), tags); } /** - * Parser the raw tags. + * Parse the raw tags. */ - default void parserDataBinary(byte[] dataBinary, List tags) { + default void parseDataBinary(byte[] dataBinary, List tags) { List tagList = GSON.fromJson(new String(dataBinary, Charsets.UTF_8), new TypeToken>() { }.getType()); tagList.forEach(pair -> tags.add(new KeyValue(pair.getKey(), pair.getValue()))); } + + /** + * Build the alarm message from the alarm record. + * The Tags in JDBC storage is base64 encoded, need to decode in different way. + */ + default AlarmMessage buildAlarmMessage(AlarmRecord alarmRecord) { + AlarmMessage message = new AlarmMessage(); + message.setId(String.valueOf(alarmRecord.getId0())); + message.setId1(String.valueOf(alarmRecord.getId1())); + message.setName(alarmRecord.getName()); + message.setMessage(alarmRecord.getAlarmMessage()); + message.setStartTime(alarmRecord.getStartTime()); + message.setScope(Scope.Finder.valueOf(alarmRecord.getScope())); + message.setScopeId(alarmRecord.getScope()); + AlarmSnapshot alarmSnapshot = message.getSnapshot(); + message.setSnapshot(alarmSnapshot); + String snapshot = alarmRecord.getSnapshot(); + if (StringUtil.isNotBlank(snapshot)) { + AlarmSnapshotRecord alarmSnapshotRecord = GSON.fromJson(snapshot, AlarmSnapshotRecord.class); + alarmSnapshot.setExpression(alarmSnapshotRecord.getExpression()); + JsonObject jsonObject = alarmSnapshotRecord.getMetrics(); + if (jsonObject != null) { + for (final var obj : jsonObject.entrySet()) { + final var name = obj.getKey(); + MQEMetric metrics = new MQEMetric(); + metrics.setName(name); + List values = GSON.fromJson( + obj.getValue().getAsString(), new TypeToken>() { + }.getType()); + metrics.setResults(values); + alarmSnapshot.getMetrics().add(metrics); + } + } + } + return message; + } } diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/mqe/rt/MQEVisitor.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/mqe/rt/MQEVisitor.java index b2b5c79226cd..ed7290e905d0 100644 --- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/mqe/rt/MQEVisitor.java +++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/mqe/rt/MQEVisitor.java @@ -27,8 +27,8 @@ import lombok.extern.slf4j.Slf4j; import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException; import org.apache.skywalking.mqe.rt.grammar.MQEParser; -import org.apache.skywalking.mqe.rt.type.MQEValue; -import org.apache.skywalking.mqe.rt.type.MQEValues; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValue; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValues; import org.apache.skywalking.oap.server.core.CoreModule; import org.apache.skywalking.oap.server.core.analysis.metrics.DataLabel; import org.apache.skywalking.oap.server.core.query.AggregationQueryService; @@ -54,8 +54,8 @@ import org.apache.skywalking.oap.server.core.storage.annotation.ValueColumnMetadata; import org.apache.skywalking.oap.server.library.module.ModuleManager; import org.apache.skywalking.mqe.rt.MQEVisitorBase; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; import org.apache.skywalking.oap.server.library.util.StringUtil; import org.joda.time.DateTime; diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/AlarmQuery.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/AlarmQuery.java index ab7815d55103..3cf1dc4ba422 100644 --- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/AlarmQuery.java +++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/AlarmQuery.java @@ -20,6 +20,7 @@ import graphql.kickstart.tools.GraphQLQueryResolver; import graphql.schema.DataFetchingEnvironment; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -38,7 +39,6 @@ import org.apache.skywalking.oap.server.core.query.enumeration.Scope; import org.apache.skywalking.oap.server.core.query.input.Duration; import org.apache.skywalking.oap.server.core.query.type.AlarmMessage; -import org.apache.skywalking.oap.server.core.query.type.AlarmTrend; import org.apache.skywalking.oap.server.core.query.type.Alarms; import org.apache.skywalking.oap.server.core.query.type.Pagination; import org.apache.skywalking.oap.server.core.query.type.event.Event; @@ -64,8 +64,11 @@ public class AlarmQuery implements GraphQLQueryResolver { private TagAutoCompleteQueryService tagQueryService; + private final DecimalFormat valueFormat = new DecimalFormat(); + public AlarmQuery(ModuleManager moduleManager) { this.moduleManager = moduleManager; + this.valueFormat.setGroupingUsed(false); } private AlarmQueryService getQueryService() { @@ -89,10 +92,6 @@ private TagAutoCompleteQueryService getTagQueryService() { return tagQueryService; } - public AlarmTrend getAlarmTrend(final Duration duration) { - return new AlarmTrend(); - } - public CompletableFuture getAlarm(final Duration duration, final Scope scope, final String keyword, final Pagination paging, final List tags, final DataFetchingEnvironment env) { @@ -110,6 +109,18 @@ public CompletableFuture getAlarm(final Duration duration, final Scope s Alarms alarms = getQueryService().getAlarm( scopeId, keyword, paging, duration, tags); + alarms.getMsgs().forEach(msg -> { + msg.getSnapshot().getMetrics().forEach(metric -> { + metric.getResults().forEach(mqeValues -> { + mqeValues.getValues().forEach(mqeValue -> { + if (!mqeValue.isEmptyValue()) { + mqeValue.setValue(valueFormat.format(mqeValue.getDoubleValue())); + } + }); + }); + }); + }); + final boolean selectEvents = env.getSelectionSet().contains("**/events/**"); if (selectEvents) { diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/MetricsExpressionQuery.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/MetricsExpressionQuery.java index bef4329ba679..43af2986dba5 100644 --- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/MetricsExpressionQuery.java +++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/MetricsExpressionQuery.java @@ -27,8 +27,8 @@ import org.antlr.v4.runtime.tree.ParseTree; import org.apache.skywalking.oap.query.graphql.mqe.rt.MQEVisitor; import org.apache.skywalking.mqe.rt.exception.ParseErrorListener; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; import org.apache.skywalking.oap.server.core.query.input.Entity; import org.apache.skywalking.oap.server.core.query.input.Duration; import org.apache.skywalking.oap.server.core.query.type.debugging.DebuggingTrace; diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol b/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol index 092856bdfefd..a9ed9eef09cf 160000 --- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol +++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol @@ -1 +1 @@ -Subproject commit 092856bdfefd2353d134efade62c6421b4ef4854 +Subproject commit a9ed9eef09cf97256df9a33eab91fca1ba13096e diff --git a/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/DebuggingHTTPHandler.java b/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/DebuggingHTTPHandler.java index 564f7c4354b9..c0025fdb8aa3 100644 --- a/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/DebuggingHTTPHandler.java +++ b/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/DebuggingHTTPHandler.java @@ -38,7 +38,7 @@ import java.util.stream.Collectors; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import org.apache.skywalking.mqe.rt.type.ExpressionResult; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult; import org.apache.skywalking.oap.query.debug.log.DebuggingQueryLogsRsp; import org.apache.skywalking.oap.query.debug.mqe.DebuggingMQERsp; import org.apache.skywalking.oap.query.debug.topology.DebuggingQueryEndpointTopologyRsp; diff --git a/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/mqe/DebuggingMQERsp.java b/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/mqe/DebuggingMQERsp.java index c9d09d4b22b5..cafa1752b2b8 100644 --- a/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/mqe/DebuggingMQERsp.java +++ b/oap-server/server-query-plugin/status-query-plugin/src/main/java/org/apache/skywalking/oap/query/debug/mqe/DebuggingMQERsp.java @@ -21,8 +21,8 @@ import java.util.List; import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.apache.skywalking.mqe.rt.type.ExpressionResultType; -import org.apache.skywalking.mqe.rt.type.MQEValues; +import org.apache.skywalking.oap.server.core.query.mqe.ExpressionResultType; +import org.apache.skywalking.oap.server.core.query.mqe.MQEValues; import org.apache.skywalking.oap.query.debug.DebuggingTraceRsp; @RequiredArgsConstructor diff --git a/oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/stream/BanyanDBAlarmQueryDAO.java b/oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/stream/BanyanDBAlarmQueryDAO.java index 2b5d15932ef9..00b1a85ac3b6 100644 --- a/oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/stream/BanyanDBAlarmQueryDAO.java +++ b/oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/stream/BanyanDBAlarmQueryDAO.java @@ -26,7 +26,6 @@ import org.apache.skywalking.oap.server.core.alarm.AlarmRecord; import org.apache.skywalking.oap.server.core.analysis.TimeBucket; import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.Tag; -import org.apache.skywalking.oap.server.core.query.enumeration.Scope; import org.apache.skywalking.oap.server.core.query.input.Duration; import org.apache.skywalking.oap.server.core.query.type.AlarmMessage; import org.apache.skywalking.oap.server.core.query.type.Alarms; @@ -49,7 +48,7 @@ public class BanyanDBAlarmQueryDAO extends AbstractBanyanDBDAO implements IAlarmQueryDAO { private static final Set TAGS = ImmutableSet.of(AlarmRecord.SCOPE, AlarmRecord.NAME, AlarmRecord.ID0, AlarmRecord.ID1, AlarmRecord.ALARM_MESSAGE, AlarmRecord.START_TIME, - AlarmRecord.RULE_NAME, AlarmRecord.TAGS, AlarmRecord.TAGS_RAW_DATA); + AlarmRecord.RULE_NAME, AlarmRecord.TAGS, AlarmRecord.TAGS_RAW_DATA, AlarmRecord.SNAPSHOT); public BanyanDBAlarmQueryDAO(BanyanDBStorageClient client) { super(client); @@ -95,18 +94,11 @@ public void apply(StreamQuery query) { AlarmRecord alarmRecord = builder.storage2Entity( new BanyanDBConverter.StorageToStream(AlarmRecord.INDEX_NAME, rowEntity) ); - - AlarmMessage message = new AlarmMessage(); - message.setId(String.valueOf(alarmRecord.getId0())); - message.setId1(String.valueOf(alarmRecord.getId1())); - message.setMessage(alarmRecord.getAlarmMessage()); - message.setStartTime(alarmRecord.getStartTime()); - message.setScope(Scope.Finder.valueOf(alarmRecord.getScope())); - message.setScopeId(alarmRecord.getScope()); + AlarmMessage alarmMessage = buildAlarmMessage(alarmRecord); if (!CollectionUtils.isEmpty(alarmRecord.getTagsRawData())) { - parserDataBinary(alarmRecord.getTagsRawData(), message.getTags()); + parseDataBinary(alarmRecord.getTagsRawData(), alarmMessage.getTags()); } - alarms.getMsgs().add(message); + alarms.getMsgs().add(alarmMessage); } return alarms; } diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AlarmQueryEsDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AlarmQueryEsDAO.java index bd41f769ef1c..03b2f9eb6087 100644 --- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AlarmQueryEsDAO.java +++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AlarmQueryEsDAO.java @@ -31,7 +31,6 @@ import org.apache.skywalking.library.elasticsearch.response.search.SearchResponse; import org.apache.skywalking.oap.server.core.alarm.AlarmRecord; import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.Tag; -import org.apache.skywalking.oap.server.core.query.enumeration.Scope; import org.apache.skywalking.oap.server.core.query.input.Duration; import org.apache.skywalking.oap.server.core.query.type.AlarmMessage; import org.apache.skywalking.oap.server.core.query.type.Alarms; @@ -93,18 +92,11 @@ public Alarms getAlarm(final Integer scopeId, final String keyword, final int li for (SearchHit searchHit : response.getHits().getHits()) { AlarmRecord.Builder builder = new AlarmRecord.Builder(); AlarmRecord alarmRecord = builder.storage2Entity(new ElasticSearchConverter.ToEntity(AlarmRecord.INDEX_NAME, searchHit.getSource())); - - AlarmMessage message = new AlarmMessage(); - message.setId(String.valueOf(alarmRecord.getId0())); - message.setId1(String.valueOf(alarmRecord.getId1())); - message.setMessage(alarmRecord.getAlarmMessage()); - message.setStartTime(alarmRecord.getStartTime()); - message.setScope(Scope.Finder.valueOf(alarmRecord.getScope())); - message.setScopeId(alarmRecord.getScope()); + AlarmMessage alarmMessage = buildAlarmMessage(alarmRecord); if (!CollectionUtils.isEmpty(alarmRecord.getTagsRawData())) { - parserDataBinary(alarmRecord.getTagsRawData(), message.getTags()); + parseDataBinary(alarmRecord.getTagsRawData(), alarmMessage.getTags()); } - alarms.getMsgs().add(message); + alarms.getMsgs().add(alarmMessage); } return alarms; } diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCAlarmQueryDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCAlarmQueryDAO.java index 588f393af144..42aa3622aea4 100644 --- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCAlarmQueryDAO.java +++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCAlarmQueryDAO.java @@ -18,6 +18,7 @@ package org.apache.skywalking.oap.server.storage.plugin.jdbc.common.dao; +import com.google.common.base.Charsets; import com.google.common.base.Strings; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; @@ -27,7 +28,6 @@ import org.apache.skywalking.oap.server.core.alarm.AlarmRecord; import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.Tag; import org.apache.skywalking.oap.server.core.config.ConfigService; -import org.apache.skywalking.oap.server.core.query.enumeration.Scope; import org.apache.skywalking.oap.server.core.query.input.Duration; import org.apache.skywalking.oap.server.core.query.type.AlarmMessage; import org.apache.skywalking.oap.server.core.query.type.Alarms; @@ -35,6 +35,7 @@ import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCClient; import org.apache.skywalking.oap.server.library.module.ModuleManager; import org.apache.skywalking.oap.server.library.util.CollectionUtils; +import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.JDBCEntityConverters; import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.JDBCTableInstaller; import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.SQLAndParameters; import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.TableHelper; @@ -88,18 +89,14 @@ public Alarms getAlarm(Integer scopeId, String keyword, int limit, int from, final var sqlAndParameters = buildSQL(scopeId, keyword, limit, from, duration, tags, table); jdbcClient.executeQuery(sqlAndParameters.sql(), resultSet -> { while (resultSet.next()) { - final var message = new AlarmMessage(); - message.setId(resultSet.getString(AlarmRecord.ID0)); - message.setId1(resultSet.getString(AlarmRecord.ID1)); - message.setMessage(resultSet.getString(AlarmRecord.ALARM_MESSAGE)); - message.setStartTime(resultSet.getLong(AlarmRecord.START_TIME)); - message.setScope(Scope.Finder.valueOf(resultSet.getInt(AlarmRecord.SCOPE))); - message.setScopeId(resultSet.getInt(AlarmRecord.SCOPE)); - String dataBinaryBase64 = resultSet.getString(AlarmRecord.TAGS_RAW_DATA); - if (!Strings.isNullOrEmpty(dataBinaryBase64)) { - parserDataBinaryBase64(dataBinaryBase64, message.getTags()); + AlarmRecord.Builder builder = new AlarmRecord.Builder(); + AlarmRecord alarmRecord = builder.storage2Entity(JDBCEntityConverters.toEntity(resultSet)); + AlarmMessage alarmMessage = buildAlarmMessage(alarmRecord); + if (!CollectionUtils.isEmpty(alarmRecord.getTagsRawData())) { + parseDataBinaryBase64( + new String(alarmRecord.getTagsRawData(), Charsets.UTF_8), alarmMessage.getTags()); } - alarmMsgs.add(message); + alarmMsgs.add(alarmMessage); } return null; }, sqlAndParameters.parameters());