diff --git a/docs/en/guides/source-extension.md b/docs/en/guides/source-extension.md index 47fc6f49f3149502b8c5fc6ab024b7416f0127f5..05602e857c1bcabccfd5ee0fce9ac5a4f7dcd503 100644 --- a/docs/en/guides/source-extension.md +++ b/docs/en/guides/source-extension.md @@ -18,10 +18,11 @@ Then it could be supported by OAL script and OAP core. Such as existed source, **Service**. ```java -@ScopeDeclaration(id = SERVICE, name = "Service") -public class Service extends Source { +@ScopeDeclaration(id = SERVICE_INSTANCE, name = "ServiceInstance", catalog = SERVICE_INSTANCE_CATALOG_NAME) +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) +public class ServiceInstance extends Source { @Override public int scope() { - return DefaultScopeDefine.SERVICE; + return DefaultScopeDefine.SERVICE_INSTANCE; } @Override public String getEntityId() { @@ -29,8 +30,9 @@ public class Service extends Source { } @Getter @Setter private int id; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_id") private int serviceId; @Getter @Setter private String name; - @Getter @Setter private String serviceInstanceName; + @Getter @Setter private String serviceName; @Getter @Setter private String endpointName; @Getter @Setter private int latency; @Getter @Setter private boolean status; @@ -47,13 +49,15 @@ Such as, in this Service scope, the id is service id, representing a particular service, like `Order` service. This value is used in [OAL group mechanism](../concepts-and-designs/oal.md#group). -5. Add scope name as keyword to oal grammar definition file, `OALLexer.g4`, which is at `antlr4` folder of `generate-tool-grammar` module. +5. `@ScopeDefaultColumn.VirtualColumnDefinition` and `@ScopeDefaultColumn.DefinedByField` are required, all declared fields(virtual/byField) +are going to be pushed into persistent entity, mapping to such as ElasticSearch index and Database table column. +Such as, include entity id mostly, and service id for endpoint and service instance level scope. Take a reference to all existing scopes. +All these fields are detected by OAL Runtime, and required in query stage. -6. Add scope name keyword as source in parser definition file, `OALParser.g4`, which is at same fold of `OALLexer.g4`. +6. Add scope name as keyword to oal grammar definition file, `OALLexer.g4`, which is at `antlr4` folder of `generate-tool-grammar` module. + +7. Add scope name keyword as source in parser definition file, `OALParser.g4`, which is at same fold of `OALLexer.g4`. -7. Set the default columns for new scope, at `generator-scope-meta.yml` file in `generated-analysis/src/main/resources`. -If you want to understand why need these columns, you have to understand all existing query(s). But there is an easy way, -follow other existing scopes. Such as, if you are adding metrics, connection number for service instance, follow existing `ServiceInstance`. ___ After you done all of these, you could build a receiver, which do diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALRuntime.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALRuntime.java index 7c983fcd61b4ce5e8b197a19e533d300c7fede4d..d7217b85b730236e0b04b1f018ef6186963505dd 100644 --- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALRuntime.java +++ b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALRuntime.java @@ -49,8 +49,6 @@ import javassist.bytecode.annotation.IntegerMemberValue; import javassist.bytecode.annotation.StringMemberValue; import org.apache.commons.io.FileUtils; import org.apache.skywalking.apm.util.StringUtil; -import org.apache.skywalking.oal.rt.meta.MetaReader; -import org.apache.skywalking.oal.rt.meta.MetaSettings; import org.apache.skywalking.oal.rt.output.AllDispatcherContext; import org.apache.skywalking.oal.rt.output.DispatcherContext; import org.apache.skywalking.oal.rt.parser.AnalysisResult; @@ -58,7 +56,6 @@ import org.apache.skywalking.oal.rt.parser.MetricsHolder; import org.apache.skywalking.oal.rt.parser.OALScripts; import org.apache.skywalking.oal.rt.parser.ScriptParser; import org.apache.skywalking.oal.rt.parser.SourceColumn; -import org.apache.skywalking.oal.rt.parser.SourceColumnsFactory; import org.apache.skywalking.oap.server.core.WorkPath; import org.apache.skywalking.oap.server.core.analysis.DisableRegister; import org.apache.skywalking.oap.server.core.analysis.DispatcherDetectorListener; @@ -131,15 +128,6 @@ public class OALRuntime implements OALEngine { this.currentClassLoader = currentClassLoader; Reader read; - try { - read = ResourceUtils.read("scope-meta.yml"); - } catch (FileNotFoundException e) { - throw new ModuleStartException("Can't locate scope-meta.yml", e); - } - - MetaReader reader = new MetaReader(); - MetaSettings metaSettings = reader.read(read); - SourceColumnsFactory.setSettings(metaSettings); try { MetricsHolder.init(); diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/meta/MetaReader.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/meta/MetaReader.java deleted file mode 100644 index 99339223a991a4e1b6062e793a53f594b6a8d2f2..0000000000000000000000000000000000000000 --- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/meta/MetaReader.java +++ /dev/null @@ -1,42 +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.oal.rt.meta; - -import java.io.InputStream; -import java.io.Reader; -import org.yaml.snakeyaml.Yaml; - -/** - * @author wusheng - */ -public class MetaReader { - public MetaSettings read(Reader reader) { - Yaml yaml = new Yaml(); - MetaSettings settings = yaml.loadAs(reader, MetaSettings.class); - - return settings; - } - - public MetaSettings read(InputStream reader) { - Yaml yaml = new Yaml(); - MetaSettings settings = yaml.loadAs(reader, MetaSettings.class); - - return settings; - } -} diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/meta/MetaSettings.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/meta/MetaSettings.java deleted file mode 100644 index 31b3cd365021248b0599515084a84cfce6c016bf..0000000000000000000000000000000000000000 --- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/meta/MetaSettings.java +++ /dev/null @@ -1,31 +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.oal.rt.meta; - -import java.util.List; -import lombok.*; - -/** - * @author wusheng - */ -@Setter -@Getter -public class MetaSettings { - private List scopes; -} diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/meta/ScopeMeta.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/meta/ScopeMeta.java deleted file mode 100644 index 7a674103d6096398a7526d3926dbe2dd2bf3ba19..0000000000000000000000000000000000000000 --- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/meta/ScopeMeta.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.skywalking.oal.rt.meta; - -import java.util.*; -import lombok.*; -import org.apache.skywalking.oal.rt.parser.SourceColumn; - -/** - * @author wusheng - */ -@Setter -@Getter -public class ScopeMeta { - private String name; - private List columns = new ArrayList<>(); -} diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumn.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumn.java index 49e16114f77f52373dacda3d80f3f0634f5c1881..b700abc65a9a3f04a619de3f3e0a6c762b5743f1 100644 --- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumn.java +++ b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumn.java @@ -33,9 +33,6 @@ public class SourceColumn { private String fieldSetter; private String fieldGetter; - public SourceColumn() { - } - public SourceColumn(String fieldName, String columnName, Class type, boolean isID) { this.fieldName = fieldName; this.columnName = columnName; diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumnsFactory.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumnsFactory.java index 7955503f9213456ced987f08d685fe0b7139512b..0830a1a17280727256830e100a1040a10d10797d 100644 --- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumnsFactory.java +++ b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/SourceColumnsFactory.java @@ -18,23 +18,22 @@ package org.apache.skywalking.oal.rt.parser; -import java.util.*; -import org.apache.skywalking.oal.rt.meta.*; +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine; +import org.apache.skywalking.oap.server.core.source.ScopeDefaultColumn; /** * @author wusheng */ public class SourceColumnsFactory { - private static Map SETTINGS; - - public static void setSettings(MetaSettings settings) { - SourceColumnsFactory.SETTINGS = new HashMap<>(); - settings.getScopes().forEach(scope -> { - SourceColumnsFactory.SETTINGS.put(scope.getName(), scope); - }); - } - public static List getColumns(String source) { - return SETTINGS.get(source).getColumns(); + List sourceColumns = new ArrayList<>(); + + List columns = DefaultScopeDefine.getDefaultColumns(source); + for (ScopeDefaultColumn defaultColumn : columns) { + sourceColumns.add(new SourceColumn(defaultColumn.getFieldName(), defaultColumn.getColumnName(), defaultColumn.getType(), defaultColumn.isID())); + } + return sourceColumns; } } diff --git a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/meta/MetaReaderTest.java b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/meta/MetaReaderTest.java deleted file mode 100644 index 17f506d8d374db3e21cde8b8bb49376743b9d198..0000000000000000000000000000000000000000 --- a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/meta/MetaReaderTest.java +++ /dev/null @@ -1,43 +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.oal.rt.meta; - -import java.io.InputStream; -import java.util.List; -import org.apache.skywalking.oal.rt.parser.SourceColumn; -import org.junit.*; - -public class MetaReaderTest { - @Test - public void testFileParser() { - MetaReader reader = new MetaReader(); - InputStream stream = MetaReaderTest.class.getResourceAsStream("/scope-meta.yml"); - MetaSettings metaSettings = reader.read(stream); - Assert.assertNotEquals(0, metaSettings.getScopes().size()); - - metaSettings.getScopes().forEach(scopeMeta -> { - List sourceColumns = MockSourceColumnsFactory.getColumns(scopeMeta.getName()); - for (int i = 0; i < sourceColumns.size(); i++) { - SourceColumn column = scopeMeta.getColumns().get(i); - SourceColumn expected = sourceColumns.get(i); - Assert.assertEquals(expected, column); - } - }); - } -} diff --git a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/meta/MockSourceColumnsFactory.java b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/meta/MockSourceColumnsFactory.java deleted file mode 100644 index 3d3c4b58ed1b518a907fbdec43ada780a634bbfe..0000000000000000000000000000000000000000 --- a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/meta/MockSourceColumnsFactory.java +++ /dev/null @@ -1,104 +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.oal.rt.meta; - -import java.util.*; -import org.apache.skywalking.oal.rt.parser.SourceColumn; - -public class MockSourceColumnsFactory { - public static List getColumns(String source) { - List columnList; - SourceColumn idColumn; - switch (source) { - case "All": - return new LinkedList<>(); - case "Service": - columnList = new LinkedList<>(); - // Service id; - idColumn = new SourceColumn("entityId", "entity_id", String.class, true); - columnList.add(idColumn); - return columnList; - case "ServiceInstance": - columnList = new LinkedList<>(); - // Service instance id; - idColumn = new SourceColumn("entityId", "entity_id", String.class, true); - columnList.add(idColumn); - SourceColumn serviceIdColumn = new SourceColumn("serviceId", "service_id", int.class, false); - columnList.add(serviceIdColumn); - return columnList; - case "Endpoint": - columnList = new LinkedList<>(); - // Endpoint id; - idColumn = new SourceColumn("entityId", "entity_id", String.class, true); - columnList.add(idColumn); - serviceIdColumn = new SourceColumn("serviceId", "service_id", int.class, false); - columnList.add(serviceIdColumn); - SourceColumn serviceInstanceIdColumn = new SourceColumn("serviceInstanceId", "service_instance_id", int.class, false); - columnList.add(serviceInstanceIdColumn); - return columnList; - case "ServiceInstanceJVMCPU": - case "ServiceInstanceJVMMemory": - case "ServiceInstanceJVMMemoryPool": - case "ServiceInstanceJVMGC": - columnList = new LinkedList<>(); - // Service instance id; - idColumn = new SourceColumn("entityId", "entity_id", String.class, true); - columnList.add(idColumn); - serviceInstanceIdColumn = new SourceColumn("serviceInstanceId", "service_instance_id", int.class, false); - columnList.add(serviceInstanceIdColumn); - return columnList; - case "ServiceRelation": - columnList = new LinkedList<>(); - SourceColumn sourceService = new SourceColumn("entityId", "entity_id", String.class, true); - columnList.add(sourceService); - return columnList; - case "ServiceInstanceRelation": - columnList = new LinkedList<>(); - sourceService = new SourceColumn("entityId", "entity_id", String.class, true); - columnList.add(sourceService); - sourceService = new SourceColumn("sourceServiceId", "source_service_id", int.class, false); - columnList.add(sourceService); - SourceColumn destService = new SourceColumn("destServiceId", "dest_service_id", int.class, false); - columnList.add(destService); - - return columnList; - case "EndpointRelation": - columnList = new LinkedList<>(); - SourceColumn sourceEndpointColumn = new SourceColumn("entityId", "entity_id", String.class, true); - columnList.add(sourceEndpointColumn); - sourceService = new SourceColumn("serviceId", "service_id", int.class, false); - columnList.add(sourceService); - destService = new SourceColumn("childServiceId", "child_service_id", int.class, false); - columnList.add(destService); - SourceColumn sourceServiceInstance = new SourceColumn("serviceInstanceId", "service_instance_id", int.class, false); - columnList.add(sourceServiceInstance); - SourceColumn destServiceInstance = new SourceColumn("childServiceInstanceId", "child_service_instance_id", int.class, false); - columnList.add(destServiceInstance); - return columnList; - case "DatabaseAccess": - columnList = new LinkedList<>(); - // Service id; - idColumn = new SourceColumn("entityId", "entity_id", String.class, true); - columnList.add(idColumn); - return columnList; - default: - throw new IllegalArgumentException("Illegal sourceScopeId :" + source); - } - } -} diff --git a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/DeepAnalysisTest.java b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/DeepAnalysisTest.java index 18b035ab39887492aefefb7c75935782c60def93..09f2c5420986546714a6daf0e4982cc64bf843a6 100644 --- a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/DeepAnalysisTest.java +++ b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/DeepAnalysisTest.java @@ -18,21 +18,30 @@ package org.apache.skywalking.oal.rt.parser; -import java.io.*; +import java.io.IOException; import java.util.List; -import org.apache.skywalking.oal.rt.meta.*; -import org.junit.*; +import org.apache.skywalking.oap.server.core.annotation.AnnotationScan; +import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class DeepAnalysisTest { @BeforeClass public static void init() throws IOException { - MetaReader reader = new MetaReader(); - InputStream stream = MetaReaderTest.class.getResourceAsStream("/scope-meta.yml"); - MetaSettings metaSettings = reader.read(stream); - SourceColumnsFactory.setSettings(metaSettings); + AnnotationScan scopeScan = new AnnotationScan(); + scopeScan.registerListener(new DefaultScopeDefine.Listener()); + scopeScan.scan(); + MetricsHolder.init(); } + @AfterClass + public static void clear() { + DefaultScopeDefine.reset(); + } + @Test public void testServiceAnalysis() { AnalysisResult result = new AnalysisResult(); diff --git a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/ScriptParserTest.java b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/ScriptParserTest.java index 35464db0334c9e9edee20791447d7e7114057533..0ee0c17c1489fe753a54bca2bb941826ead5b7d2 100644 --- a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/ScriptParserTest.java +++ b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/ScriptParserTest.java @@ -18,20 +18,18 @@ package org.apache.skywalking.oal.rt.parser; -import java.io.*; +import java.io.IOException; import java.util.List; -import org.apache.skywalking.oal.rt.meta.*; import org.apache.skywalking.oap.server.core.annotation.AnnotationScan; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine; -import org.junit.*; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; public class ScriptParserTest { @BeforeClass public static void init() throws IOException { - MetaReader reader = new MetaReader(); - InputStream stream = MetaReaderTest.class.getResourceAsStream("/scope-meta.yml"); - MetaSettings metaSettings = reader.read(stream); - SourceColumnsFactory.setSettings(metaSettings); MetricsHolder.init(); AnnotationScan scopeScan = new AnnotationScan(); diff --git a/oap-server/oal-rt/src/test/resources/scope-meta.yml b/oap-server/oal-rt/src/test/resources/scope-meta.yml deleted file mode 100644 index 004a400fb04170d75b9d270a0492b2b98d405150..0000000000000000000000000000000000000000 --- a/oap-server/oal-rt/src/test/resources/scope-meta.yml +++ /dev/null @@ -1,136 +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. - -scopes: - - name: All - - name: Service - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - name: ServiceInstance - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false - - name: Endpoint - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false - - fieldName: serviceInstanceId - columnName: service_instance_id - typeName: int - ID: false - - name: ServiceInstanceJVMCPU - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceInstanceId - columnName: service_instance_id - typeName: int - ID: false - - name: ServiceInstanceJVMMemory - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceInstanceId - columnName: service_instance_id - typeName: int - ID: false - - name: ServiceInstanceJVMMemoryPool - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceInstanceId - columnName: service_instance_id - typeName: int - ID: false - - name: ServiceInstanceJVMGC - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceInstanceId - columnName: service_instance_id - typeName: int - ID: false - - name: ServiceRelation - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - name: ServiceInstanceRelation - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: sourceServiceId - columnName: source_service_id - typeName: int - ID: false - - fieldName: destServiceId - columnName: dest_service_id - typeName: int - ID: false - - name: EndpointRelation - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false - - fieldName: childServiceId - columnName: child_service_id - typeName: int - ID: false - - fieldName: serviceInstanceId - columnName: service_instance_id - typeName: int - ID: false - - fieldName: childServiceInstanceId - columnName: child_service_instance_id - typeName: int - ID: false - - name: DatabaseAccess - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DatabaseAccess.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DatabaseAccess.java index 67a17fbbe13556a727be582d23e5c33905ea95bc..dcf95862d048abbfe5b6c7271e6098058212abb5 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DatabaseAccess.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DatabaseAccess.java @@ -26,6 +26,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.DA * @author: liuhaoyang */ @ScopeDeclaration(id = DATABASE_ACCESS, name = "DatabaseAccess") +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class DatabaseAccess extends Source { @Override diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DefaultScopeDefine.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DefaultScopeDefine.java index 8d83b164445f974624546746776c791114d5cb45..97fcd2246d2c9f2137c0025c48000066a721bb58 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DefaultScopeDefine.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/DefaultScopeDefine.java @@ -19,7 +19,11 @@ package org.apache.skywalking.oap.server.core.source; import java.lang.annotation.Annotation; -import java.util.*; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.skywalking.oap.server.core.UnexpectedException; import org.apache.skywalking.oap.server.core.annotation.AnnotationListener; @@ -30,6 +34,7 @@ import org.apache.skywalking.oap.server.core.annotation.AnnotationListener; public class DefaultScopeDefine { private static final Map NAME_2_ID = new HashMap<>(); private static final Map ID_2_NAME = new HashMap<>(); + private static final Map> SCOPE_COLUMNS = new HashMap<>(); /** * All metrics IDs in [0, 10,000) are reserved in Apache SkyWalking. @@ -94,11 +99,31 @@ public class DefaultScopeDefine { } String name = declaration.name(); if (NAME_2_ID.containsKey(name)) { - throw new UnexpectedException("ScopeDeclaration name=" + name + " at " + originalClass.getName() + " has conflict with another id= " + NAME_2_ID.get(name)); + throw new UnexpectedException("ScopeDeclaration fieldName=" + name + " at " + originalClass.getName() + " has conflict with another id= " + NAME_2_ID.get(name)); } ID_2_NAME.put(id, name); NAME_2_ID.put(name, id); + List scopeDefaultColumns = new ArrayList<>(); + + ScopeDefaultColumn.VirtualColumnDefinition virtualColumn = (ScopeDefaultColumn.VirtualColumnDefinition)originalClass.getAnnotation(ScopeDefaultColumn.VirtualColumnDefinition.class); + if (virtualColumn != null) { + scopeDefaultColumns.add(new ScopeDefaultColumn(virtualColumn.fieldName(), virtualColumn.columnName(), + virtualColumn.type(), virtualColumn.isID())); + } + Field[] scopeClassField = originalClass.getDeclaredFields(); + if (scopeClassField != null) { + for (Field field : scopeClassField) { + ScopeDefaultColumn.DefinedByField definedByField = field.getAnnotation(ScopeDefaultColumn.DefinedByField.class); + if (definedByField != null) { + scopeDefaultColumns.add(new ScopeDefaultColumn(field.getName(), definedByField.columnName(), + field.getType(), definedByField.isID())); + } + } + } + + SCOPE_COLUMNS.put(name, scopeDefaultColumns); + String catalogName = declaration.catalog(); switch (catalogName) { case SERVICE_CATALOG_NAME: @@ -124,7 +149,7 @@ public class DefaultScopeDefine { public static int valueOf(String name) { Integer id = NAME_2_ID.get(name); if (id == null) { - throw new UnexpectedException("ScopeDefine name = " + name + " not found."); + throw new UnexpectedException("ScopeDefine fieldName = " + name + " not found."); } return id; } @@ -132,6 +157,7 @@ public class DefaultScopeDefine { public static void reset() { NAME_2_ID.clear(); ID_2_NAME.clear(); + SCOPE_COLUMNS.clear(); } public static boolean inServiceCatalog(int scopeId) { @@ -145,4 +171,18 @@ public class DefaultScopeDefine { public static boolean inEndpointCatalog(int scopeId) { return ENDPOINT_CATALOG.containsKey(scopeId); } -} + + /** + * Get the default columns defined in Scope. All those columns will forward to persistent entity. + * + * @param scopeName of the default columns + * @return + */ + public static List getDefaultColumns(String scopeName) { + List scopeDefaultColumns = SCOPE_COLUMNS.get(scopeName); + if (scopeDefaultColumns == null) { + throw new UnexpectedException("ScopeDefine name = " + scopeName + " not found."); + } + return scopeDefaultColumns; + } +} \ No newline at end of file diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Endpoint.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Endpoint.java index 57b51ddada8e945212a0fb82b28341a61c1c8aac..8c4ba5b16a714449df14e66e2aa5fa71d8ce8caa 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Endpoint.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Endpoint.java @@ -27,6 +27,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.EN * @author peng-yongsheng */ @ScopeDeclaration(id = ENDPOINT, name = "Endpoint", catalog = ENDPOINT_CATALOG_NAME) +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class Endpoint extends Source { @Override public int scope() { return DefaultScopeDefine.ENDPOINT; @@ -38,9 +39,9 @@ public class Endpoint extends Source { @Getter @Setter private int id; @Getter @Setter private String name; - @Getter @Setter private int serviceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_id") private int serviceId; @Getter @Setter private String serviceName; - @Getter @Setter private int serviceInstanceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_instance_id") private int serviceInstanceId; @Getter @Setter private String serviceInstanceName; @Getter @Setter private int latency; @Getter @Setter private boolean status; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/EndpointRelation.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/EndpointRelation.java index f2dfd41552284b4a802ca04cae021fc9e67dfeb7..47a978755f14e7d79ebe633209844bdb8095eb0a 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/EndpointRelation.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/EndpointRelation.java @@ -27,6 +27,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.EN * @author peng-yongsheng */ @ScopeDeclaration(id = ENDPOINT_RELATION, name = "EndpointRelation") +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class EndpointRelation extends Source { @Override public int scope() { @@ -39,16 +40,16 @@ public class EndpointRelation extends Source { @Getter @Setter private int endpointId; @Getter @Setter private String endpoint; - @Getter @Setter private int serviceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_id") private int serviceId; @Getter @Setter private String serviceName; - @Getter @Setter private int serviceInstanceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_instance_id") private int serviceInstanceId; @Getter @Setter private String serviceInstanceName; @Getter @Setter private int childEndpointId; @Getter @Setter private String childEndpoint; - @Getter @Setter private int childServiceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "child_service_id") private int childServiceId; @Getter @Setter private String childServiceName; - @Getter @Setter private int childServiceInstanceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "child_service_instance_id") private int childServiceInstanceId; @Getter @Setter private String childServiceInstanceName; @Getter @Setter private int componentId; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/EnvoyInstanceMetric.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/EnvoyInstanceMetric.java index d6e2c6c4a5ebaf3399e435504cd3dde02982e5fd..dce3f56a3d228c59ad0cd80570bb69f04c7461c8 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/EnvoyInstanceMetric.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/EnvoyInstanceMetric.java @@ -31,6 +31,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SE * @author wusheng */ @ScopeDeclaration(id = ENVOY_INSTANCE_METRIC, name = "EnvoyInstanceMetric", catalog = SERVICE_INSTANCE_CATALOG_NAME) +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class EnvoyInstanceMetric extends Source { @Override public int scope() { return ENVOY_INSTANCE_METRIC; @@ -44,7 +45,7 @@ public class EnvoyInstanceMetric extends Source { * Instance id */ @Getter @Setter private int id; - @Getter @Setter private int serviceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_id") private int serviceId; @Getter @Setter private String name; @Getter @Setter private String serviceName; @Getter @Setter private String metricName; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ScopeDefaultColumn.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ScopeDefaultColumn.java new file mode 100644 index 0000000000000000000000000000000000000000..d23bcc7fbc2e502cb713564adc5f0809610f7083 --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ScopeDefaultColumn.java @@ -0,0 +1,69 @@ +/* + * 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.source; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; + +/** + * Define the default columns of source scope. These columns pass down into the persistent entity(OAL metrics entity) + * automatically. + * + * @author wusheng + */ +@Getter(AccessLevel.PUBLIC) +@Setter(AccessLevel.PUBLIC) +public class ScopeDefaultColumn { + private String fieldName; + private String columnName; + private Class type; + private boolean isID; + + public ScopeDefaultColumn(String fieldName, String columnName, Class type, boolean isID) { + this.fieldName = fieldName; + this.columnName = columnName; + this.type = type; + this.isID = isID; + } + + @Target({ElementType.FIELD}) + @Retention(RetentionPolicy.RUNTIME) + public @interface DefinedByField { + String columnName(); + + boolean isID() default false; + } + + @Target({ElementType.TYPE}) + @Retention(RetentionPolicy.RUNTIME) + public @interface VirtualColumnDefinition { + String fieldName(); + + String columnName(); + + Class type(); + + boolean isID() default false; + } +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Service.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Service.java index cfd03ed7a0c326ff9ca72bb068ab4ffa02ebfe7c..cadfebfcf71601aae25d8272cd972ec2d252fe4c 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Service.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/Service.java @@ -26,6 +26,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.*; * @author wusheng, peng-yongsheng */ @ScopeDeclaration(id = SERVICE, name = "Service", catalog = SERVICE_CATALOG_NAME) +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class Service extends Source { @Override public int scope() { return DefaultScopeDefine.SERVICE; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstance.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstance.java index c1651ff073a23fe94bb97106575aef800bcca2c7..6f559bdcadf2170b6280a835837588f35c648c39 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstance.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstance.java @@ -27,6 +27,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SE * @author peng-yongsheng */ @ScopeDeclaration(id = SERVICE_INSTANCE, name = "ServiceInstance", catalog = SERVICE_INSTANCE_CATALOG_NAME) +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class ServiceInstance extends Source { @Override public int scope() { return DefaultScopeDefine.SERVICE_INSTANCE; @@ -37,7 +38,7 @@ public class ServiceInstance extends Source { } @Getter @Setter private int id; - @Getter @Setter private int serviceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_id") private int serviceId; @Getter @Setter private String name; @Getter @Setter private String serviceName; @Getter @Setter private String endpointName; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRCPU.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRCPU.java index 82131fcb984724bdeb291658761a947d5dd72904..f6cff55b92318739eabbffaf351765e0f9c9bc4f 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRCPU.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRCPU.java @@ -28,6 +28,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SE * @author liuhaoyang **/ @ScopeDeclaration(id = SERVICE_INSTANCE_CLR_CPU, name = "ServiceInstanceCLRCPU", catalog = SERVICE_INSTANCE_CATALOG_NAME) +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class ServiceInstanceCLRCPU extends Source { @Override public int scope() { return DefaultScopeDefine.SERVICE_INSTANCE_CLR_CPU; @@ -40,6 +41,6 @@ public class ServiceInstanceCLRCPU extends Source { @Getter @Setter private int id; @Getter @Setter private String name; @Getter @Setter private String serviceName; - @Getter @Setter private int serviceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_id") private int serviceId; @Getter @Setter private double usePercent; } \ No newline at end of file diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRGC.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRGC.java index 6aa60933cd5297fc2bcb98be502ca4cc8f45cfba..00d6d4e6c5faee703729acb11429bda3a2671766 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRGC.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRGC.java @@ -28,6 +28,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SE * @author liuhaoyang **/ @ScopeDeclaration(id = SERVICE_INSTANCE_CLR_GC, name = "ServiceInstanceCLRGC", catalog = SERVICE_INSTANCE_CATALOG_NAME) +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class ServiceInstanceCLRGC extends Source { @Override public int scope() { return DefaultScopeDefine.SERVICE_INSTANCE_CLR_GC; @@ -40,7 +41,7 @@ public class ServiceInstanceCLRGC extends Source { @Getter @Setter private int id; @Getter @Setter private String name; @Getter @Setter private String serviceName; - @Getter @Setter private int serviceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_id") private int serviceId; @Getter @Setter private long gen0CollectCount; @Getter @Setter private long gen1CollectCount; @Getter @Setter private long gen2CollectCount; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRThread.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRThread.java index 7a9c5bb058f507a096cd33a731f2118fe1e12995..01a80515a32fcc59fe078f7efafbffee50901dec 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRThread.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceCLRThread.java @@ -28,6 +28,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SE * @author liuhaoyang **/ @ScopeDeclaration(id = SERVICE_INSTANCE_CLR_THREAD, name = "ServiceInstanceCLRThread", catalog = SERVICE_INSTANCE_CATALOG_NAME) +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class ServiceInstanceCLRThread extends Source { @Override public int scope() { return DefaultScopeDefine.SERVICE_INSTANCE_CLR_THREAD; @@ -40,7 +41,7 @@ public class ServiceInstanceCLRThread extends Source { @Getter @Setter private int id; @Getter @Setter private String name; @Getter @Setter private String serviceName; - @Getter @Setter private int serviceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_id") private int serviceId; @Getter @Setter private long availableCompletionPortThreads; @Getter @Setter private long availableWorkerThreads; @Getter @Setter private long maxCompletionPortThreads; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMCPU.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMCPU.java index a1b40ecfb80c1c1f957364968a737b3508f53d24..2ac7825f222723bbce99da65c02c68cc7dc772fa 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMCPU.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMCPU.java @@ -18,7 +18,8 @@ package org.apache.skywalking.oap.server.core.source; -import lombok.*; +import lombok.Getter; +import lombok.Setter; import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CATALOG_NAME; import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_JVM_CPU; @@ -27,6 +28,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SE * @author peng-yongsheng */ @ScopeDeclaration(id = SERVICE_INSTANCE_JVM_CPU, name = "ServiceInstanceJVMCPU", catalog = SERVICE_INSTANCE_CATALOG_NAME) +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class ServiceInstanceJVMCPU extends Source { @Override public int scope() { return DefaultScopeDefine.SERVICE_INSTANCE_JVM_CPU; @@ -39,6 +41,6 @@ public class ServiceInstanceJVMCPU extends Source { @Getter @Setter private int id; @Getter @Setter private String name; @Getter @Setter private String serviceName; - @Getter @Setter private int serviceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_id") private int serviceId; @Getter @Setter private double usePercent; } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMGC.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMGC.java index c58e1570cc088c48b3f2c281c073617cca6a1b17..3b1647ecd856b3ac82abda434923e68d1a093127 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMGC.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMGC.java @@ -27,6 +27,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SE * @author peng-yongsheng */ @ScopeDeclaration(id = SERVICE_INSTANCE_JVM_GC, name = "ServiceInstanceJVMGC", catalog = SERVICE_INSTANCE_CATALOG_NAME) +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class ServiceInstanceJVMGC extends Source { @Override public int scope() { return DefaultScopeDefine.SERVICE_INSTANCE_JVM_GC; @@ -39,7 +40,7 @@ public class ServiceInstanceJVMGC extends Source { @Getter @Setter private int id; @Getter @Setter private String name; @Getter @Setter private String serviceName; - @Getter @Setter private int serviceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_id") private int serviceId; @Getter @Setter private GCPhrase phrase; @Getter @Setter private long time; @Getter @Setter private long count; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMMemory.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMMemory.java index 960adb0f46268afec1a5a03ce29d8d0ed3453b87..7223b0c561bdd2055160d75f1a9818c843b3237f 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMMemory.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMMemory.java @@ -27,6 +27,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SE * @author peng-yongsheng */ @ScopeDeclaration(id = SERVICE_INSTANCE_JVM_MEMORY, name = "ServiceInstanceJVMMemory", catalog = SERVICE_INSTANCE_CATALOG_NAME) +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class ServiceInstanceJVMMemory extends Source { @Override public int scope() { return DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY; @@ -39,7 +40,7 @@ public class ServiceInstanceJVMMemory extends Source { @Getter @Setter private int id; @Getter @Setter private String name; @Getter @Setter private String serviceName; - @Getter @Setter private int serviceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_id") private int serviceId; @Getter @Setter private boolean heapStatus; @Getter @Setter private long init; @Getter @Setter private long max; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMMemoryPool.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMMemoryPool.java index f3cf81be04cd32e1e737172cdcfc416969e05752..90f49e0e99eac57681f3aefa3fb795f372c82286 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMMemoryPool.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceJVMMemoryPool.java @@ -27,6 +27,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SE * @author peng-yongsheng */ @ScopeDeclaration(id = SERVICE_INSTANCE_JVM_MEMORY_POOL, name = "ServiceInstanceJVMMemoryPool", catalog = SERVICE_INSTANCE_CATALOG_NAME) +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class ServiceInstanceJVMMemoryPool extends Source { @Override public int scope() { return DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY_POOL; @@ -39,7 +40,7 @@ public class ServiceInstanceJVMMemoryPool extends Source { @Getter @Setter private int id; @Getter @Setter private String name; @Getter @Setter private String serviceName; - @Getter @Setter private int serviceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "service_id") private int serviceId; @Getter @Setter private MemoryPoolType poolType; @Getter @Setter private long init; @Getter @Setter private long max; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceRelation.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceRelation.java index 27d4b658b4049ebf0b63297418990730a3fb27f4..07bc59c75535f380f9bf08b29a09deb1dbc91732 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceRelation.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceInstanceRelation.java @@ -27,6 +27,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SE * @author peng-yongsheng */ @ScopeDeclaration(id = SERVICE_INSTANCE_RELATION, name = "ServiceInstanceRelation") +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class ServiceInstanceRelation extends Source { @Override public int scope() { @@ -38,11 +39,11 @@ public class ServiceInstanceRelation extends Source { } @Getter @Setter private int sourceServiceInstanceId; - @Getter @Setter private int sourceServiceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "source_service_id") private int sourceServiceId; @Getter @Setter private String sourceServiceName; @Getter @Setter private String sourceServiceInstanceName; @Getter @Setter private int destServiceInstanceId; - @Getter @Setter private int destServiceId; + @Getter @Setter @ScopeDefaultColumn.DefinedByField(columnName = "dest_service_id") private int destServiceId; @Getter @Setter private String destServiceName; @Getter @Setter private String destServiceInstanceName; @Getter @Setter private String endpoint; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceRelation.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceRelation.java index 8f10250229bb40ce953e3711426877c337c817b4..3451572f4f1a5354950697d109686045ad4943c8 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceRelation.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceRelation.java @@ -27,6 +27,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SE * @author peng-yongsheng */ @ScopeDeclaration(id = SERVICE_RELATION, name = "ServiceRelation") +@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class) public class ServiceRelation extends Source { @Override public int scope() { diff --git a/oap-server/server-starter/pom.xml b/oap-server/server-starter/pom.xml index af2070400fdb8a1d7f703797d1f3c3184eac5238..d7f51f1a22b83d76572e4a21498aab4e72123b5a 100644 --- a/oap-server/server-starter/pom.xml +++ b/oap-server/server-starter/pom.xml @@ -240,7 +240,6 @@ datasource-settings.properties endpoint_naming_rules.properties official_analysis.oal - scope-meta.yml diff --git a/oap-server/server-starter/src/main/assembly/assembly.xml b/oap-server/server-starter/src/main/assembly/assembly.xml index e2c30a77fcfa747030189f558588375922250bfa..7182607f55d698c78b80db3bef073af56da80e22 100644 --- a/oap-server/server-starter/src/main/assembly/assembly.xml +++ b/oap-server/server-starter/src/main/assembly/assembly.xml @@ -47,7 +47,6 @@ component-libraries.yml official_analysis.oal - scope-meta.yml /config diff --git a/oap-server/server-starter/src/main/resources/scope-meta.yml b/oap-server/server-starter/src/main/resources/scope-meta.yml deleted file mode 100644 index a93ca4ada2ad0d38618f20bf36cc123875cb259a..0000000000000000000000000000000000000000 --- a/oap-server/server-starter/src/main/resources/scope-meta.yml +++ /dev/null @@ -1,176 +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. - -scopes: - - name: All - - name: Service - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - name: ServiceInstance - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false - - name: Endpoint - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false - - fieldName: serviceInstanceId - columnName: service_instance_id - typeName: int - ID: false - - name: ServiceInstanceJVMCPU - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false - - name: ServiceInstanceJVMMemory - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false - - name: ServiceInstanceJVMMemoryPool - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false - - name: ServiceInstanceJVMGC - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false - - name: ServiceRelation - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - name: ServiceInstanceRelation - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: sourceServiceId - columnName: source_service_id - typeName: int - ID: false - - fieldName: destServiceId - columnName: dest_service_id - typeName: int - ID: false - - name: EndpointRelation - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false - - fieldName: childServiceId - columnName: child_service_id - typeName: int - ID: false - - fieldName: serviceInstanceId - columnName: service_instance_id - typeName: int - ID: false - - fieldName: childServiceInstanceId - columnName: child_service_instance_id - typeName: int - ID: false - - name: DatabaseAccess - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - name: ServiceInstanceCLRCPU - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false - - name: ServiceInstanceCLRGC - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false - - name: ServiceInstanceCLRThread - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false - - name: EnvoyInstanceMetric - columns: - - fieldName: entityId - columnName: entity_id - typeName: java.lang.String - ID: true - - fieldName: serviceId - columnName: service_id - typeName: int - ID: false \ No newline at end of file diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2RegisterLockInstaller.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2RegisterLockInstaller.java index 261eee4c6399e8279bdf7c39a0708529c897b5df..1bbceae3b4cc494efce09a8685bf2dd6fa8a2b51 100644 --- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2RegisterLockInstaller.java +++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2RegisterLockInstaller.java @@ -61,7 +61,7 @@ public class H2RegisterLockInstaller { for (Class registerSource : InventoryStreamProcessor.getInstance().getAllRegisterSources()) { int scopeId = ((Stream)registerSource.getAnnotation(Stream.class)).scopeId(); - putIfAbsent(h2Client, connection, scopeId, DefaultScopeDefine.nameOf(1)); + putIfAbsent(h2Client, connection, scopeId, DefaultScopeDefine.nameOf(scopeId)); } } catch (JDBCClientException | SQLException e) { throw new StorageException(e.getMessage(), e);