Skip to content

Commit

Permalink
feat(query-profile): add DTO and VO models for query profile (#2212)
Browse files Browse the repository at this point in the history
* support build graph by V$OB_SQL_PLAN

* use DO to build graph instead of query

* set title by objectName

* format code

* response to CR comments

* move UT

* update license

* response to CR comments

* format code

* remove reference for SqlProfileData

* update license
  • Loading branch information
LuckyPickleZZ authored Apr 16, 2024
1 parent 7e73479 commit f8bed43
Show file tree
Hide file tree
Showing 32 changed files with 900 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import com.oceanbase.odc.ServiceTestEnv;
import com.oceanbase.odc.common.event.LocalEventPublisher;
import com.oceanbase.odc.core.flow.graph.GraphEdge;
import com.oceanbase.odc.common.graph.GraphEdge;
import com.oceanbase.odc.metadb.flow.NodeInstanceEntity;
import com.oceanbase.odc.metadb.flow.NodeInstanceEntityRepository;
import com.oceanbase.odc.metadb.flow.SequenceInstanceEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.oceanbase.odc.core.flow.graph;
package com.oceanbase.odc.common.graph;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -44,7 +44,7 @@ public abstract class BaseGraphElement {
public BaseGraphElement(@NonNull String graphId, String name) {
this.name = name;
this.graphId = graphId;
this.attributes = new HashMap<>();
this.attributes = new LinkedHashMap<>();
}

public void setAttribute(@NonNull String key, Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.oceanbase.odc.core.flow.graph;
package com.oceanbase.odc.common.graph;

import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -26,6 +26,7 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -39,7 +40,9 @@
@Slf4j
public class Graph {

@Getter
protected final List<GraphEdge> edgeList = new LinkedList<>();
@Getter
protected final List<GraphVertex> vertexList = new LinkedList<>();
private final AtomicInteger edgeIdGenerator = new AtomicInteger(0);
public final static float INFINITE = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.oceanbase.odc.core.flow.graph;
package com.oceanbase.odc.common.graph;

import java.util.LinkedList;

import com.oceanbase.odc.core.shared.Verify;

import lombok.NonNull;

/**
Expand Down Expand Up @@ -99,7 +97,9 @@ private <E extends GraphEdge> GraphConfigurer<T, V> route(float weight, E graphE
return this;
}
V from = last();
Verify.notNull(from, "FromVertex");
if (from == null) {
throw new IllegalStateException("FromVertex should not be null");
}
if (target.contains(from) && target.contains(to)) {
if (target.getWeight(from.getGraphId(), to.getGraphId()) != Graph.INFINITE) {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.oceanbase.odc.core.flow.graph;
package com.oceanbase.odc.common.graph;

import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.oceanbase.odc.core.flow.graph;
package com.oceanbase.odc.common.graph;

import java.util.LinkedList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.oceanbase.odc.core.flow;
package com.oceanbase.odc.common.graph;

import java.util.HashMap;
import java.util.LinkedList;
Expand All @@ -31,10 +31,6 @@
import org.junit.rules.ExpectedException;

import com.oceanbase.odc.common.lang.Pair;
import com.oceanbase.odc.core.flow.graph.Graph;
import com.oceanbase.odc.core.flow.graph.GraphConfigurer;
import com.oceanbase.odc.core.flow.graph.GraphEdge;
import com.oceanbase.odc.core.flow.graph.GraphVertex;

/**
* Test cases for {@link Graph}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

import java.util.Optional;

import com.oceanbase.odc.common.graph.GraphConfigurer;
import com.oceanbase.odc.common.graph.GraphEdge;
import com.oceanbase.odc.core.flow.builder.BaseProcessNodeBuilder;
import com.oceanbase.odc.core.flow.builder.ConditionSequenceFlowBuilder;
import com.oceanbase.odc.core.flow.builder.EndEventBuilder;
import com.oceanbase.odc.core.flow.builder.ExclusiveGatewayBuilder;
import com.oceanbase.odc.core.flow.builder.FlowableProcessBuilder;
import com.oceanbase.odc.core.flow.builder.ParallelGatewayBuilder;
import com.oceanbase.odc.core.flow.builder.SequenceFlowBuilder;
import com.oceanbase.odc.core.flow.graph.GraphConfigurer;
import com.oceanbase.odc.core.flow.graph.GraphEdge;

import lombok.NonNull;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.flowable.bpmn.model.Activity;
import org.flowable.bpmn.model.BoundaryEvent;

import com.oceanbase.odc.core.flow.graph.GraphEdge;
import com.oceanbase.odc.common.graph.GraphEdge;

import lombok.NonNull;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import org.flowable.bpmn.model.FlowableListener;
import org.flowable.bpmn.model.FormProperty;

import com.oceanbase.odc.common.graph.GraphVertex;
import com.oceanbase.odc.core.flow.BaseExecutionListener;
import com.oceanbase.odc.core.flow.ProcessElementBuilder;
import com.oceanbase.odc.core.flow.graph.GraphVertex;
import com.oceanbase.odc.core.flow.util.FlowConstants;
import com.oceanbase.odc.core.flow.util.FlowIdGenerators;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.flowable.bpmn.model.EndEvent;

import com.oceanbase.odc.core.flow.graph.GraphEdge;
import com.oceanbase.odc.common.graph.GraphEdge;

import lombok.NonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import org.flowable.bpmn.model.Process;
import org.flowable.bpmn.model.SequenceFlow;

import com.oceanbase.odc.common.graph.Graph;
import com.oceanbase.odc.common.graph.GraphEdge;
import com.oceanbase.odc.common.graph.GraphVertex;
import com.oceanbase.odc.core.flow.BaseExecutionListener;
import com.oceanbase.odc.core.flow.ExecutionConfigurer;
import com.oceanbase.odc.core.flow.ProcessElementBuilder;
import com.oceanbase.odc.core.flow.graph.Graph;
import com.oceanbase.odc.core.flow.graph.GraphEdge;
import com.oceanbase.odc.core.flow.graph.GraphVertex;
import com.oceanbase.odc.core.flow.util.FlowConstants;
import com.oceanbase.odc.core.flow.util.FlowIdGenerators;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import org.flowable.bpmn.model.SequenceFlow;

import com.oceanbase.odc.common.graph.GraphEdge;
import com.oceanbase.odc.core.flow.ProcessElementBuilder;
import com.oceanbase.odc.core.flow.graph.GraphEdge;
import com.oceanbase.odc.core.flow.util.FlowIdGenerators;

import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.flowable.bpmn.model.FormProperty;
import org.flowable.bpmn.model.StartEvent;

import com.oceanbase.odc.core.flow.graph.GraphEdge;
import com.oceanbase.odc.core.flow.graph.GraphVertex;
import com.oceanbase.odc.common.graph.GraphEdge;
import com.oceanbase.odc.common.graph.GraphVertex;

import lombok.NonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;

import com.oceanbase.odc.common.graph.GraphVertex;
import com.oceanbase.odc.core.authority.model.SecurityResource;
import com.oceanbase.odc.core.flow.graph.GraphVertex;
import com.oceanbase.odc.core.flow.model.FlowableElement;
import com.oceanbase.odc.core.flow.model.FlowableElementType;
import com.oceanbase.odc.core.shared.OrganizationIsolated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;

import com.oceanbase.odc.common.graph.Graph;
import com.oceanbase.odc.common.graph.GraphEdge;
import com.oceanbase.odc.common.graph.GraphVertex;
import com.oceanbase.odc.common.lang.Pair;
import com.oceanbase.odc.core.authority.model.SecurityResource;
import com.oceanbase.odc.core.flow.BaseExecutionListener;
import com.oceanbase.odc.core.flow.ExecutionConfigurer;
import com.oceanbase.odc.core.flow.builder.FlowableProcessBuilder;
import com.oceanbase.odc.core.flow.graph.Graph;
import com.oceanbase.odc.core.flow.graph.GraphEdge;
import com.oceanbase.odc.core.flow.graph.GraphVertex;
import com.oceanbase.odc.core.flow.model.FlowableElement;
import com.oceanbase.odc.core.flow.util.FlowUtil;
import com.oceanbase.odc.core.shared.OrganizationIsolated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.flowable.bpmn.model.Gateway;
import org.flowable.bpmn.model.Task;

import com.oceanbase.odc.common.graph.GraphConfigurer;
import com.oceanbase.odc.core.flow.BaseExecutionListener;
import com.oceanbase.odc.core.flow.ExecutionConfigurer;
import com.oceanbase.odc.core.flow.builder.BaseProcessNodeBuilder;
Expand All @@ -41,7 +42,6 @@
import com.oceanbase.odc.core.flow.builder.ServiceTaskBuilder;
import com.oceanbase.odc.core.flow.builder.TimerBoundaryEventBuilder;
import com.oceanbase.odc.core.flow.builder.UserTaskBuilder;
import com.oceanbase.odc.core.flow.graph.GraphConfigurer;
import com.oceanbase.odc.core.flow.model.FlowableElement;
import com.oceanbase.odc.core.shared.Verify;
import com.oceanbase.odc.core.shared.constant.ErrorCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2023 OceanBase.
*
* Licensed 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 com.oceanbase.odc.service.queryprofile.display;

import java.util.List;
import java.util.Map;

import lombok.Data;

/**
* @author liuyizhuo.lyz
* @date 2024/4/11
*/
@Data
public class PlanGraph {
private List<PlanGraphEdge> edges;
private List<PlanGraphOperator> vertexes;
private Map<String, String> statistics;
private Map<String, String> overview;
private Map<String, List<String>> topNodes;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2023 OceanBase.
*
* Licensed 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 com.oceanbase.odc.service.queryprofile.display;

import lombok.Data;

/**
* @author liuyizhuo.lyz
* @date 2024/4/11
*/
@Data
public class PlanGraphEdge {
private String from;
private String to;
private Float weight;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2023 OceanBase.
*
* Licensed 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 com.oceanbase.odc.service.queryprofile.display;

import java.util.Map;

import com.oceanbase.odc.service.queryprofile.model.SqlProfile.Status;

import lombok.Data;

/**
* @author liuyizhuo.lyz
* @date 2024/4/11
*/
@Data
public class PlanGraphOperator {
private String graphId;
private String name;
private String title;
private Status status;
private Map<String, Object> attributes;
private Map<String, String> statistics;
private Map<String, String> overview;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2023 OceanBase.
*
* Licensed 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 com.oceanbase.odc.service.queryprofile.display;

import java.util.Date;

import com.oceanbase.odc.service.queryprofile.model.SqlProfile.Status;

import lombok.Data;

/**
* @author liuyizhuo.lyz
* @date 2024/4/11
*/
@Data
public class SqlProfile {
private Date startTime;
private Date endTime;
private Status status;
private Long duration;
private String traceId;
private String sqlText;
}
Loading

0 comments on commit f8bed43

Please sign in to comment.