Move MQE codes to independent Maven module in`oap-server`. (#11176)
This commit is contained in:
parent
95155f9fce
commit
a4c7705ddf
|
|
@ -19,7 +19,7 @@ OALLexer.tokens
|
|||
.externalToolBuilders
|
||||
oap-server/oal-grammar/**/gen/
|
||||
MQELexer.tokens
|
||||
oap-server/server-query-plugin/mqe-grammar/gen/
|
||||
oap-server/mqe-grammar/**/gen/
|
||||
PromQLLexer.tokens
|
||||
oap-server/server-query-plugin/promql-plugin/gen/
|
||||
LogQLLexer.tokens
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@
|
|||
~
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>server-query-plugin</artifactId>
|
||||
<artifactId>oap-server</artifactId>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<version>9.6.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
~
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>oap-server</artifactId>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<version>9.6.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>mqe-rt</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<artifactId>server-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<artifactId>library-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<artifactId>mqe-grammar</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,209 @@
|
|||
/*
|
||||
* 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.mqe.rt;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.skywalking.mqe.rt.grammar.MQEParser;
|
||||
import org.apache.skywalking.mqe.rt.grammar.MQEParserBaseVisitor;
|
||||
import org.apache.skywalking.mqe.rt.operation.AggregateLabelsOp;
|
||||
import org.apache.skywalking.mqe.rt.operation.AggregationOp;
|
||||
import org.apache.skywalking.mqe.rt.operation.BinaryOp;
|
||||
import org.apache.skywalking.mqe.rt.operation.FunctionOp;
|
||||
import org.apache.skywalking.mqe.rt.type.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.Const;
|
||||
import org.apache.skywalking.oap.server.library.util.StringUtil;
|
||||
|
||||
@Slf4j
|
||||
public abstract class MQEVisitorBase extends MQEParserBaseVisitor<ExpressionResult> {
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitAddSubOp(MQEParser.AddSubOpContext ctx) {
|
||||
ExpressionResult left = visit(ctx.expression(0));
|
||||
if (StringUtil.isNotBlank(left.getError())) {
|
||||
return left;
|
||||
}
|
||||
ExpressionResult right = visit(ctx.expression(1));
|
||||
if (StringUtil.isNotBlank(right.getError())) {
|
||||
return right;
|
||||
}
|
||||
int opType = ctx.addSub().getStart().getType();
|
||||
try {
|
||||
return BinaryOp.doBinaryOp(left, right, opType);
|
||||
} catch (IllegalExpressionException e) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
result.setType(ExpressionResultType.UNKNOWN);
|
||||
result.setError(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitMulDivModOp(MQEParser.MulDivModOpContext ctx) {
|
||||
ExpressionResult left = visit(ctx.expression(0));
|
||||
if (StringUtil.isNotBlank(left.getError())) {
|
||||
return left;
|
||||
}
|
||||
ExpressionResult right = visit(ctx.expression(1));
|
||||
if (StringUtil.isNotBlank(right.getError())) {
|
||||
return right;
|
||||
}
|
||||
int opType = ctx.mulDivMod().getStart().getType();
|
||||
try {
|
||||
return BinaryOp.doBinaryOp(left, right, opType);
|
||||
} catch (IllegalExpressionException e) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
result.setType(ExpressionResultType.UNKNOWN);
|
||||
result.setError(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitScalar(MQEParser.ScalarContext ctx) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
double value = Double.parseDouble(ctx.getText());
|
||||
MQEValue mqeValue = new MQEValue();
|
||||
mqeValue.setDoubleValue(value);
|
||||
mqeValue.setEmptyValue(false);
|
||||
MQEValues mqeValues = new MQEValues();
|
||||
mqeValues.getValues().add(mqeValue);
|
||||
result.getResults().add(mqeValues);
|
||||
result.setType(ExpressionResultType.SINGLE_VALUE);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitAggregationOp(MQEParser.AggregationOpContext ctx) {
|
||||
int opType = ctx.aggregation().getStart().getType();
|
||||
ExpressionResult expResult = visit(ctx.expression());
|
||||
if (StringUtil.isNotEmpty(expResult.getError())) {
|
||||
return expResult;
|
||||
}
|
||||
try {
|
||||
return AggregationOp.doAggregationOp(expResult, opType);
|
||||
} catch (IllegalExpressionException e) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
result.setType(ExpressionResultType.UNKNOWN);
|
||||
result.setError(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitAggregateLabelsOp(final MQEParser.AggregateLabelsOpContext ctx) {
|
||||
int funcType = ctx.aggregateLabelsFunc().getStart().getType();
|
||||
ExpressionResult expResult = visit(ctx.expression());
|
||||
if (StringUtil.isNotEmpty(expResult.getError())) {
|
||||
return expResult;
|
||||
}
|
||||
|
||||
if (!expResult.isLabeledResult()) {
|
||||
expResult.setError("The result of expression [" + ctx.expression().getText() + "] is not a labeled result.");
|
||||
return expResult;
|
||||
}
|
||||
|
||||
try {
|
||||
return AggregateLabelsOp.doAggregateLabelsOp(expResult, funcType);
|
||||
} catch (IllegalExpressionException e) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
result.setType(ExpressionResultType.UNKNOWN);
|
||||
result.setError(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitFunction0OP(MQEParser.Function0OPContext ctx) {
|
||||
int opType = ctx.function0().getStart().getType();
|
||||
ExpressionResult expResult = visit(ctx.expression());
|
||||
if (StringUtil.isNotEmpty(expResult.getError())) {
|
||||
return expResult;
|
||||
}
|
||||
try {
|
||||
return FunctionOp.doFunction0Op(expResult, opType);
|
||||
} catch (IllegalExpressionException e) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
result.setType(ExpressionResultType.UNKNOWN);
|
||||
result.setError(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitFunction1OP(MQEParser.Function1OPContext ctx) {
|
||||
int opType = ctx.function1().getStart().getType();
|
||||
ExpressionResult expResult = visit(ctx.expression());
|
||||
if (StringUtil.isNotEmpty(expResult.getError())) {
|
||||
return expResult;
|
||||
}
|
||||
try {
|
||||
return FunctionOp.doFunction1Op(expResult, opType, Integer.parseInt(ctx.parameter().INTEGER().getText()));
|
||||
} catch (IllegalExpressionException e) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
result.setType(ExpressionResultType.UNKNOWN);
|
||||
result.setError(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitTopNOP(MQEParser.TopNOPContext ctx) {
|
||||
return visit(ctx.metric());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitRelablesOP(MQEParser.RelablesOPContext ctx) {
|
||||
ExpressionResult result = visit(ctx.expression());
|
||||
if (!result.isLabeledResult()) {
|
||||
// Reserve the original result type
|
||||
result.setError("The result of expression [" + ctx.expression().getText() + "] is not a labeled result.");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<String> relabelList = Collections.emptyList();
|
||||
String newLabelValue = ctx.label().labelValue().getText();
|
||||
String labelValueTrim = newLabelValue.substring(1, newLabelValue.length() - 1);
|
||||
if (StringUtil.isNotBlank(labelValueTrim)) {
|
||||
relabelList = Arrays.asList(labelValueTrim.split(Const.COMMA));
|
||||
}
|
||||
List<MQEValues> mqeValuesList = result.getResults();
|
||||
|
||||
if (mqeValuesList.size() != relabelList.size()) {
|
||||
// Reserve the original result type
|
||||
result.setError("The number of relabels is not equal to the number of labels.");
|
||||
return result;
|
||||
}
|
||||
// For now, we only have a single label named `label`
|
||||
for (int i = 0; i < mqeValuesList.size(); i++) {
|
||||
mqeValuesList.get(i).getMetric().getLabels().get(0).setValue(relabelList.get(i));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract ExpressionResult visitMetric(MQEParser.MetricContext ctx);
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe.rt.exception;
|
||||
package org.apache.skywalking.mqe.rt.exception;
|
||||
|
||||
public class IllegalExpressionException extends Exception {
|
||||
public IllegalExpressionException(String message) {
|
||||
|
|
@ -16,9 +16,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe.rt.exception;
|
||||
package org.apache.skywalking.mqe.rt.exception;
|
||||
|
||||
import graphql.org.antlr.v4.runtime.misc.ParseCancellationException;
|
||||
import org.antlr.v4.runtime.misc.ParseCancellationException;
|
||||
import org.antlr.v4.runtime.BaseErrorListener;
|
||||
import org.antlr.v4.runtime.RecognitionException;
|
||||
import org.antlr.v4.runtime.Recognizer;
|
||||
|
|
@ -16,22 +16,22 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe.rt.operation;
|
||||
package org.apache.skywalking.mqe.rt.operation;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException;
|
||||
import org.apache.skywalking.mqe.rt.grammar.MQEParser;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.exception.IllegalExpressionException;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.operation.aggregatelabels.AggregateLabelsFunc;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.operation.aggregatelabels.AggregateLabelsFuncFactory;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.operation.aggregatelabels.AvgAggregateLabelsFunc;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.operation.aggregatelabels.MaxAggregateLabelsFunc;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.operation.aggregatelabels.MinAggregateLabelsFunc;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.operation.aggregatelabels.SumAggregateLabelsFunc;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResult;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.MQEValue;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.MQEValues;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.Metadata;
|
||||
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.mqe.rt.operation.aggregatelabels.AggregateLabelsFunc;
|
||||
import org.apache.skywalking.mqe.rt.operation.aggregatelabels.AggregateLabelsFuncFactory;
|
||||
import org.apache.skywalking.mqe.rt.operation.aggregatelabels.AvgAggregateLabelsFunc;
|
||||
import org.apache.skywalking.mqe.rt.operation.aggregatelabels.MaxAggregateLabelsFunc;
|
||||
import org.apache.skywalking.mqe.rt.operation.aggregatelabels.MinAggregateLabelsFunc;
|
||||
import org.apache.skywalking.mqe.rt.operation.aggregatelabels.SumAggregateLabelsFunc;
|
||||
import org.apache.skywalking.mqe.rt.type.Metadata;
|
||||
import org.apache.skywalking.oap.server.library.util.CollectionUtils;
|
||||
|
||||
public class AggregateLabelsOp {
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe.rt.operation;
|
||||
package org.apache.skywalking.mqe.rt.operation;
|
||||
|
||||
import com.google.common.collect.Streams;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -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.oap.query.graphql.mqe.rt.exception.IllegalExpressionException;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResult;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResultType;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.MQEValue;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.MQEValues;
|
||||
import org.apache.skywalking.mqe.rt.type.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;
|
||||
|
||||
public class AggregationOp {
|
||||
public static ExpressionResult doAggregationOp(ExpressionResult result,
|
||||
|
|
@ -16,17 +16,17 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe.rt.operation;
|
||||
package org.apache.skywalking.mqe.rt.operation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.skywalking.mqe.rt.exception.IllegalExpressionException;
|
||||
import org.apache.skywalking.mqe.rt.grammar.MQEParser;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.exception.IllegalExpressionException;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResult;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResultType;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.MQEValue;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.MQEValues;
|
||||
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.type.KeyValue;
|
||||
|
||||
public class BinaryOp {
|
||||
|
|
@ -16,14 +16,14 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe.rt.operation;
|
||||
package org.apache.skywalking.mqe.rt.operation;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
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.oap.query.graphql.mqe.rt.exception.IllegalExpressionException;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResult;
|
||||
import org.apache.skywalking.mqe.rt.type.ExpressionResult;
|
||||
|
||||
public class FunctionOp {
|
||||
public static ExpressionResult doFunction0Op(ExpressionResult expResult,
|
||||
|
|
@ -16,10 +16,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe.rt.operation.aggregatelabels;
|
||||
package org.apache.skywalking.mqe.rt.operation.aggregatelabels;
|
||||
|
||||
public interface AggregateLabelsFunc {
|
||||
void combine(Double value);
|
||||
|
||||
Double getResult();
|
||||
}
|
||||
}
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe.rt.operation.aggregatelabels;
|
||||
package org.apache.skywalking.mqe.rt.operation.aggregatelabels;
|
||||
|
||||
public interface AggregateLabelsFuncFactory {
|
||||
AggregateLabelsFunc getAggregateLabelsFunc();
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe.rt.operation.aggregatelabels;
|
||||
package org.apache.skywalking.mqe.rt.operation.aggregatelabels;
|
||||
|
||||
public class AvgAggregateLabelsFunc implements AggregateLabelsFunc {
|
||||
|
||||
|
|
@ -46,4 +46,4 @@ public class AvgAggregateLabelsFunc implements AggregateLabelsFunc {
|
|||
|
||||
return sum / count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe.rt.operation.aggregatelabels;
|
||||
package org.apache.skywalking.mqe.rt.operation.aggregatelabels;
|
||||
|
||||
public class MaxAggregateLabelsFunc implements AggregateLabelsFunc {
|
||||
|
||||
|
|
@ -41,4 +41,4 @@ public class MaxAggregateLabelsFunc implements AggregateLabelsFunc {
|
|||
public Double getResult() {
|
||||
return max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe.rt.operation.aggregatelabels;
|
||||
package org.apache.skywalking.mqe.rt.operation.aggregatelabels;
|
||||
|
||||
public class MinAggregateLabelsFunc implements AggregateLabelsFunc {
|
||||
|
||||
|
|
@ -41,4 +41,4 @@ public class MinAggregateLabelsFunc implements AggregateLabelsFunc {
|
|||
public Double getResult() {
|
||||
return min;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe.rt.operation.aggregatelabels;
|
||||
package org.apache.skywalking.mqe.rt.operation.aggregatelabels;
|
||||
|
||||
public class SumAggregateLabelsFunc implements AggregateLabelsFunc {
|
||||
|
||||
|
|
@ -39,4 +39,4 @@ public class SumAggregateLabelsFunc implements AggregateLabelsFunc {
|
|||
public Double getResult() {
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.type.mql;
|
||||
package org.apache.skywalking.mqe.rt.type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.type.mql;
|
||||
package org.apache.skywalking.mqe.rt.type;
|
||||
|
||||
public enum ExpressionResultType {
|
||||
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.type.mql;
|
||||
package org.apache.skywalking.mqe.rt.type;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.type.mql;
|
||||
package org.apache.skywalking.mqe.rt.type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.type.mql;
|
||||
package org.apache.skywalking.mqe.rt.type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -16,12 +16,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe;
|
||||
package org.apache.skywalking.library.mqe.rt;
|
||||
|
||||
import org.apache.skywalking.mqe.rt.grammar.MQEParser;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.operation.AggregateLabelsOp;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResult;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResultType;
|
||||
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.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
|
@ -16,12 +16,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe;
|
||||
package org.apache.skywalking.library.mqe.rt;
|
||||
|
||||
import org.apache.skywalking.mqe.rt.grammar.MQEParser;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.operation.AggregationOp;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResult;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResultType;
|
||||
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.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
|
@ -16,12 +16,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe;
|
||||
package org.apache.skywalking.library.mqe.rt;
|
||||
|
||||
import org.apache.skywalking.mqe.rt.grammar.MQEParser;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.operation.BinaryOp;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResult;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResultType;
|
||||
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.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
|
@ -16,12 +16,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe;
|
||||
package org.apache.skywalking.library.mqe.rt;
|
||||
|
||||
import org.apache.skywalking.mqe.rt.grammar.MQEParser;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.operation.FunctionOp;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResult;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResultType;
|
||||
import org.apache.skywalking.mqe.rt.operation.FunctionOp;
|
||||
import org.apache.skywalking.mqe.rt.type.ExpressionResult;
|
||||
import org.apache.skywalking.mqe.rt.type.ExpressionResultType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
|
@ -16,13 +16,13 @@
|
|||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.query.graphql.mqe;
|
||||
package org.apache.skywalking.library.mqe.rt;
|
||||
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResult;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResultType;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.MQEValue;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.MQEValues;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.Metadata;
|
||||
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.type.KeyValue;
|
||||
|
||||
public class MockData {
|
||||
|
|
@ -48,6 +48,8 @@
|
|||
<module>server-health-checker</module>
|
||||
<module>microbench</module>
|
||||
<module>ai-pipeline</module>
|
||||
<module>mqe-grammar</module>
|
||||
<module>mqe-rt</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@
|
|||
<modules>
|
||||
<module>query-graphql-plugin</module>
|
||||
<module>zipkin-query-plugin</module>
|
||||
<module>mqe-grammar</module>
|
||||
<module>promql-plugin</module>
|
||||
<module>logql-plugin</module>
|
||||
</modules>
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<artifactId>mqe-grammar</artifactId>
|
||||
<artifactId>mqe-rt</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -25,16 +25,13 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.exception.IllegalExpressionException;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.operation.AggregateLabelsOp;
|
||||
import org.apache.skywalking.oap.query.graphql.mqe.rt.operation.AggregationOp;
|
||||
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.mqe.rt.type.Metadata;
|
||||
import org.apache.skywalking.oap.query.graphql.resolver.MetricsQuery;
|
||||
import org.apache.skywalking.oap.query.graphql.resolver.RecordsQuery;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResult;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResultType;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.MQEValue;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.MQEValues;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.Metadata;
|
||||
import org.apache.skywalking.oap.server.core.Const;
|
||||
import org.apache.skywalking.oap.server.core.query.DurationUtils;
|
||||
import org.apache.skywalking.oap.server.core.query.PointOfTime;
|
||||
|
|
@ -52,15 +49,12 @@ import org.apache.skywalking.oap.server.core.query.type.SelectedRecord;
|
|||
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.util.StringUtil;
|
||||
import org.apache.skywalking.mqe.rt.grammar.MQEParser;
|
||||
import org.apache.skywalking.mqe.rt.grammar.MQEParserBaseVisitor;
|
||||
|
||||
import static org.apache.skywalking.oap.query.graphql.mqe.rt.operation.BinaryOp.doBinaryOp;
|
||||
import static org.apache.skywalking.oap.query.graphql.mqe.rt.operation.FunctionOp.doFunction0Op;
|
||||
import static org.apache.skywalking.oap.query.graphql.mqe.rt.operation.FunctionOp.doFunction1Op;
|
||||
import org.apache.skywalking.mqe.rt.MQEVisitorBase;
|
||||
import org.apache.skywalking.mqe.rt.type.ExpressionResult;
|
||||
import org.apache.skywalking.mqe.rt.type.ExpressionResultType;
|
||||
|
||||
@Slf4j
|
||||
public class MQEVisitor extends MQEParserBaseVisitor<ExpressionResult> {
|
||||
public class MQEVisitor extends MQEVisitorBase {
|
||||
private final MetricsQuery metricsQuery;
|
||||
private final RecordsQuery recordsQuery;
|
||||
private final Entity entity;
|
||||
|
|
@ -78,171 +72,6 @@ public class MQEVisitor extends MQEParserBaseVisitor<ExpressionResult> {
|
|||
this.duration = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitAddSubOp(MQEParser.AddSubOpContext ctx) {
|
||||
ExpressionResult left = visit(ctx.expression(0));
|
||||
if (StringUtil.isNotBlank(left.getError())) {
|
||||
return left;
|
||||
}
|
||||
ExpressionResult right = visit(ctx.expression(1));
|
||||
if (StringUtil.isNotBlank(right.getError())) {
|
||||
return right;
|
||||
}
|
||||
int opType = ctx.addSub().getStart().getType();
|
||||
try {
|
||||
return doBinaryOp(left, right, opType);
|
||||
} catch (IllegalExpressionException e) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
result.setType(ExpressionResultType.UNKNOWN);
|
||||
result.setError(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitMulDivModOp(MQEParser.MulDivModOpContext ctx) {
|
||||
ExpressionResult left = visit(ctx.expression(0));
|
||||
if (StringUtil.isNotBlank(left.getError())) {
|
||||
return left;
|
||||
}
|
||||
ExpressionResult right = visit(ctx.expression(1));
|
||||
if (StringUtil.isNotBlank(right.getError())) {
|
||||
return right;
|
||||
}
|
||||
int opType = ctx.mulDivMod().getStart().getType();
|
||||
try {
|
||||
return doBinaryOp(left, right, opType);
|
||||
} catch (IllegalExpressionException e) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
result.setType(ExpressionResultType.UNKNOWN);
|
||||
result.setError(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitScalar(MQEParser.ScalarContext ctx) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
double value = Double.parseDouble(ctx.getText());
|
||||
MQEValue mqeValue = new MQEValue();
|
||||
mqeValue.setDoubleValue(value);
|
||||
mqeValue.setEmptyValue(false);
|
||||
MQEValues mqeValues = new MQEValues();
|
||||
mqeValues.getValues().add(mqeValue);
|
||||
result.getResults().add(mqeValues);
|
||||
result.setType(ExpressionResultType.SINGLE_VALUE);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitAggregationOp(MQEParser.AggregationOpContext ctx) {
|
||||
int opType = ctx.aggregation().getStart().getType();
|
||||
ExpressionResult expResult = visit(ctx.expression());
|
||||
if (StringUtil.isNotEmpty(expResult.getError())) {
|
||||
return expResult;
|
||||
}
|
||||
try {
|
||||
return AggregationOp.doAggregationOp(expResult, opType);
|
||||
} catch (IllegalExpressionException e) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
result.setType(ExpressionResultType.UNKNOWN);
|
||||
result.setError(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitAggregateLabelsOp(final MQEParser.AggregateLabelsOpContext ctx) {
|
||||
int funcType = ctx.aggregateLabelsFunc().getStart().getType();
|
||||
ExpressionResult expResult = visit(ctx.expression());
|
||||
if (StringUtil.isNotEmpty(expResult.getError())) {
|
||||
return expResult;
|
||||
}
|
||||
|
||||
if (!expResult.isLabeledResult()) {
|
||||
expResult.setError("The result of expression [" + ctx.expression().getText() + "] is not a labeled result.");
|
||||
return expResult;
|
||||
}
|
||||
|
||||
try {
|
||||
return AggregateLabelsOp.doAggregateLabelsOp(expResult, funcType);
|
||||
} catch (IllegalExpressionException e) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
result.setType(ExpressionResultType.UNKNOWN);
|
||||
result.setError(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitFunction0OP(MQEParser.Function0OPContext ctx) {
|
||||
int opType = ctx.function0().getStart().getType();
|
||||
ExpressionResult expResult = visit(ctx.expression());
|
||||
if (StringUtil.isNotEmpty(expResult.getError())) {
|
||||
return expResult;
|
||||
}
|
||||
try {
|
||||
return doFunction0Op(expResult, opType);
|
||||
} catch (IllegalExpressionException e) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
result.setType(ExpressionResultType.UNKNOWN);
|
||||
result.setError(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitFunction1OP(MQEParser.Function1OPContext ctx) {
|
||||
int opType = ctx.function1().getStart().getType();
|
||||
ExpressionResult expResult = visit(ctx.expression());
|
||||
if (StringUtil.isNotEmpty(expResult.getError())) {
|
||||
return expResult;
|
||||
}
|
||||
try {
|
||||
return doFunction1Op(expResult, opType, Integer.parseInt(ctx.parameter().INTEGER().getText()));
|
||||
} catch (IllegalExpressionException e) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
result.setType(ExpressionResultType.UNKNOWN);
|
||||
result.setError(e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitTopNOP(MQEParser.TopNOPContext ctx) {
|
||||
return visit(ctx.metric());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitRelablesOP(MQEParser.RelablesOPContext ctx) {
|
||||
ExpressionResult result = visit(ctx.expression());
|
||||
if (!result.isLabeledResult()) {
|
||||
// Reserve the original result type
|
||||
result.setError("The result of expression [" + ctx.expression().getText() + "] is not a labeled result.");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<String> relabelList = Collections.emptyList();
|
||||
String newLabelValue = ctx.label().labelValue().getText();
|
||||
String labelValueTrim = newLabelValue.substring(1, newLabelValue.length() - 1);
|
||||
if (StringUtil.isNotBlank(labelValueTrim)) {
|
||||
relabelList = Arrays.asList(labelValueTrim.split(Const.COMMA));
|
||||
}
|
||||
List<MQEValues> mqeValuesList = result.getResults();
|
||||
|
||||
if (mqeValuesList.size() != relabelList.size()) {
|
||||
// Resever the original result type
|
||||
result.setError("The number of relabels is not equal to the number of labels.");
|
||||
return result;
|
||||
}
|
||||
// For now, we only have a single label named `label`
|
||||
for (int i = 0; i < mqeValuesList.size(); i++) {
|
||||
mqeValuesList.get(i).getMetric().getLabels().get(0).setValue(relabelList.get(i));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionResult visitMetric(MQEParser.MetricContext ctx) {
|
||||
ExpressionResult result = new ExpressionResult();
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ import org.antlr.v4.runtime.CharStreams;
|
|||
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.oap.query.graphql.mqe.rt.exception.ParseErrorListener;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResult;
|
||||
import org.apache.skywalking.oap.query.graphql.type.mql.ExpressionResultType;
|
||||
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.input.Entity;
|
||||
import org.apache.skywalking.oap.server.core.query.input.Duration;
|
||||
import org.apache.skywalking.oap.server.library.module.ModuleManager;
|
||||
|
|
|
|||
Loading…
Reference in New Issue