Alarm: Support store and query the metrics snapshot when the alarm is triggered (#12910)
This commit is contained in:
parent
f8f5fa5206
commit
d3d3ee8abd
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ import org.apache.skywalking.mqe.rt.operation.MathematicalFunctionOp;
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ import java.util.LinkedHashMap;
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -27,11 +27,11 @@ import java.util.OptionalDouble;
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ package org.apache.skywalking.mqe.rt.operation;
|
|||
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ package org.apache.skywalking.mqe.rt.operation;
|
|||
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@ import java.util.List;
|
|||
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
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ package org.apache.skywalking.mqe.rt.operation;
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import java.math.RoundingMode;
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ import java.util.Map;
|
|||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ import java.util.Optional;
|
|||
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,
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ import java.util.ArrayList;
|
|||
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 {
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ import java.util.ArrayList;
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ package org.apache.skywalking.mqe.rt;
|
|||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ package org.apache.skywalking.mqe.rt;
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ package org.apache.skywalking.mqe.rt;
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ package org.apache.skywalking.mqe.rt;
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ package org.apache.skywalking.mqe.rt;
|
|||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ 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.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;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import java.util.Optional;
|
|||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ package org.apache.skywalking.mqe.rt;
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException;
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ public class AlarmRulesWatcher extends ConfigChangeWatcher {
|
|||
this.runningContext = newRunningContext;
|
||||
this.alarmRuleRunningRuleMap = newAlarmRuleRunningRuleMap;
|
||||
this.exprMetricsMap = newExprMetricsMap;
|
||||
log.info("Update alarm rules to {}", rules);
|
||||
log.debug("Update alarm rules to {}", rules);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -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.antlr.v4.runtime.tree.ParseTree;
|
|||
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 class RunningRule {
|
|||
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 RunningRule {
|
|||
private int silenceCountdown;
|
||||
private LinkedList<Map<String, Metrics>> values;
|
||||
private ReentrantLock lock = new ReentrantLock();
|
||||
private JsonObject mqeMetricsSnapshot;
|
||||
|
||||
public Window(int period, int additionalPeriod) {
|
||||
this.additionalPeriod = additionalPeriod;
|
||||
|
|
@ -395,6 +399,7 @@ public class RunningRule {
|
|||
if (log.isTraceEnabled()) {
|
||||
log.trace("Match expression is {}", expression);
|
||||
}
|
||||
this.mqeMetricsSnapshot = visitor.getMqeMetricsSnapshot();
|
||||
return isMatch == 1;
|
||||
} finally {
|
||||
TRACE_CONTEXT.remove();
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ import lombok.Getter;
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -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.LinkedList;
|
|||
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<String> 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<Map<String, Metrics>> metricsValues,
|
||||
final LocalDateTime endTime,
|
||||
|
|
@ -69,6 +78,7 @@ public class AlarmMQEVisitor extends MQEVisitorBase {
|
|||
this.windowSize = metricsValues.size();
|
||||
this.windowTimes = initWindowTimes();
|
||||
this.maxTrendRange = maxTrendRange;
|
||||
this.mqeMetricsSnapshot = new JsonObject();
|
||||
this.initMetricsValues();
|
||||
}
|
||||
|
||||
|
|
@ -119,6 +129,7 @@ public class AlarmMQEVisitor extends MQEVisitorBase {
|
|||
}
|
||||
result.setResults(mqeValuesList);
|
||||
result.setType(ExpressionResultType.TIME_SERIES_VALUES);
|
||||
this.mqeMetricsSnapshot.addProperty(metricName, GSON.toJson(mqeValuesList));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -222,13 +233,13 @@ public class AlarmMQEVisitor extends MQEVisitorBase {
|
|||
} else {
|
||||
mqeValue.setEmptyValue(true);
|
||||
}
|
||||
DataLabel dataLabel = new DataLabel();
|
||||
dataLabel.put(labelCondition);
|
||||
for (Map.Entry<String, String> 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<String, String> 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);
|
||||
|
|
|
|||
|
|
@ -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<String> hooks = new HashSet<>();
|
||||
private String expression;
|
||||
private JsonObject mqeMetricsSnapshot;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.annotation.SQLDatabase;
|
|||
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 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.AL
|
|||
@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 class AlarmRecord extends Record {
|
|||
private List<String> 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<AlarmRecord> {
|
||||
@Override
|
||||
|
|
@ -106,6 +108,7 @@ public class AlarmRecord extends Record {
|
|||
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 class AlarmRecord extends Record {
|
|||
converter.accept(RULE_NAME, storageData.getRuleName());
|
||||
converter.accept(TAGS_RAW_DATA, storageData.getTagsRawData());
|
||||
converter.accept(TAGS, storageData.getTagsInString());
|
||||
converter.accept(SNAPSHOT, storageData.getSnapshot());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -31,7 +31,6 @@ import org.apache.skywalking.oap.server.core.source.TagAutocomplete;
|
|||
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 class AlarmStandardPersistence implements AlarmCallback {
|
|||
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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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 {
|
||||
|
||||
|
|
@ -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<MQEValues> results;
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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<KeyValue> tags;
|
||||
private List<Event> events = new ArrayList<>(2);
|
||||
private AlarmSnapshot snapshot = new AlarmSnapshot();
|
||||
|
||||
public AlarmMessage() {
|
||||
tags = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -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<MQEMetric> metrics = new ArrayList<>();
|
||||
}
|
||||
|
|
@ -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<Integer> numOfAlarm;
|
||||
|
||||
public AlarmTrend() {
|
||||
this.numOfAlarm = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
|
@ -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 java.util.List;
|
|||
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 @@ public interface IAlarmQueryDAO extends DAO {
|
|||
final Duration duration, final List<Tag> tags) throws IOException;
|
||||
|
||||
/**
|
||||
* Parser the raw tags.
|
||||
* Parse the raw tags.
|
||||
*/
|
||||
default void parserDataBinaryBase64(String dataBinaryBase64, List<KeyValue> tags) {
|
||||
parserDataBinary(Base64.getDecoder().decode(dataBinaryBase64), tags);
|
||||
default void parseDataBinaryBase64(String dataBinaryBase64, List<KeyValue> tags) {
|
||||
parseDataBinary(Base64.getDecoder().decode(dataBinaryBase64), tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parser the raw tags.
|
||||
* Parse the raw tags.
|
||||
*/
|
||||
default void parserDataBinary(byte[] dataBinary, List<KeyValue> tags) {
|
||||
default void parseDataBinary(byte[] dataBinary, List<KeyValue> tags) {
|
||||
List<Tag> tagList = GSON.fromJson(new String(dataBinary, Charsets.UTF_8), new TypeToken<List<Tag>>() {
|
||||
}.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<MQEValues> values = GSON.fromJson(
|
||||
obj.getValue().getAsString(), new TypeToken<List<MQEValues>>() {
|
||||
}.getType());
|
||||
metrics.setResults(values);
|
||||
alarmSnapshot.getMetrics().add(metrics);
|
||||
}
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ import java.util.Optional;
|
|||
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.Column;
|
|||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package org.apache.skywalking.oap.query.graphql.resolver;
|
|||
|
||||
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.TagAutoCompleteQueryService;
|
|||
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 @@ public class AlarmQuery implements GraphQLQueryResolver {
|
|||
return tagQueryService;
|
||||
}
|
||||
|
||||
public AlarmTrend getAlarmTrend(final Duration duration) {
|
||||
return new AlarmTrend();
|
||||
}
|
||||
|
||||
public CompletableFuture<Alarms> getAlarm(final Duration duration, final Scope scope, final String keyword,
|
||||
final Pagination paging, final List<Tag> tags,
|
||||
final DataFetchingEnvironment env) {
|
||||
|
|
@ -110,6 +109,18 @@ public class AlarmQuery implements GraphQLQueryResolver {
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ import org.antlr.v4.runtime.CommonTokenStream;
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 092856bdfefd2353d134efade62c6421b4ef4854
|
||||
Subproject commit a9ed9eef09cf97256df9a33eab91fca1ba13096e
|
||||
|
|
@ -38,7 +38,7 @@ import java.util.Optional;
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ package org.apache.skywalking.oap.query.debug.mqe;
|
|||
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
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import org.apache.skywalking.banyandb.v1.client.TimestampRange;
|
|||
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 @@ import java.util.Set;
|
|||
public class BanyanDBAlarmQueryDAO extends AbstractBanyanDBDAO implements IAlarmQueryDAO {
|
||||
private static final Set<String> 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 class BanyanDBAlarmQueryDAO extends AbstractBanyanDBDAO implements IAlarm
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import org.apache.skywalking.library.elasticsearch.response.search.SearchHit;
|
|||
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 class AlarmQueryEsDAO extends EsDAO implements IAlarmQueryDAO {
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.CoreModule;
|
|||
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.core.storage.query.IAlarmQueryDAO;
|
|||
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 class JDBCAlarmQueryDAO implements IAlarmQueryDAO {
|
|||
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());
|
||||
|
|
|
|||
Loading…
Reference in New Issue