Improve OAP extendibility (#2288)

* Make scope meta configurable.

* Fix test cases in ci.

* Change step 1

* Refactor step 2

* Other compile issue done. Prepare the generator changes.

* Revert some wrong changes to Istio receiver.

* Step 3, make compile pass.

* Try to make CI passed.

* Add a check.

* Fix generated code style

* Provide new and extendable dispatcher generator tool

* Fix startup.

* Can't guarantee the dispatchers are always existing. Put explicit comments at there to avoid confusion, since this is different with old version.

* Fix a H2 query for endpoint search.

* Fix a wrong mysql alarm query.

* Provide new document and `generate-tool-grammer` module.

* Add missing last section of document.

* Fix typo

* Relocate the @ScopeDeclaration annotation, make it more sense. Also remove the useless @SourceType annotation. And adjust document for these changes

* ScopeDeclaration can be used once for each class only, now.
This commit is contained in:
吴晟 Wu Sheng 2019-02-26 13:43:14 +08:00 committed by GitHub
parent 8b4de0d482
commit fb62025da8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
106 changed files with 1264 additions and 1282 deletions

View File

@ -30,7 +30,7 @@ For each official Apache release, there is a complete and independent source cod
* `grpc-java` and `java` folders in **apm-protocol/apm-network/target/generated-sources/protobuf**
* `grpc-java` and `java` folders in **oap-server/server-core/target/generated-sources/protobuf**
* `grpc-java` and `java` folders in **oap-server/server-receiver-plugin/skywalking-istio-telemetry-receiver-plugin/target/generated-sources/protobuf**
* `antlr4` folder in **oap-server/generate-tool/target/generated-sources**
* `antlr4` folder in **oap-server/generate-tool-grammar/target/generated-sources**
* `oal` folder in **oap-server/generated-analysis/target/generated-sources**
## Setup your Eclipse IDE

View File

@ -27,7 +27,7 @@ All the following channels are open to the community, you could choose the way y
As a develop, first step, read [Compiling Guide](How-to-build.md). It teaches developer how to build the project in local.
### Project Extensions
SkyWalking project supports many ways to extends existing features. If you are interesting in these ways,
SkyWalking project supports many ways to extend existing features. If you are interesting in these ways,
read the following guides.
- [Java agent plugin development guide](Java-Plugin-Development-Guide.md).
@ -37,6 +37,11 @@ and private plugin developer should read this.
- [Storage extension development guide](storage-extention.md). Help potential contributors to build a new
storage implementor besides the official.
- [Customize analysis by oal script](write-oal.md). Guide you to use oal script to make your own metric available.
- [Source and scope extension for new metric](source-extension.md). If you want to analysis a new metric, which SkyWalking
haven't provide. You need to
add a new receiver rather than choosing [existed receiver](../setup/backend/backend-receivers.md).
At that moment,
you most likely need to add a new source and scope. This document will teach you how to do.
- [Backend Inventory entity extension](inventory-extension.md). If you want to extend SkyWalking inventory entities, and
want to push upstream back to our Apache OSS repo, please read these principles.

View File

@ -0,0 +1,63 @@
# Source and Scope extension for new metric
From [OAL scope introduction](../concepts-and-designs/oal.md#scope), you should already have understood what the scope is.
At here, as you want to do more extension, you need understand deeper, which is the **Source**.
**Source** and **Scope** are binding concepts. **Scope** declare the id(int) and name, **Source** declare the attributes.
Please follow these steps to create a new Source and Scope.
1. In the OAP core module, it provide **SourceReceiver** internal service.
```java
public interface SourceReceiver extends Service {
void receive(Source source);
}
```
2. All analysis data must be a **org.apache.skywalking.oap.server.core.source.Source** sub class,
tagged by `@SourceType` annotation, and in `org.apache.skywalking` package.
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 {
@Override public int scope() {
return DefaultScopeDefine.SERVICE;
}
@Override public String getEntityId() {
return String.valueOf(id);
}
@Getter @Setter private int id;
@Getter @Setter private String name;
@Getter @Setter private String serviceInstanceName;
@Getter @Setter private String endpointName;
@Getter @Setter private int latency;
@Getter @Setter private boolean status;
@Getter @Setter private int responseCode;
@Getter @Setter private RequestType type;
}
```
3. The `scope()` method in Source, returns an ID, which is not a random number. This ID need to be declared through
`@ScopeDeclaration` annotation too. The ID in `@ScopeDeclaration` and ID in `scope()` method should be same for this Source.
4. The `String getEntityId()` method in Source, requests the return value representing unique entity which the scope related.
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.
6. 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 metric, connection number for service instance, follow existing `ServiceInstance`.
___
After you done all of these, you could build a receiver, which do
1. Get the original data of the metric,
1. Build the source, send into `SourceReceiver`.
1. Write your whole OAL scripts.
1. Repackage the project.

View File

@ -30,7 +30,7 @@
* **apm-protocol/apm-network/target/generated-sources/protobuf** 文件夹下的`grpc-java` 和 `java`
* **oap-server/server-core/target/generated-sources/protobuf** 文件夹下的`grpc-java` 和 `java`
* **oap-server/server-receiver-plugin/skywalking-istio-telemetry-receiver-plugin/target/generated-sources/protobuf** 文件夹下的`grpc-java` 和 `java`
* **oap-server/generate-tool/target/generated-sources** 文件夹下的 `antlr4`
* **oap-server/generate-tool-grammar/target/generated-sources** 文件夹下的 `antlr4`
* **oap-server/generated-analysis/target/generated-sources** 文件夹下的 `oal`
## 设置Eclipse IDE

View File

@ -0,0 +1,57 @@
<?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>6.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>generate-tool-grammar</artifactId>
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4</artifactId>
<version>4.7.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.7.1</version>
<executions>
<execution>
<id>antlr</id>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -33,6 +33,11 @@
<artifactId>server-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>generate-tool-grammar</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4</artifactId>
@ -54,22 +59,4 @@
<version>2.3.28</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.7.1</version>
<executions>
<execution>
<id>antlr</id>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -22,17 +22,25 @@ import freemarker.template.TemplateException;
import java.io.*;
import java.util.List;
import org.apache.skywalking.apm.util.StringUtil;
import org.apache.skywalking.oal.tool.meta.*;
import org.apache.skywalking.oal.tool.output.FileGenerator;
import org.apache.skywalking.oal.tool.parser.*;
import org.apache.skywalking.oap.server.core.annotation.AnnotationScan;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
public class Main {
public static void main(String[] args) throws IOException, TemplateException {
AnnotationScan scopeScan = new AnnotationScan();
scopeScan.registerListener(new DefaultScopeDefine.Listener());
scopeScan.scan(null);
String modulePath = args[0];
String scriptFilePath = StringUtil.join(File.separatorChar, modulePath, "src", "main", "resources", "official_analysis.oal");
String outputPath = StringUtil.join(File.separatorChar, modulePath, "..", "generated-analysis", "target", "generated-sources", "oal",
"org", "apache", "skywalking", "oap", "server", "core", "analysis");
String metaFilePath = StringUtil.join(File.separatorChar, modulePath, "src", "main", "resources", "generator-scope-meta.yml");
Indicators.init();
@ -41,6 +49,15 @@ public class Main {
throw new IllegalArgumentException("OAL script file [" + scriptFilePath + "] doesn't exist");
}
File metaFile = new File(metaFilePath);
if (!metaFile.exists()) {
throw new IllegalArgumentException("Generator meta file [" + metaFilePath + "] doesn't exist");
}
MetaReader reader = new MetaReader();
MetaSettings metaSettings = reader.read(new FileInputStream(metaFile));
SourceColumnsFactory.setSettings(metaSettings);
ScriptParser scriptParser = ScriptParser.createFromFile(scriptFilePath);
List<AnalysisResult> analysisResults = scriptParser.parse();

View File

@ -0,0 +1,34 @@
/*
* 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.tool.meta;
import java.io.InputStream;
import org.yaml.snakeyaml.Yaml;
/**
* @author wusheng
*/
public class MetaReader {
public MetaSettings read(InputStream settingFileStream) {
Yaml yaml = new Yaml();
MetaSettings settings = yaml.loadAs(settingFileStream, MetaSettings.class);
return settings;
}
}

View File

@ -16,14 +16,16 @@
*
*/
package org.apache.skywalking.oap.server.core.source.annotation;
package org.apache.skywalking.oal.tool.meta;
import java.lang.annotation.*;
import java.util.List;
import lombok.*;
/**
* @author peng-yongsheng
* @author wusheng
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface SourceType {
@Setter
@Getter
public class MetaSettings {
private List<ScopeMeta> scopes;
}

View File

@ -0,0 +1,33 @@
/*
* 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.tool.meta;
import java.util.*;
import lombok.*;
import org.apache.skywalking.oal.tool.parser.SourceColumn;
/**
* @author wusheng
*/
@Setter
@Getter
public class ScopeMeta {
private String name;
private List<SourceColumn> columns = new ArrayList<>();
}

View File

@ -0,0 +1,28 @@
/*
* 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.tool.output;
import java.util.*;
import lombok.*;
@Getter
@Setter
public class AllDispatcherContext {
private Map<String, DispatcherContext> allContext = new HashMap<>();
}

View File

@ -22,19 +22,10 @@ import java.util.*;
import lombok.*;
import org.apache.skywalking.oal.tool.parser.AnalysisResult;
@Getter(AccessLevel.PUBLIC)
@Setter(AccessLevel.PUBLIC)
@Getter
@Setter
public class DispatcherContext {
private List<AnalysisResult> allIndicators = new LinkedList<>();
private List<AnalysisResult> serviceIndicators = new LinkedList<>();
private List<AnalysisResult> serviceInstanceIndicators = new LinkedList<>();
private List<AnalysisResult> endpointIndicators = new LinkedList<>();
private List<AnalysisResult> serviceRelationIndicators = new LinkedList<>();
private List<AnalysisResult> serviceInstanceRelationIndicators = new LinkedList<>();
private List<AnalysisResult> endpointRelationIndicators = new LinkedList<>();
private List<AnalysisResult> serviceInstanceJVMCPUIndicators = new LinkedList<>();
private List<AnalysisResult> serviceInstanceJVMMemoryIndicators = new LinkedList<>();
private List<AnalysisResult> serviceInstanceJVMMemoryPoolIndicators = new LinkedList<>();
private List<AnalysisResult> serviceInstanceJVMGCIndicators = new LinkedList<>();
private List<AnalysisResult> databaseAccessIndicators = new LinkedList<>();
private String source;
private String packageName;
private List<AnalysisResult> indicators = new ArrayList<>();
}

View File

@ -27,7 +27,7 @@ public class FileGenerator {
private List<AnalysisResult> results;
private String outputPath;
private Configuration configuration;
private DispatcherContext dispatcherContext;
private AllDispatcherContext allDispatcherContext;
public FileGenerator(List<AnalysisResult> results, String outputPath) {
this.results = results;
@ -35,61 +35,19 @@ public class FileGenerator {
configuration = new Configuration(new Version("2.3.28"));
configuration.setEncoding(Locale.ENGLISH, "UTF-8");
configuration.setClassLoaderForTemplateLoading(FileGenerator.class.getClassLoader(), "/code-templates");
this.toDispatchers();
allDispatcherContext = new AllDispatcherContext();
buildDispatcherContext();
}
public void generate() throws IOException, TemplateException {
for (AnalysisResult result : results) {
generate(result, "Indicator.java", writer -> generateIndicatorImplementor(result, writer));
String scopeName = result.getSourceName();
File file = new File(outputPath, "generated/" + scopeName.toLowerCase() + "/" + scopeName + "Dispatcher.java");
createFile(file);
generateDispatcher(result, new FileWriter(file));
}
File file = new File(outputPath, "generated/all/AllDispatcher.java");
createFile(file);
this.generateAllDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/service/ServiceDispatcher.java");
createFile(file);
this.generateServiceDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/databaseaccess/DatabaseAccessDispatcher.java");
createFile(file);
this.generateDatabaseAccessDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/servicerelation/ServiceRelationDispatcher.java");
createFile(file);
this.generateServiceRelationDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/endpoint/EndpointDispatcher.java");
createFile(file);
this.generateEndpointDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/endpointrelation/EndpointRelationDispatcher.java");
createFile(file);
this.generateEndpointRelationDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/serviceinstance/ServiceInstanceDispatcher.java");
createFile(file);
this.generateServiceInstanceDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/serviceinstancerelation/ServiceInstanceRelationDispatcher.java");
createFile(file);
this.generateServiceInstanceRelationDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/serviceinstancejvmcpu/ServiceInstanceJVMCPUDispatcher.java");
createFile(file);
this.generateServiceInstanceJVMCPUDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/serviceinstancejvmmemory/ServiceInstanceJVMMemoryDispatcher.java");
createFile(file);
this.generateServiceInstanceJVMMemoryDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/serviceinstancejvmmemorypool/ServiceInstanceJVMMemoryPoolDispatcher.java");
createFile(file);
this.generateServiceInstanceJVMMemoryPoolDispatcher(new FileWriter(file));
file = new File(outputPath, "generated/serviceinstancejvmgc/ServiceInstanceJVMGCDispatcher.java");
createFile(file);
this.generateServiceInstanceJVMGCDispatcher(new FileWriter(file));
}
private void generate(AnalysisResult result, String fileSuffix,
@ -123,98 +81,26 @@ public class FileGenerator {
configuration.getTemplate("IndicatorImplementor.ftl").process(result, output);
}
void generateAllDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("AllDispatcherTemplate.ftl").process(dispatcherContext, output);
void generateDispatcher(AnalysisResult result, Writer output) throws IOException, TemplateException {
String scopeName = result.getSourceName();
DispatcherContext context = allDispatcherContext.getAllContext().get(scopeName);
if (context != null) {
configuration.getTemplate("DispatcherTemplate.ftl").process(context, output);
}
}
void generateServiceDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateDatabaseAccessDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("DatabaseAccessDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceRelationDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceRelationDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateEndpointDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("EndpointDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateEndpointRelationDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("EndpointRelationDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceInstanceDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceInstanceDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceInstanceRelationDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceInstanceRelationDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceInstanceJVMCPUDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceInstanceJVMCPUDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceInstanceJVMMemoryDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceInstanceJVMMemoryDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceInstanceJVMMemoryPoolDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceInstanceJVMMemoryPoolDispatcherTemplate.ftl").process(dispatcherContext, output);
}
void generateServiceInstanceJVMGCDispatcher(Writer output) throws IOException, TemplateException {
configuration.getTemplate("ServiceInstanceJVMGCDispatcherTemplate.ftl").process(dispatcherContext, output);
}
private void toDispatchers() {
dispatcherContext = new DispatcherContext();
private void buildDispatcherContext() {
for (AnalysisResult result : results) {
String sourceName = result.getSourceName();
switch (sourceName) {
case "All":
dispatcherContext.getAllIndicators().add(result);
break;
case "Service":
dispatcherContext.getServiceIndicators().add(result);
break;
case "ServiceRelation":
dispatcherContext.getServiceRelationIndicators().add(result);
break;
case "ServiceInstance":
dispatcherContext.getServiceInstanceIndicators().add(result);
break;
case "ServiceInstanceRelation":
dispatcherContext.getServiceInstanceRelationIndicators().add(result);
break;
case "Endpoint":
dispatcherContext.getEndpointIndicators().add(result);
break;
case "EndpointRelation":
dispatcherContext.getEndpointRelationIndicators().add(result);
break;
case "ServiceInstanceJVMCPU":
dispatcherContext.getServiceInstanceJVMCPUIndicators().add(result);
break;
case "ServiceInstanceJVMMemory":
dispatcherContext.getServiceInstanceJVMMemoryIndicators().add(result);
break;
case "ServiceInstanceJVMMemoryPool":
dispatcherContext.getServiceInstanceJVMMemoryPoolIndicators().add(result);
break;
case "ServiceInstanceJVMGC":
dispatcherContext.getServiceInstanceJVMGCIndicators().add(result);
break;
case "DatabaseAccess":
dispatcherContext.getDatabaseAccessIndicators().add(result);
break;
default:
throw new RuntimeException("Unexpected dispatcher");
DispatcherContext context = allDispatcherContext.getAllContext().get(sourceName);
if (context == null) {
context = new DispatcherContext();
context.setSource(sourceName);
context.setPackageName(sourceName.toLowerCase());
allDispatcherContext.getAllContext().put(sourceName, context);
}
context.getIndicators().add(result);
}
}
}

View File

@ -34,6 +34,8 @@ public class AnalysisResult {
private String sourceName;
private int sourceScopeId;
private String sourceAttribute;
private String aggregationFunctionName;

View File

@ -21,6 +21,7 @@ package org.apache.skywalking.oal.tool.parser;
import java.util.List;
import org.antlr.v4.runtime.misc.NotNull;
import org.apache.skywalking.oal.tool.grammar.*;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
public class OALListener extends OALParserBaseListener {
private List<AnalysisResult> results;
@ -46,6 +47,7 @@ public class OALListener extends OALParserBaseListener {
@Override public void enterSource(OALParser.SourceContext ctx) {
current.setSourceName(ctx.getText());
current.setSourceScopeId(DefaultScopeDefine.valueOf(metricNameFormat(ctx.getText())));
}
@Override

View File

@ -18,6 +18,7 @@
package org.apache.skywalking.oal.tool.parser;
import java.util.Objects;
import lombok.*;
import org.apache.skywalking.oal.tool.util.ClassMethodUtil;
@ -32,6 +33,9 @@ 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;
@ -43,6 +47,35 @@ public class SourceColumn {
this.fieldSetter = ClassMethodUtil.toSetMethod(fieldName);
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
this.fieldGetter = ClassMethodUtil.toGetMethod(fieldName);
this.fieldSetter = ClassMethodUtil.toSetMethod(fieldName);
}
public void setTypeName(String typeName) {
switch (typeName) {
case "int":
this.type = int.class;
break;
case "long":
this.type = long.class;
break;
case "string":
case "String":
this.type = String.class;
typeName = "String";
default:
try {
this.type = Class.forName(typeName);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
this.typeName = typeName;
}
@Override public String toString() {
return "SourceColumn{" +
"fieldName='" + fieldName + '\'' +
@ -51,4 +84,23 @@ public class SourceColumn {
", isID=" + isID +
'}';
}
@Override public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
SourceColumn column = (SourceColumn)o;
return isID == column.isID &&
Objects.equals(fieldName, column.fieldName) &&
Objects.equals(columnName, column.columnName) &&
Objects.equals(type, column.type) &&
Objects.equals(typeName, column.typeName) &&
Objects.equals(fieldSetter, column.fieldSetter) &&
Objects.equals(fieldGetter, column.fieldGetter);
}
@Override public int hashCode() {
return Objects.hash(fieldName, columnName, type, typeName, isID, fieldSetter, fieldGetter);
}
}

View File

@ -19,85 +19,22 @@
package org.apache.skywalking.oal.tool.parser;
import java.util.*;
import org.apache.skywalking.oal.tool.meta.*;
/**
* @author wusheng
*/
public class SourceColumnsFactory {
public static List<SourceColumn> getColumns(String source) {
List<SourceColumn> 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", "destServiceId", int.class, false);
columnList.add(destService);
private static Map<String, ScopeMeta> SETTINGS;
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 source :" + source);
}
public static void setSettings(MetaSettings settings) {
SourceColumnsFactory.SETTINGS = new HashMap<>();
settings.getScopes().forEach(scope -> {
SourceColumnsFactory.SETTINGS.put(scope.getName(), scope);
});
}
public static List<SourceColumn> getColumns(String source) {
return SETTINGS.get(source).getColumns();
}
}

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core.analysis.generated.databaseaccess;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (databaseAccessIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list databaseAccessIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class DatabaseAccessDispatcher implements SourceDispatcher<DatabaseAccess> {
@Override public void dispatch(DatabaseAccess source) {
<#list databaseAccessIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list databaseAccessIndicators as indicator>
private void do${indicator.metricName}(DatabaseAccess source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}

View File

@ -16,12 +16,12 @@
*
*/
package org.apache.skywalking.oap.server.core.analysis.generated.all;
package org.apache.skywalking.oap.server.core.analysis.generated.${packageName};
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (allIndicators?size>0)>
<#if (indicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list allIndicators as indicator>
<#list indicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
@ -35,16 +35,16 @@ import org.apache.skywalking.oap.server.core.source.*;
*
* @author Observability Analysis Language code generator
*/
public class AllDispatcher implements SourceDispatcher<All> {
public class ${source}Dispatcher implements SourceDispatcher<${source}> {
@Override public void dispatch(All source) {
<#list allIndicators as indicator>
@Override public void dispatch(${source} source) {
<#list indicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list allIndicators as indicator>
private void do${indicator.metricName}(All source) {
<#list indicators as indicator>
private void do${indicator.metricName}(${source} source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>

View File

@ -1,67 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core.analysis.generated.endpoint;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (endpointIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list endpointIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class EndpointDispatcher implements SourceDispatcher<Endpoint> {
@Override public void dispatch(Endpoint source) {
<#list endpointIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list endpointIndicators as indicator>
private void do${indicator.metricName}(Endpoint source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core.analysis.generated.endpointrelation;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (endpointRelationIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list endpointRelationIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class EndpointRelationDispatcher implements SourceDispatcher<EndpointRelation> {
@Override public void dispatch(EndpointRelation source) {
<#list endpointRelationIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list endpointRelationIndicators as indicator>
private void do${indicator.metricName}(EndpointRelation source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}

View File

@ -36,7 +36,6 @@ import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.source.Scope;
/**
* This class is auto generated. Please don't change this class manually.
@ -45,7 +44,7 @@ import org.apache.skywalking.oap.server.core.source.Scope;
*/
@IndicatorType
@StreamData
@StorageEntity(name = "${tableName}", builder = ${metricName}Indicator.Builder.class, source = Scope.${sourceName})
@StorageEntity(name = "${tableName}", builder = ${metricName}Indicator.Builder.class, sourceScopeId = ${sourceScopeId})
public class ${metricName}Indicator extends ${indicatorClassName} implements AlarmSupported {
<#list fieldsFromSource as sourceField>
@ -172,7 +171,7 @@ public class ${metricName}Indicator extends ${indicatorClassName} implements Ala
}
@Override public AlarmMeta getAlarmMeta() {
return new AlarmMeta("${varName}", Scope.${sourceName}<#if (fieldsFromSource?size>0) ><#list fieldsFromSource as field><#if field.isID()>, ${field.fieldName}</#if></#list></#if>);
return new AlarmMeta("${varName}", ${sourceScopeId}<#if (fieldsFromSource?size>0) ><#list fieldsFromSource as field><#if field.isID()>, ${field.fieldName}</#if></#list></#if>);
}
@Override

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core.analysis.generated.service;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceDispatcher implements SourceDispatcher<Service> {
@Override public void dispatch(Service source) {
<#list serviceIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceIndicators as indicator>
private void do${indicator.metricName}(Service source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core.analysis.generated.serviceinstance;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceInstanceIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceInstanceIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceInstanceDispatcher implements SourceDispatcher<ServiceInstance> {
@Override public void dispatch(ServiceInstance source) {
<#list serviceInstanceIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceInstanceIndicators as indicator>
private void do${indicator.metricName}(ServiceInstance source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core.analysis.generated.serviceinstancejvmcpu;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceInstanceJVMCPUIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceInstanceJVMCPUIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceInstanceJVMCPUDispatcher implements SourceDispatcher<ServiceInstanceJVMCPU> {
@Override public void dispatch(ServiceInstanceJVMCPU source) {
<#list serviceInstanceJVMCPUIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceInstanceJVMCPUIndicators as indicator>
private void do${indicator.metricName}(ServiceInstanceJVMCPU source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core.analysis.generated.serviceinstancejvmgc;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceInstanceJVMGCIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceInstanceJVMGCIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceInstanceJVMGCDispatcher implements SourceDispatcher<ServiceInstanceJVMGC> {
@Override public void dispatch(ServiceInstanceJVMGC source) {
<#list serviceInstanceJVMGCIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceInstanceJVMGCIndicators as indicator>
private void do${indicator.metricName}(ServiceInstanceJVMGC source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core.analysis.generated.serviceinstancejvmmemory;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceInstanceJVMMemoryIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceInstanceJVMMemoryIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceInstanceJVMMemoryDispatcher implements SourceDispatcher<ServiceInstanceJVMMemory> {
@Override public void dispatch(ServiceInstanceJVMMemory source) {
<#list serviceInstanceJVMMemoryIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceInstanceJVMMemoryIndicators as indicator>
private void do${indicator.metricName}(ServiceInstanceJVMMemory source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core.analysis.generated.serviceinstancejvmmemorypool;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceInstanceJVMMemoryPoolIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceInstanceJVMMemoryPoolIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceInstanceJVMMemoryPoolDispatcher implements SourceDispatcher<ServiceInstanceJVMMemoryPool> {
@Override public void dispatch(ServiceInstanceJVMMemoryPool source) {
<#list serviceInstanceJVMMemoryPoolIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceInstanceJVMMemoryPoolIndicators as indicator>
private void do${indicator.metricName}(ServiceInstanceJVMMemoryPool source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core.analysis.generated.serviceinstancerelation;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceInstanceRelationIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceInstanceRelationIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceInstanceRelationDispatcher implements SourceDispatcher<ServiceInstanceRelation> {
@Override public void dispatch(ServiceInstanceRelation source) {
<#list serviceInstanceRelationIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceInstanceRelationIndicators as indicator>
private void do${indicator.metricName}(ServiceInstanceRelation source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core.analysis.generated.servicerelation;
import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
<#if (serviceRelationIndicators?size>0)>
import org.apache.skywalking.oap.server.core.analysis.worker.IndicatorProcess;
<#list serviceRelationIndicators as indicator>
<#if indicator.filterExpressions??>
import org.apache.skywalking.oap.server.core.analysis.indicator.expression.*;
<#break>
</#if>
</#list>
</#if>
import org.apache.skywalking.oap.server.core.source.*;
/**
* This class is auto generated. Please don't change this class manually.
*
* @author Observability Analysis Language code generator
*/
public class ServiceRelationDispatcher implements SourceDispatcher<ServiceRelation> {
@Override public void dispatch(ServiceRelation source) {
<#list serviceRelationIndicators as indicator>
do${indicator.metricName}(source);
</#list>
}
<#list serviceRelationIndicators as indicator>
private void do${indicator.metricName}(ServiceRelation source) {
${indicator.metricName}Indicator indicator = new ${indicator.metricName}Indicator();
<#if indicator.filterExpressions??>
<#list indicator.filterExpressions as filterExpression>
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
return;
}
</#list>
</#if>
indicator.setTimeBucket(source.getTimeBucket());
<#list indicator.fieldsFromSource as field>
indicator.${field.fieldSetter}(source.${field.fieldGetter}());
</#list>
indicator.${indicator.entryMethod.methodName}(<#list indicator.entryMethod.argsExpressions as arg>${arg}<#if arg_has_next>, </#if></#list>);
IndicatorProcess.INSTANCE.in(indicator);
}
</#list>
}

View File

@ -0,0 +1,43 @@
/*
* 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.tool.meta;
import java.io.InputStream;
import java.util.List;
import org.apache.skywalking.oal.tool.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<SourceColumn> 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);
}
});
}
}

View File

@ -0,0 +1,104 @@
/*
* 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.tool.meta;
import java.util.*;
import org.apache.skywalking.oal.tool.parser.SourceColumn;
public class MockSourceColumnsFactory {
public static List<SourceColumn> getColumns(String source) {
List<SourceColumn> 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);
}
}
}

View File

@ -21,14 +21,24 @@ package org.apache.skywalking.oal.tool.output;
import freemarker.template.TemplateException;
import java.io.*;
import java.util.*;
import org.apache.skywalking.oal.tool.meta.*;
import org.apache.skywalking.oal.tool.parser.*;
import org.junit.*;
public class FileGeneratorTest {
@BeforeClass
public static void init() {
MetaReader reader = new MetaReader();
InputStream stream = MetaReaderTest.class.getResourceAsStream("/scope-meta.yml");
MetaSettings metaSettings = reader.read(stream);
SourceColumnsFactory.setSettings(metaSettings);
}
private AnalysisResult buildResult() {
AnalysisResult result = new AnalysisResult();
result.setVarName("generate_indicator");
result.setSourceName("Service");
result.setSourceScopeId(1);
result.setPackageName("service.serviceavg");
result.setTableName("service_avg");
result.setSourceAttribute("latency");
@ -83,7 +93,7 @@ public class FileGeneratorTest {
FileGenerator fileGenerator = new FileGenerator(results, ".");
StringWriter writer = new StringWriter();
fileGenerator.generateServiceDispatcher(writer);
fileGenerator.generateDispatcher(result, writer);
Assert.assertEquals(readExpectedFile("ServiceDispatcherExpected.java"), writer.toString());
//fileGenerator.generateServiceDispatcher(new OutputStreamWriter(System.out));

View File

@ -18,13 +18,18 @@
package org.apache.skywalking.oal.tool.parser;
import java.io.IOException;
import java.io.*;
import java.util.List;
import org.apache.skywalking.oal.tool.meta.*;
import org.junit.*;
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);
Indicators.init();
}

View File

@ -18,14 +18,30 @@
package org.apache.skywalking.oal.tool.parser;
import java.io.IOException;
import java.io.*;
import java.util.List;
import org.apache.skywalking.oal.tool.meta.*;
import org.apache.skywalking.oap.server.core.annotation.AnnotationScan;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.junit.*;
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);
Indicators.init();
AnnotationScan scopeScan = new AnnotationScan();
scopeScan.registerListener(new DefaultScopeDefine.Listener());
scopeScan.scan(null);
}
@AfterClass
public static void clear() {
DefaultScopeDefine.reset();
}
@Test

View File

@ -29,7 +29,6 @@ import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.source.Scope;
/**
* This class is auto generated. Please don't change this class manually.
@ -38,7 +37,7 @@ import org.apache.skywalking.oap.server.core.source.Scope;
*/
@IndicatorType
@StreamData
@StorageEntity(name = "service_avg", builder = ServiceAvgIndicator.Builder.class, source = Scope.Service)
@StorageEntity(name = "service_avg", builder = ServiceAvgIndicator.Builder.class, sourceScopeId = 1)
public class ServiceAvgIndicator extends LongAvgIndicator implements AlarmSupported {
@Setter @Getter @Column(columnName = "entity_id") @IDColumn private java.lang.String entityId;
@ -110,7 +109,7 @@ public class ServiceAvgIndicator extends LongAvgIndicator implements AlarmSuppor
}
@Override public AlarmMeta getAlarmMeta() {
return new AlarmMeta("generate_indicator", Scope.Service, entityId);
return new AlarmMeta("generate_indicator", 1, entityId);
}
@Override

View File

@ -0,0 +1,136 @@
# 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

View File

@ -0,0 +1,136 @@
# 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

View File

@ -40,6 +40,7 @@
<module>generated-analysis</module>
<module>generate-tool</module>
<module>server-telemetry</module>
<module>generate-tool-grammar</module>
</modules>
<properties>

View File

@ -25,6 +25,8 @@ import org.apache.skywalking.oap.server.core.alarm.IndicatorNotify;
import org.apache.skywalking.oap.server.core.alarm.MetaInAlarm;
import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.*;
public class NotifyHandler implements IndicatorNotify {
private final AlarmCore core;
private final Rules rules;
@ -35,12 +37,12 @@ public class NotifyHandler implements IndicatorNotify {
}
@Override public void notify(MetaInAlarm meta, Indicator indicator) {
switch (meta.getScope()) {
case Service:
switch (meta.getScopeId()) {
case SERVICE:
break;
case ServiceInstance:
case SERVICE_INSTANCE:
break;
case Endpoint:
case ENDPOINT:
break;
default:
return;

View File

@ -30,7 +30,6 @@ import org.apache.skywalking.oap.server.core.analysis.indicator.DoubleValueHolde
import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import org.apache.skywalking.oap.server.core.analysis.indicator.IntValueHolder;
import org.apache.skywalking.oap.server.core.analysis.indicator.LongValueHolder;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.library.util.CollectionUtils;
import org.joda.time.LocalDateTime;
import org.joda.time.Minutes;
@ -57,7 +56,7 @@ public class RunningRule {
private final int silencePeriod;
private Map<MetaInAlarm, Window> windows;
private volatile IndicatorValueType valueType;
private Scope targetScope;
private int targetScopeId;
private List<String> includeNames;
private AlarmMessageFormatter formatter;
@ -111,7 +110,7 @@ public class RunningRule {
} else {
return;
}
targetScope = meta.getScope();
targetScopeId = meta.getScopeId();
}
if (valueType != null) {
@ -147,7 +146,7 @@ public class RunningRule {
Window window = entry.getValue();
AlarmMessage alarmMessage = window.checkAlarm();
if (alarmMessage != AlarmMessage.NONE) {
alarmMessage.setScope(meta.getScope());
alarmMessage.setScopeId(meta.getScopeId());
alarmMessage.setName(meta.getName());
alarmMessage.setId0(meta.getId0());
alarmMessage.setId1(meta.getId1());

View File

@ -19,9 +19,7 @@
package org.apache.skywalking.oap.server.core.alarm.provider;
import org.apache.skywalking.oap.server.core.alarm.MetaInAlarm;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.junit.Assert;
import org.junit.Test;
import org.junit.*;
public class AlarmMessageFormatterTest {
@Test
@ -29,8 +27,8 @@ public class AlarmMessageFormatterTest {
AlarmMessageFormatter formatter = new AlarmMessageFormatter("abc words {sdf");
String message = formatter.format(new MetaInAlarm() {
@Override public Scope getScope() {
return null;
@Override public int getScopeId() {
return -1;
}
@Override public String getName() {
@ -58,8 +56,8 @@ public class AlarmMessageFormatterTest {
AlarmMessageFormatter formatter = new AlarmMessageFormatter("abc} words {name} - {id} .. {");
String message = formatter.format(new MetaInAlarm() {
@Override public Scope getScope() {
return null;
@Override public int getScopeId() {
return -1;
}
@Override public String getName() {

View File

@ -18,22 +18,14 @@
package org.apache.skywalking.oap.server.core.alarm.provider;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
import org.apache.skywalking.oap.server.core.alarm.MetaInAlarm;
import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import org.apache.skywalking.oap.server.core.analysis.indicator.IntValueHolder;
import java.util.*;
import org.apache.skywalking.oap.server.core.alarm.*;
import org.apache.skywalking.oap.server.core.analysis.indicator.*;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.joda.time.LocalDateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.junit.Assert;
import org.junit.Test;
import org.joda.time.format.*;
import org.junit.*;
import org.powermock.reflect.Whitebox;
/**
@ -177,7 +169,7 @@ public class RunningRuleTest {
Assert.assertEquals(0, runningRule.check().size()); //check matches, no alarm
runningRule.moveTo(TIME_BUCKET_FORMATTER.parseLocalDateTime("201808301441"));
// check at 201808301441
Assert.assertEquals(0, runningRule.check().size()); //check matches, no alarm
Assert.assertEquals(0, runningRule.check().size()); //check matches, no alarm
runningRule.moveTo(TIME_BUCKET_FORMATTER.parseLocalDateTime("201808301442"));
// check at 201808301442
Assert.assertNotEquals(0, runningRule.check().size()); //alarm
@ -191,8 +183,8 @@ public class RunningRuleTest {
private MetaInAlarm getMetaInAlarm(int id) {
return new MetaInAlarm() {
@Override public Scope getScope() {
return Scope.Service;
@Override public int getScopeId() {
return DefaultScopeDefine.SERVICE;
}
@Override public String getName() {

View File

@ -18,30 +18,17 @@
package org.apache.skywalking.oap.server.core.alarm.provider;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import com.google.gson.*;
import java.io.*;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.skywalking.oap.server.core.alarm.AlarmMessage;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.eclipse.jetty.servlet.*;
import org.junit.*;
public class WebhookCallbackTest implements Servlet {
private Server server;
@ -74,12 +61,12 @@ public class WebhookCallbackTest implements Servlet {
WebhookCallback webhookCallback = new WebhookCallback(remoteEndpoints);
List<AlarmMessage> alarmMessages = new ArrayList<>(2);
AlarmMessage alarmMessage = new AlarmMessage();
alarmMessage.setScope(Scope.All);
alarmMessage.setAlarmMessage("alarmMessage with [Scope.All]");
alarmMessage.setScopeId(DefaultScopeDefine.ALL);
alarmMessage.setAlarmMessage("alarmMessage with [DefaultScopeDefine.All]");
alarmMessages.add(alarmMessage);
AlarmMessage anotherAlarmMessage = new AlarmMessage();
anotherAlarmMessage.setScope(Scope.Endpoint);
anotherAlarmMessage.setAlarmMessage("anotherAlarmMessage with [Scope.Endpoint]");
anotherAlarmMessage.setScopeId(DefaultScopeDefine.ENDPOINT);
anotherAlarmMessage.setAlarmMessage("anotherAlarmMessage with [DefaultScopeDefine.Endpoint]");
alarmMessages.add(anotherAlarmMessage);
webhookCallback.doAlarm(alarmMessages);

View File

@ -85,7 +85,15 @@ public class CoreModuleProvider extends ModuleProvider {
return moduleConfig;
}
@Override public void prepare() throws ServiceNotProvidedException {
@Override public void prepare() throws ServiceNotProvidedException, ModuleStartException {
AnnotationScan scopeScan = new AnnotationScan();
scopeScan.registerListener(new DefaultScopeDefine.Listener());
try {
scopeScan.scan(null);
} catch (IOException e) {
throw new ModuleStartException(e.getMessage(), e);
}
grpcServer = new GRPCServer(moduleConfig.getGRPCHost(), moduleConfig.getGRPCPort());
if (moduleConfig.getMaxConcurrentCallsPerConnection() > 0) {
grpcServer.setMaxConcurrentCallsPerConnection(moduleConfig.getMaxConcurrentCallsPerConnection());

View File

@ -21,14 +21,12 @@ package org.apache.skywalking.oap.server.core.alarm;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import org.apache.skywalking.oap.server.core.cache.EndpointInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
import org.apache.skywalking.oap.server.core.register.EndpointInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
import org.apache.skywalking.oap.server.core.register.ServiceInventory;
import org.apache.skywalking.oap.server.core.cache.*;
import org.apache.skywalking.oap.server.core.register.*;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.*;
/**
* @author wusheng
*/
@ -56,7 +54,7 @@ public class AlarmEntrance {
MetaInAlarm metaInAlarm;
switch (alarmMeta.getScope()) {
case Service:
case SERVICE:
int serviceId = Integer.parseInt(alarmMeta.getId());
ServiceInventory serviceInventory = serviceInventoryCache.get(serviceId);
ServiceMetaInAlarm serviceMetaInAlarm = new ServiceMetaInAlarm();
@ -65,7 +63,7 @@ public class AlarmEntrance {
serviceMetaInAlarm.setName(serviceInventory.getName());
metaInAlarm = serviceMetaInAlarm;
break;
case ServiceInstance:
case SERVICE_INSTANCE:
int serviceInstanceId = Integer.parseInt(alarmMeta.getId());
ServiceInstanceInventory serviceInstanceInventory = serviceInstanceInventoryCache.get(serviceInstanceId);
ServiceInstanceMetaInAlarm instanceMetaInAlarm = new ServiceInstanceMetaInAlarm();
@ -74,7 +72,7 @@ public class AlarmEntrance {
instanceMetaInAlarm.setName(serviceInstanceInventory.getName());
metaInAlarm = instanceMetaInAlarm;
break;
case Endpoint:
case ENDPOINT:
int endpointId = Integer.parseInt(alarmMeta.getId());
EndpointInventory endpointInventory = endpointInventoryCache.get(endpointId);
EndpointMetaInAlarm endpointMetaInAlarm = new EndpointMetaInAlarm();

View File

@ -19,7 +19,6 @@
package org.apache.skywalking.oap.server.core.alarm;
import lombok.*;
import org.apache.skywalking.oap.server.core.source.Scope;
/**
* Alarm message represents the details of each alarm.
@ -32,7 +31,7 @@ public class AlarmMessage {
public static AlarmMessage NONE = new NoAlarm();
private Scope scope;
private int scopeId;
private String name;
private int id0;
private int id1;

View File

@ -18,26 +18,24 @@
package org.apache.skywalking.oap.server.core.alarm;
import lombok.Getter;
import lombok.Setter;
import lombok.*;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.source.Scope;
/**
* @author wusheng
*/
public class AlarmMeta {
@Setter @Getter private String indicatorName;
@Setter @Getter private Scope scope;
@Setter @Getter private int scope;
@Setter @Getter private String id;
public AlarmMeta(String indicatorName, Scope scope) {
public AlarmMeta(String indicatorName, int scope) {
this.indicatorName = indicatorName;
this.scope = scope;
this.id = Const.EMPTY_STRING;
}
public AlarmMeta(String indicatorName, Scope scope, String id) {
public AlarmMeta(String indicatorName, int scope, String id) {
this.indicatorName = indicatorName;
this.scope = scope;
this.id = id;

View File

@ -23,17 +23,20 @@ import lombok.*;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.analysis.record.Record;
import org.apache.skywalking.oap.server.core.analysis.record.annotation.RecordType;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ALARM;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
@RecordType
@StorageEntity(name = AlarmRecord.INDEX_NAME, builder = AlarmRecord.Builder.class, source = Scope.Alarm)
@ScopeDeclaration(id = ALARM, name = "Alarm")
@StorageEntity(name = AlarmRecord.INDEX_NAME, builder = AlarmRecord.Builder.class, sourceScopeId = DefaultScopeDefine.ALARM)
public class AlarmRecord extends Record {
public static final String INDEX_NAME = "alarm_record";

View File

@ -39,7 +39,7 @@ public class AlarmStandardPersistence implements AlarmCallback {
}
AlarmRecord record = new AlarmRecord();
record.setScope(message.getScope().ordinal());
record.setScope(message.getScopeId());
record.setId0(message.getId0());
record.setId1(message.getId1());
record.setName(message.getName());

View File

@ -21,7 +21,7 @@ package org.apache.skywalking.oap.server.core.alarm;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
@Getter(AccessLevel.PUBLIC)
@Setter(AccessLevel.PUBLIC)
@ -33,8 +33,8 @@ public class EndpointMetaInAlarm extends MetaInAlarm {
private String[] tags;
private String[] properties;
@Override public Scope getScope() {
return Scope.Endpoint;
@Override public int getScopeId() {
return DefaultScopeDefine.ENDPOINT;
}
@Override public int getId0() {

View File

@ -19,10 +19,9 @@
package org.apache.skywalking.oap.server.core.alarm;
import java.util.Objects;
import org.apache.skywalking.oap.server.core.source.Scope;
public abstract class MetaInAlarm {
public abstract Scope getScope();
public abstract int getScopeId();
public abstract String getName();
@ -30,7 +29,7 @@ public abstract class MetaInAlarm {
/**
* In most scopes, there is only id0, as primary id. Such as Service, Endpoint. But in relation, the ID includes
* two, actually. Such as ServiceRelation, id0 represents the source service id
* two, actually. Such as ServiceRelation, id0 represents the sourceScopeId service id
*
* @return the primary id.
*/

View File

@ -21,7 +21,7 @@ package org.apache.skywalking.oap.server.core.alarm;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
@Getter(AccessLevel.PUBLIC)
@Setter(AccessLevel.PUBLIC)
@ -33,8 +33,8 @@ public class ServiceInstanceMetaInAlarm extends MetaInAlarm {
private String[] tags;
private String[] properties;
@Override public Scope getScope() {
return Scope.ServiceInstance;
@Override public int getScopeId() {
return DefaultScopeDefine.SERVICE_INSTANCE;
}
@Override public int getId0() {

View File

@ -21,7 +21,7 @@ package org.apache.skywalking.oap.server.core.alarm;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
@Getter(AccessLevel.PUBLIC)
@Setter(AccessLevel.PUBLIC)
@ -33,8 +33,8 @@ public class ServiceMetaInAlarm extends MetaInAlarm {
private String[] tags;
private String[] properties;
@Override public Scope getScope() {
return Scope.Service;
@Override public int getScopeId() {
return DefaultScopeDefine.SERVICE;
}
@Override public int getId0() {

View File

@ -21,17 +21,11 @@ package org.apache.skywalking.oap.server.core.analysis;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.ClassPath;
import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.lang.reflect.*;
import java.util.*;
import org.apache.skywalking.oap.server.core.UnexpectedException;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.Source;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.*;
/**
* @author peng-yongsheng, wusheng
@ -40,7 +34,7 @@ public class DispatcherManager {
private static final Logger logger = LoggerFactory.getLogger(DispatcherManager.class);
private Map<Scope, List<SourceDispatcher>> dispatcherMap;
private Map<Integer, List<SourceDispatcher>> dispatcherMap;
public DispatcherManager() {
this.dispatcherMap = new HashMap<>();
@ -51,8 +45,17 @@ public class DispatcherManager {
return;
}
for (SourceDispatcher dispatcher : dispatcherMap.get(source.scope())) {
dispatcher.dispatch(source);
List<SourceDispatcher> dispatchers = dispatcherMap.get(source.scope());
/**
* Dispatcher is only generated by oal script analysis result.
* So these will/could be possible, the given source doesn't have the dispatcher,
* when the receiver is open, and oal script doesn't ask for analysis.
*/
if (dispatchers != null) {
for (SourceDispatcher dispatcher : dispatchers) {
dispatcher.dispatch(source);
}
}
}
@ -93,17 +96,17 @@ public class DispatcherManager {
Source dispatcherSource = (Source)source;
SourceDispatcher dispatcher = (SourceDispatcher)aClass.newInstance();
Scope scope = dispatcherSource.scope();
int scopeId = dispatcherSource.scope();
List<SourceDispatcher> dispatchers = this.dispatcherMap.get(scope);
List<SourceDispatcher> dispatchers = this.dispatcherMap.get(scopeId);
if (dispatchers == null) {
dispatchers = new ArrayList<>();
this.dispatcherMap.put(scope, dispatchers);
this.dispatcherMap.put(scopeId, dispatchers);
}
dispatchers.add(dispatcher);
logger.info("Dispatcher {} is added into Scope {}.", dispatcher.getClass().getName(), scope);
logger.info("Dispatcher {} is added into DefaultScopeDefine {}.", dispatcher.getClass().getName(), scopeId);
}
}
}

View File

@ -20,10 +20,9 @@ package org.apache.skywalking.oap.server.core.analysis.manual.database;
import java.util.*;
import lombok.*;
import org.apache.skywalking.oap.server.core.*;
import org.apache.skywalking.oap.server.core.analysis.topn.TopN;
import org.apache.skywalking.oap.server.core.analysis.topn.annotation.TopNType;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
@ -33,7 +32,7 @@ import org.apache.skywalking.oap.server.core.storage.annotation.*;
* @author wusheng
*/
@TopNType
@StorageEntity(name = TopNDatabaseStatement.INDEX_NAME, builder = TopNDatabaseStatement.Builder.class, source = Scope.DatabaseSlowStatement)
@StorageEntity(name = TopNDatabaseStatement.INDEX_NAME, builder = TopNDatabaseStatement.Builder.class, sourceScopeId = DefaultScopeDefine.DATABASE_SLOW_STATEMENT)
public class TopNDatabaseStatement extends TopN {
public static final String INDEX_NAME = "top_n_database_statement";

View File

@ -25,13 +25,13 @@ import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
@IndicatorType
@StreamData
@StorageEntity(name = EndpointRelationServerSideIndicator.INDEX_NAME, builder = EndpointRelationServerSideIndicator.Builder.class, source = Scope.EndpointRelation)
@StorageEntity(name = EndpointRelationServerSideIndicator.INDEX_NAME, builder = EndpointRelationServerSideIndicator.Builder.class, sourceScopeId = DefaultScopeDefine.ENDPOINT_RELATION)
public class EndpointRelationServerSideIndicator extends Indicator {
public static final String INDEX_NAME = "endpoint_relation_server_side";

View File

@ -24,7 +24,7 @@ import org.apache.skywalking.apm.util.StringUtil;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.analysis.record.Record;
import org.apache.skywalking.oap.server.core.analysis.record.annotation.RecordType;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.library.util.CollectionUtils;
@ -33,7 +33,7 @@ import org.apache.skywalking.oap.server.library.util.CollectionUtils;
* @author peng-yongsheng
*/
@RecordType
@StorageEntity(name = SegmentRecord.INDEX_NAME, builder = SegmentRecord.Builder.class, source = Scope.Segment)
@StorageEntity(name = SegmentRecord.INDEX_NAME, builder = SegmentRecord.Builder.class, sourceScopeId = DefaultScopeDefine.SEGMENT)
public class SegmentRecord extends Record {
public static final String INDEX_NAME = "segment";

View File

@ -25,13 +25,13 @@ import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
@IndicatorType
@StreamData
@StorageEntity(name = ServiceRelationClientSideIndicator.INDEX_NAME, builder = ServiceRelationClientSideIndicator.Builder.class, source = Scope.ServiceRelation)
@StorageEntity(name = ServiceRelationClientSideIndicator.INDEX_NAME, builder = ServiceRelationClientSideIndicator.Builder.class, sourceScopeId = DefaultScopeDefine.SERVICE_RELATION)
public class ServiceRelationClientSideIndicator extends Indicator {
public static final String INDEX_NAME = "service_relation_client_side";

View File

@ -25,14 +25,14 @@ import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
@IndicatorType
@StreamData
@StorageEntity(name = ServiceRelationServerSideIndicator.INDEX_NAME, builder = ServiceRelationServerSideIndicator.Builder.class,
source = Scope.ServiceRelation)
sourceScopeId = DefaultScopeDefine.SERVICE_RELATION)
public class ServiceRelationServerSideIndicator extends Indicator {
public static final String INDEX_NAME = "service_relation_server_side";

View File

@ -56,7 +56,9 @@ public class AnnotationScan {
listener.complete()
);
callBack.run();
if (callBack != null) {
callBack.run();
}
}
public class AnnotationListenerCache {

View File

@ -20,7 +20,6 @@ package org.apache.skywalking.oap.server.core.query;
import java.io.IOException;
import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.StorageModule;
import org.apache.skywalking.oap.server.core.storage.query.IAlarmQueryDAO;
import org.apache.skywalking.oap.server.library.module.*;
@ -48,9 +47,9 @@ public class AlarmQueryService implements Service {
return alarmQueryDAO;
}
public Alarms getAlarm(final Scope scope, final String keyword, final Pagination paging, final long startTB,
public Alarms getAlarm(final Integer scopeId, final String keyword, final Pagination paging, final long startTB,
final long endTB) throws IOException {
PaginationUtils.Page page = PaginationUtils.INSTANCE.exchange(paging);
return getAlarmQueryDAO().getAlarm(scope, keyword, page.getLimit(), page.getFrom(), startTB, endTB);
return getAlarmQueryDAO().getAlarm(scopeId, keyword, page.getLimit(), page.getFrom(), startTB, endTB);
}
}

View File

@ -19,7 +19,6 @@
package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*;
import org.apache.skywalking.oap.server.core.source.Scope;
/**
* @author peng-yongsheng
@ -28,6 +27,7 @@ import org.apache.skywalking.oap.server.core.source.Scope;
@Setter
public class AlarmMessage {
private Scope scope;
private int scopeId;
private String id;
private String message;
private Long startTime;

View File

@ -0,0 +1,57 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.oap.server.core.query.entity;
import java.util.HashMap;
import lombok.Getter;
import org.apache.skywalking.oap.server.core.UnexpectedException;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
/**
* @author wusheng
*/
public enum Scope {
Service(DefaultScopeDefine.SERVICE),
ServiceInstance(DefaultScopeDefine.SERVICE_INSTANCE),
Endpoint(DefaultScopeDefine.ENDPOINT),
ServiceRelation(DefaultScopeDefine.SERVICE_RELATION),
ServiceInstanceRelation(DefaultScopeDefine.SERVICE_INSTANCE_RELATION),
EndpointRelation(DefaultScopeDefine.ENDPOINT_RELATION);
@Getter
private int scopeId;
Scope(int scopeId) {
this.scopeId = scopeId;
Finder.ALL_QUERY_SCOPES.put(scopeId, this);
}
public static class Finder {
private static HashMap<Integer, Scope> ALL_QUERY_SCOPES = new HashMap<>();
public static Scope valueOf(int scopeId) {
Scope scope = ALL_QUERY_SCOPES.get(scopeId);
if (scope == null) {
throw new UnexpectedException("Can't find scope id =" + scopeId);
}
return scope;
}
}
}

View File

@ -24,17 +24,20 @@ import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.annotation.InventoryType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.elasticsearch.common.Strings;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENDPOINT_INVENTORY;
/**
* @author peng-yongsheng
*/
@InventoryType
@StreamData
@StorageEntity(name = EndpointInventory.MODEL_NAME, builder = EndpointInventory.Builder.class, deleteHistory = false, source = Scope.EndpointInventory)
@ScopeDeclaration(id = ENDPOINT_INVENTORY, name = "EndpointInventory")
@StorageEntity(name = EndpointInventory.MODEL_NAME, builder = EndpointInventory.Builder.class, deleteHistory = false, sourceScopeId = DefaultScopeDefine.ENDPOINT_INVENTORY)
public class EndpointInventory extends RegisterSource {
public static final String MODEL_NAME = "endpoint_inventory";

View File

@ -24,17 +24,20 @@ import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.annotation.InventoryType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.elasticsearch.common.Strings;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.NETWORK_ADDRESS;
/**
* @author peng-yongsheng
*/
@InventoryType
@StreamData
@StorageEntity(name = NetworkAddressInventory.MODEL_NAME, builder = NetworkAddressInventory.Builder.class, deleteHistory = false, source = Scope.NetworkAddress)
@ScopeDeclaration(id = NETWORK_ADDRESS, name = "NetworkAddress")
@StorageEntity(name = NetworkAddressInventory.MODEL_NAME, builder = NetworkAddressInventory.Builder.class, deleteHistory = false, sourceScopeId = DefaultScopeDefine.NETWORK_ADDRESS)
public class NetworkAddressInventory extends RegisterSource {
public static final String MODEL_NAME = "network_address_inventory";

View File

@ -26,18 +26,21 @@ import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.annotation.InventoryType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
import org.elasticsearch.common.Strings;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_INVENTORY;
/**
* @author peng-yongsheng
*/
@InventoryType
@StreamData
@StorageEntity(name = ServiceInstanceInventory.MODEL_NAME, builder = ServiceInstanceInventory.Builder.class, deleteHistory = false, source = Scope.ServiceInstanceInventory)
@ScopeDeclaration(id = SERVICE_INSTANCE_INVENTORY, name = "ServiceInstanceInventory")
@StorageEntity(name = ServiceInstanceInventory.MODEL_NAME, builder = ServiceInstanceInventory.Builder.class, deleteHistory = false, sourceScopeId = DefaultScopeDefine.SERVICE_INSTANCE_INVENTORY)
public class ServiceInstanceInventory extends RegisterSource {
public static final String MODEL_NAME = "service_instance_inventory";

View File

@ -25,18 +25,21 @@ import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.annotation.InventoryType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.*;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
import org.elasticsearch.common.Strings;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INVENTORY;
/**
* @author peng-yongsheng
*/
@InventoryType
@StreamData
@StorageEntity(name = ServiceInventory.MODEL_NAME, builder = ServiceInventory.Builder.class, deleteHistory = false, source = Scope.ServiceInventory)
@ScopeDeclaration(id = SERVICE_INVENTORY, name = "ServiceInventory")
@StorageEntity(name = ServiceInventory.MODEL_NAME, builder = ServiceInventory.Builder.class, deleteHistory = false, sourceScopeId = DefaultScopeDefine.SERVICE_INVENTORY)
public class ServiceInventory extends RegisterSource {
public static final String MODEL_NAME = "service_inventory";

View File

@ -18,20 +18,12 @@
package org.apache.skywalking.oap.server.core.register.worker;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import org.apache.skywalking.oap.server.core.UnexpectedException;
import org.apache.skywalking.oap.server.core.register.RegisterSource;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.IRegisterDAO;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.StorageDAO;
import org.apache.skywalking.oap.server.core.storage.StorageModule;
import org.apache.skywalking.oap.server.core.storage.*;
import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntityAnnotationUtils;
import org.apache.skywalking.oap.server.core.worker.WorkerIdGenerator;
import org.apache.skywalking.oap.server.core.worker.WorkerInstances;
import org.apache.skywalking.oap.server.core.worker.*;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
/**
@ -48,7 +40,7 @@ public enum InventoryProcess {
public void create(ModuleManager moduleManager, Class<? extends RegisterSource> inventoryClass) {
String modelName = StorageEntityAnnotationUtils.getModelName(inventoryClass);
Scope scope = StorageEntityAnnotationUtils.getSourceScope(inventoryClass);
int scopeId = StorageEntityAnnotationUtils.getSourceScope(inventoryClass);
Class<? extends StorageBuilder> builderClass = StorageEntityAnnotationUtils.getBuilder(inventoryClass);
@ -60,7 +52,7 @@ public enum InventoryProcess {
throw new UnexpectedException("");
}
RegisterPersistentWorker persistentWorker = new RegisterPersistentWorker(WorkerIdGenerator.INSTANCES.generate(), modelName, moduleManager, registerDAO, scope);
RegisterPersistentWorker persistentWorker = new RegisterPersistentWorker(WorkerIdGenerator.INSTANCES.generate(), modelName, moduleManager, registerDAO, scopeId);
WorkerInstances.INSTANCES.put(persistentWorker.getWorkerId(), persistentWorker);
RegisterRemoteWorker remoteWorker = new RegisterRemoteWorker(WorkerIdGenerator.INSTANCES.generate(), moduleManager, persistentWorker);
@ -73,7 +65,7 @@ public enum InventoryProcess {
}
/**
* @return all register source class types
* @return all register sourceScopeId class types
*/
public List<Class> getAllRegisterSources() {
List allSources = new ArrayList<>();

View File

@ -24,7 +24,7 @@ import org.apache.skywalking.apm.commons.datacarrier.consumer.*;
import org.apache.skywalking.oap.server.core.*;
import org.apache.skywalking.oap.server.core.analysis.data.EndOfBatchContext;
import org.apache.skywalking.oap.server.core.register.RegisterSource;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.*;
import org.apache.skywalking.oap.server.core.worker.AbstractWorker;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
@ -37,7 +37,7 @@ public class RegisterPersistentWorker extends AbstractWorker<RegisterSource> {
private static final Logger logger = LoggerFactory.getLogger(RegisterPersistentWorker.class);
private final Scope scope;
private final int scopeId;
private final String modelName;
private final Map<RegisterSource, RegisterSource> sources;
private final IRegisterLockDAO registerLockDAO;
@ -45,13 +45,13 @@ public class RegisterPersistentWorker extends AbstractWorker<RegisterSource> {
private final DataCarrier<RegisterSource> dataCarrier;
RegisterPersistentWorker(int workerId, String modelName, ModuleManager moduleManager,
IRegisterDAO registerDAO, Scope scope) {
IRegisterDAO registerDAO, int scopeId) {
super(workerId);
this.modelName = modelName;
this.sources = new HashMap<>();
this.registerDAO = registerDAO;
this.registerLockDAO = moduleManager.find(StorageModule.NAME).provider().getService(IRegisterLockDAO.class);
this.scope = scope;
this.scopeId = scopeId;
this.dataCarrier = new DataCarrier<>("IndicatorPersistentWorker." + modelName, 1, 1000);
String name = "REGISTER_L2";
@ -91,7 +91,7 @@ public class RegisterPersistentWorker extends AbstractWorker<RegisterSource> {
}
} else {
int sequence;
if ((sequence = registerLockDAO.getId(scope, registerSource)) != Const.NONE) {
if ((sequence = registerLockDAO.getId(scopeId, registerSource)) != Const.NONE) {
try {
dbSource = registerDAO.get(modelName, source.id());
if (Objects.nonNull(dbSource)) {
@ -106,7 +106,7 @@ public class RegisterPersistentWorker extends AbstractWorker<RegisterSource> {
logger.error(t.getMessage(), t);
}
} else {
logger.info("{} inventory register try lock and increment sequence failure.", scope.name());
logger.info("{} inventory register try lock and increment sequence failure.", DefaultScopeDefine.nameOf(scopeId));
}
}
} catch (Throwable t) {

View File

@ -18,17 +18,16 @@
package org.apache.skywalking.oap.server.core.source;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import lombok.*;
@SourceType
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ALL;
@ScopeDeclaration(id = ALL, name = "All")
public class All extends Source {
@Override public Scope scope() {
return Scope.All;
@Override public int scope() {
return DefaultScopeDefine.ALL;
}
@Override public String getEntityId() {
return "";
}

View File

@ -18,17 +18,19 @@
package org.apache.skywalking.oap.server.core.source;
import lombok.Getter;
import lombok.Setter;
import lombok.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.DATABASE_ACCESS;
/**
* @author: liuhaoyang
*/
@ScopeDeclaration(id = DATABASE_ACCESS, name = "DatabaseAccess")
public class DatabaseAccess extends Source {
@Override
public Scope scope() {
return Scope.DatabaseAccess;
public int scope() {
return DefaultScopeDefine.DATABASE_ACCESS;
}
@Override

View File

@ -20,12 +20,13 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.DATABASE_SLOW_STATEMENT;
/**
* @author wusheng
*/
@SourceType
@ScopeDeclaration(id = DATABASE_SLOW_STATEMENT, name = "DatabaseSlowStatement")
public class DatabaseSlowStatement extends Source {
@Getter @Setter private String id;
@Getter @Setter private int databaseServiceId;
@ -33,8 +34,8 @@ public class DatabaseSlowStatement extends Source {
@Getter @Setter private long latency;
@Getter @Setter private String traceId;
@Override public Scope scope() {
return Scope.DatabaseSlowStatement;
@Override public int scope() {
return DefaultScopeDefine.DATABASE_SLOW_STATEMENT;
}
@Override public String getEntityId() {

View File

@ -0,0 +1,100 @@
/*
* 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.Annotation;
import java.util.*;
import org.apache.skywalking.oap.server.core.UnexpectedException;
import org.apache.skywalking.oap.server.core.annotation.AnnotationListener;
/**
* @author peng-yongsheng, wusheng
*/
public class DefaultScopeDefine {
private static final Map<String, Integer> NAME_2_ID = new HashMap<>();
private static final Map<Integer, String> ID_2_NAME = new HashMap<>();
public static final int ALL = 0;
public static final int SERVICE = 1;
public static final int SERVICE_INSTANCE = 2;
public static final int ENDPOINT = 3;
public static final int SERVICE_RELATION = 4;
public static final int SERVICE_INSTANCE_RELATION = 5;
public static final int ENDPOINT_RELATION = 6;
public static final int NETWORK_ADDRESS = 7;
public static final int SERVICE_INSTANCE_JVM_CPU = 8;
public static final int SERVICE_INSTANCE_JVM_MEMORY = 9;
public static final int SERVICE_INSTANCE_JVM_MEMORY_POOL = 10;
public static final int SERVICE_INSTANCE_JVM_GC = 11;
public static final int SEGMENT = 12;
public static final int ALARM = 13;
public static final int SERVICE_INVENTORY = 14;
public static final int SERVICE_INSTANCE_INVENTORY = 15;
public static final int ENDPOINT_INVENTORY = 16;
public static final int DATABASE_ACCESS = 17;
public static final int DATABASE_SLOW_STATEMENT = 18;
public static class Listener implements AnnotationListener {
@Override public Class<? extends Annotation> annotation() {
return ScopeDeclaration.class;
}
@Override public void notify(Class originalClass) {
ScopeDeclaration declaration = (ScopeDeclaration)originalClass.getAnnotation(ScopeDeclaration.class);
if (declaration != null) {
addNewScope(declaration, originalClass);
}
}
}
public static final void addNewScope(ScopeDeclaration declaration, Class originalClass) {
int id = declaration.id();
if (ID_2_NAME.containsKey(id)) {
throw new UnexpectedException("ScopeDeclaration id=" + id + " at " + originalClass.getName() + " has conflict with another named " + ID_2_NAME.get(id));
}
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));
}
ID_2_NAME.put(id, name);
NAME_2_ID.put(name, id);
}
public static String nameOf(int id) {
String name = ID_2_NAME.get(id);
if (name == null) {
throw new UnexpectedException("ScopeDefine id = " + id + " not found.");
}
return name;
}
public static int valueOf(String name) {
Integer id = NAME_2_ID.get(name);
if (id == null) {
throw new UnexpectedException("ScopeDefine name = " + name + " not found.");
}
return id;
}
public static void reset() {
NAME_2_ID.clear();
ID_2_NAME.clear();
}
}

View File

@ -19,15 +19,16 @@
package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENDPOINT;
/**
* @author peng-yongsheng
*/
@SourceType
@ScopeDeclaration(id = ENDPOINT, name = "Endpoint")
public class Endpoint extends Source {
@Override public Scope scope() {
return Scope.Endpoint;
@Override public int scope() {
return DefaultScopeDefine.ENDPOINT;
}
@Override public String getEntityId() {

View File

@ -21,13 +21,16 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import org.apache.skywalking.oap.server.core.Const;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENDPOINT_RELATION;
/**
* @author peng-yongsheng
*/
@ScopeDeclaration(id = ENDPOINT_RELATION, name = "EndpointRelation")
public class EndpointRelation extends Source {
@Override public Scope scope() {
return Scope.EndpointRelation;
@Override public int scope() {
return DefaultScopeDefine.ENDPOINT_RELATION;
}
@Override public String getEntityId() {

View File

@ -18,18 +18,16 @@
package org.apache.skywalking.oap.server.core.source;
/**
* @author peng-yongsheng, wusheng
*/
public enum Scope {
All, Service, ServiceInstance, Endpoint, ServiceRelation, ServiceInstanceRelation, EndpointRelation, NetworkAddress,
ServiceInstanceJVMCPU, ServiceInstanceJVMMemory, ServiceInstanceJVMMemoryPool, ServiceInstanceJVMGC,
Segment, Alarm, ServiceInventory, ServiceInstanceInventory, EndpointInventory, DatabaseAccess, DatabaseSlowStatement;
import java.lang.annotation.*;
public static Scope valueOf(int ordinal) {
if (ordinal < 0 || ordinal >= values().length) {
throw new IndexOutOfBoundsException("Invalid ordinal");
}
return values()[ordinal];
}
/**
* DefaultScopeDefine id declaration.
*
* @author wusheng
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface ScopeDeclaration {
int id();
String name();
}

View File

@ -19,16 +19,17 @@
package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SEGMENT;
/**
* @author peng-yongsheng
*/
@SourceType
@ScopeDeclaration(id = SEGMENT, name = "Segment")
public class Segment extends Source {
@Override public Scope scope() {
return Scope.Segment;
@Override public int scope() {
return DefaultScopeDefine.SEGMENT;
}
@Override public String getEntityId() {

View File

@ -19,15 +19,16 @@
package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE;
/**
* @author wusheng, peng-yongsheng
*/
@SourceType
@ScopeDeclaration(id = SERVICE, name = "Service")
public class Service extends Source {
@Override public Scope scope() {
return Scope.Service;
@Override public int scope() {
return DefaultScopeDefine.SERVICE;
}
@Override public String getEntityId() {

View File

@ -19,15 +19,16 @@
package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE;
/**
* @author peng-yongsheng
*/
@SourceType
@ScopeDeclaration(id = SERVICE_INSTANCE, name = "ServiceInstance")
public class ServiceInstance extends Source {
@Override public Scope scope() {
return Scope.ServiceInstance;
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE;
}
@Override public String getEntityId() {

View File

@ -19,15 +19,16 @@
package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_JVM_CPU;
/**
* @author peng-yongsheng
*/
@SourceType
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_CPU, name = "ServiceInstanceJVMCPU")
public class ServiceInstanceJVMCPU extends Source {
@Override public Scope scope() {
return Scope.ServiceInstanceJVMCPU;
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE_JVM_CPU;
}
@Override public String getEntityId() {

View File

@ -19,15 +19,16 @@
package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import org.apache.skywalking.oap.server.core.source.annotation.SourceType;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_JVM_GC;
/**
* @author peng-yongsheng
*/
@SourceType
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_GC, name = "ServiceInstanceJVMGC")
public class ServiceInstanceJVMGC extends Source {
@Override public Scope scope() {
return Scope.ServiceInstanceJVMGC;
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE_JVM_GC;
}
@Override public String getEntityId() {

View File

@ -20,12 +20,15 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY;
/**
* @author peng-yongsheng
*/
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_MEMORY, name = "ServiceInstanceJVMMemory")
public class ServiceInstanceJVMMemory extends Source {
@Override public Scope scope() {
return Scope.ServiceInstanceJVMMemory;
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY;
}
@Override public String getEntityId() {

View File

@ -20,12 +20,15 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY_POOL;
/**
* @author peng-yongsheng
*/
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_MEMORY_POOL, name = "ServiceInstanceJVMMemoryPool")
public class ServiceInstanceJVMMemoryPool extends Source {
@Override public Scope scope() {
return Scope.ServiceInstanceJVMMemoryPool;
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY_POOL;
}
@Override public String getEntityId() {

View File

@ -21,13 +21,16 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import org.apache.skywalking.oap.server.core.Const;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_RELATION;
/**
* @author peng-yongsheng
*/
@ScopeDeclaration(id = SERVICE_INSTANCE_RELATION, name = "ServiceInstanceRelation")
public class ServiceInstanceRelation extends Source {
@Override public Scope scope() {
return Scope.ServiceInstanceRelation;
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE_RELATION;
}
@Override public String getEntityId() {

View File

@ -21,13 +21,16 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import org.apache.skywalking.oap.server.core.Const;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_RELATION;
/**
* @author peng-yongsheng
*/
@ScopeDeclaration(id = SERVICE_RELATION, name = "ServiceRelation")
public class ServiceRelation extends Source {
@Override public Scope scope() {
return Scope.ServiceRelation;
@Override public int scope() {
return DefaultScopeDefine.SERVICE_RELATION;
}
@Override public String getEntityId() {

View File

@ -24,7 +24,7 @@ import lombok.*;
* @author peng-yongsheng
*/
public abstract class Source {
public abstract Scope scope();
public abstract int scope();
@Getter @Setter private long timeBucket;

View File

@ -19,7 +19,6 @@
package org.apache.skywalking.oap.server.core.storage;
import org.apache.skywalking.oap.server.core.register.RegisterSource;
import org.apache.skywalking.oap.server.core.source.Scope;
/**
* Entity register and ID generator.
@ -32,8 +31,8 @@ public interface IRegisterLockDAO extends DAO {
* in concurrent way, so no `sync` in method level, but the implementation must make sure the return id is unique no
* matter the cluster size.
*
* @param scope for the id. IDs at different scopes could be same, but unique in same scope.
* @param scopeId for the id. IDs at different scopes could be same, but unique in same scope.
* @return Unique ID.
*/
int getId(Scope scope, RegisterSource registerSource);
int getId(int scopeId, RegisterSource registerSource);
}

View File

@ -20,20 +20,13 @@ package org.apache.skywalking.oap.server.core.storage.annotation;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.*;
import lombok.Getter;
import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorAnnotationUtils;
import org.apache.skywalking.oap.server.core.annotation.AnnotationListener;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.model.ColumnName;
import org.apache.skywalking.oap.server.core.storage.model.IModelGetter;
import org.apache.skywalking.oap.server.core.storage.model.IModelOverride;
import org.apache.skywalking.oap.server.core.storage.model.Model;
import org.apache.skywalking.oap.server.core.storage.model.ModelColumn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.core.storage.model.*;
import org.slf4j.*;
/**
* @author peng-yongsheng
@ -57,12 +50,14 @@ public class StorageAnnotationListener implements AnnotationListener, IModelGett
String modelName = StorageEntityAnnotationUtils.getModelName(aClass);
boolean deleteHistory = StorageEntityAnnotationUtils.getDeleteHistory(aClass);
Scope sourceScope = StorageEntityAnnotationUtils.getSourceScope(aClass);
int sourceScopeId = StorageEntityAnnotationUtils.getSourceScope(aClass);
// Check this scope id is valid.
DefaultScopeDefine.nameOf(sourceScopeId);
List<ModelColumn> modelColumns = new LinkedList<>();
boolean isIndicator = IndicatorAnnotationUtils.isIndicator(aClass);
retrieval(aClass, modelName, modelColumns);
models.add(new Model(modelName, modelColumns, isIndicator, deleteHistory, sourceScope));
models.add(new Model(modelName, modelColumns, isIndicator, deleteHistory, sourceScopeId));
}
private void retrieval(Class clazz, String modelName, List<ModelColumn> modelColumns) {

View File

@ -19,7 +19,6 @@
package org.apache.skywalking.oap.server.core.storage.annotation;
import java.lang.annotation.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
/**
@ -32,7 +31,10 @@ public @interface StorageEntity {
Class<? extends StorageBuilder> builder();
Scope source();
/**
* @return scope id.
*/
int sourceScopeId();
boolean deleteHistory() default true;
}

View File

@ -19,7 +19,6 @@
package org.apache.skywalking.oap.server.core.storage.annotation;
import org.apache.skywalking.oap.server.core.UnexpectedException;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
/**
@ -54,10 +53,10 @@ public class StorageEntityAnnotationUtils {
}
}
public static Scope getSourceScope(Class aClass) {
public static int getSourceScope(Class aClass) {
if (aClass.isAnnotationPresent(StorageEntity.class)) {
StorageEntity annotation = (StorageEntity)aClass.getAnnotation(StorageEntity.class);
return annotation.source();
return annotation.sourceScopeId();
} else {
throw new UnexpectedException("");
}

View File

@ -20,7 +20,6 @@ package org.apache.skywalking.oap.server.core.storage.model;
import java.util.List;
import lombok.Getter;
import org.apache.skywalking.oap.server.core.source.Scope;
/**
* @author peng-yongsheng
@ -31,17 +30,18 @@ public class Model {
private final boolean isIndicator;
private final boolean deleteHistory;
private final List<ModelColumn> columns;
private final Scope source;
private final int sourceScopeId;
public Model(String name, List<ModelColumn> columns, boolean isIndicator, boolean deleteHistory, Scope source) {
public Model(String name, List<ModelColumn> columns, boolean isIndicator, boolean deleteHistory,
int sourceScopeId) {
this.name = name;
this.columns = columns;
this.isIndicator = isIndicator;
this.deleteHistory = deleteHistory;
this.source = source;
this.sourceScopeId = sourceScopeId;
}
public Model copy(String name) {
return new Model(name, columns, isIndicator, deleteHistory, source);
return new Model(name, columns, isIndicator, deleteHistory, sourceScopeId);
}
}

View File

@ -19,8 +19,7 @@
package org.apache.skywalking.oap.server.core.storage.query;
import java.io.IOException;
import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.query.entity.Alarms;
import org.apache.skywalking.oap.server.core.storage.DAO;
/**
@ -28,6 +27,6 @@ import org.apache.skywalking.oap.server.core.storage.DAO;
*/
public interface IAlarmQueryDAO extends DAO {
Alarms getAlarm(final Scope scope, final String keyword, final int limit, final int from, final long startTB,
Alarms getAlarm(final Integer scopeId, final String keyword, final int limit, final int from, final long startTB,
final long endTB) throws IOException;
}

View File

@ -20,11 +20,10 @@ package org.apache.skywalking.oap.query.graphql.resolver;
import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import java.io.IOException;
import org.apache.skywalking.oap.query.graphql.type.Duration;
import org.apache.skywalking.oap.query.graphql.type.*;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.query.*;
import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
/**
@ -55,6 +54,6 @@ public class AlarmQuery implements GraphQLQueryResolver {
long startTimeBucket = DurationUtils.INSTANCE.startTimeDurationToSecondTimeBucket(duration.getStep(), duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.endTimeDurationToSecondTimeBucket(duration.getStep(), duration.getEnd());
return getQueryService().getAlarm(scope, keyword, paging, startTimeBucket, endTimeBucket);
return getQueryService().getAlarm(scope.getScopeId(), keyword, paging, startTimeBucket, endTimeBucket);
}
}

View File

@ -22,7 +22,6 @@ import java.io.IOException;
import java.util.Map;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.RegisterSource;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.IRegisterLockDAO;
import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.EsDAO;
@ -41,8 +40,8 @@ public class RegisterLockDAOImpl extends EsDAO implements IRegisterLockDAO {
super(client);
}
@Override public int getId(Scope scope, RegisterSource registerSource) {
String id = String.valueOf(scope.ordinal());
@Override public int getId(int scopeId, RegisterSource registerSource) {
String id = scopeId + "";
int sequence = Const.NONE;
try {

View File

@ -20,7 +20,6 @@ package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.lock;
import java.io.IOException;
import org.apache.skywalking.oap.server.core.register.worker.InventoryProcess;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.StorageException;
import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntityAnnotationUtils;
import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
@ -56,8 +55,8 @@ public class RegisterLockInstaller {
}
for (Class registerSource : InventoryProcess.INSTANCE.getAllRegisterSources()) {
Scope sourceScope = StorageEntityAnnotationUtils.getSourceScope(registerSource);
putIfAbsent(sourceScope.ordinal());
int sourceScopeId = StorageEntityAnnotationUtils.getSourceScope(registerSource);
putIfAbsent(sourceScopeId);
}
} catch (IOException e) {
throw new StorageException(e.getMessage());

View File

@ -23,7 +23,6 @@ import java.io.IOException;
import java.util.Objects;
import org.apache.skywalking.oap.server.core.alarm.AlarmRecord;
import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.query.IAlarmQueryDAO;
import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.*;
@ -41,15 +40,16 @@ public class AlarmQueryEsDAO extends EsDAO implements IAlarmQueryDAO {
super(client);
}
public Alarms getAlarm(final Scope scope, final String keyword, final int limit, final int from, final long startTB,
public Alarms getAlarm(final Integer scopeId, final String keyword, final int limit, final int from,
final long startTB,
final long endTB) throws IOException {
SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must().add(QueryBuilders.rangeQuery(AlarmRecord.TIME_BUCKET).gte(startTB).lte(endTB));
if (Objects.nonNull(scope)) {
boolQueryBuilder.must().add(QueryBuilders.termQuery(AlarmRecord.SCOPE, scope.ordinal()));
if (Objects.nonNull(scopeId)) {
boolQueryBuilder.must().add(QueryBuilders.termQuery(AlarmRecord.SCOPE, scopeId.intValue()));
}
if (!Strings.isNullOrEmpty(keyword)) {
@ -74,7 +74,8 @@ public class AlarmQueryEsDAO extends EsDAO implements IAlarmQueryDAO {
message.setId(String.valueOf(alarmRecord.getId0()));
message.setMessage(alarmRecord.getAlarmMessage());
message.setStartTime(alarmRecord.getStartTime());
message.setScope(Scope.valueOf(alarmRecord.getScope()));
message.setScope(Scope.Finder.valueOf(alarmRecord.getScope()));
message.setScopeId(alarmRecord.getScope());
alarms.getMsgs().add(message);
}
return alarms;

View File

@ -23,7 +23,6 @@ import java.sql.*;
import java.util.*;
import org.apache.skywalking.oap.server.core.alarm.AlarmRecord;
import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.query.IAlarmQueryDAO;
import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient;
import org.elasticsearch.common.Strings;
@ -39,13 +38,15 @@ public class H2AlarmQueryDAO implements IAlarmQueryDAO {
}
@Override
public Alarms getAlarm(Scope scope, String keyword, int limit, int from, long startTB,
public Alarms getAlarm(Integer scopeId, String keyword, int limit, int from, long startTB,
long endTB) throws IOException {
StringBuilder sql = new StringBuilder();
List<Object> parameters = new ArrayList<>(10);
sql.append("from ").append(AlarmRecord.INDEX_NAME).append(" where ");
sql.append(" 1=1 ");
sql.append(" and ").append(AlarmRecord.SCOPE).append(" = ?");
parameters.add(scopeId.intValue());
if (startTB != 0 && endTB != 0) {
sql.append(" and ").append(AlarmRecord.TIME_BUCKET).append(" >= ?");
parameters.add(startTB);
@ -75,7 +76,8 @@ public class H2AlarmQueryDAO implements IAlarmQueryDAO {
message.setId(resultSet.getString(AlarmRecord.ID0));
message.setMessage(resultSet.getString(AlarmRecord.ALARM_MESSAGE));
message.setStartTime(resultSet.getLong(AlarmRecord.START_TIME));
message.setScope(Scope.valueOf(resultSet.getInt(AlarmRecord.SCOPE)));
message.setScope(Scope.Finder.valueOf(resultSet.getInt(AlarmRecord.SCOPE)));
message.setScopeId(resultSet.getInt(AlarmRecord.SCOPE));
alarms.getMsgs().add(message);
}

Some files were not shown because too many files have changed in this diff Show More