diff --git a/docs/en/setup/README.md b/docs/en/setup/README.md index 0bf613ab9..0840de0ec 100644 --- a/docs/en/setup/README.md +++ b/docs/en/setup/README.md @@ -2,12 +2,16 @@ Setup based on which kind of probes are you going to use. If you don't understand, please read [Concepts and Designs](../concepts-and-designs/README.md) first. ## Language agents in Service - - Install agents - - [Java agent](service-agent/java-agent/README.md). Introduce how to install java agent to your service, without change any codes. - - [.NET Core agent](https://github.com/OpenSkywalking/skywalking-netcore). See .NET Core agent project document for more details. - - [Node.js agent](https://github.com/OpenSkywalking/skywalking-nodejs). See Node.js server side agent project document for more details. - - [Setup backend](backend/backend-language-agent-setup.md). Set the backend for language agents scenario. - + +- [Java agent](service-agent/java-agent/README.md). Introduce how to install java agent to your service, without change any codes. +- [.NET Core agent](https://github.com/OpenSkywalking/skywalking-netcore). See .NET Core agent project document for more details. +- [Node.js agent](https://github.com/OpenSkywalking/skywalking-nodejs). See Node.js server side agent project document for more details. + ## On Service Mesh - Istio - - [SkyWalking on Istio](istio/README.md). Introduce how to use Istio Mixer SkyWalking Adapter to work with SkyWalking. \ No newline at end of file + - [SkyWalking on Istio](istio/README.md). Introduce how to use Istio Mixer SkyWalking Adapter to work with SkyWalking. + + +## Setup backend +Follow [backend setup document](backend/backend-language-agent-setup.md) to understand and config the backend for different +scenarios, and open advanced features. \ No newline at end of file diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java index d01de7d4a..9605e2b89 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/CoreModuleProvider.java @@ -19,6 +19,7 @@ package org.apache.skywalking.oap.server.core; import java.io.IOException; +import org.apache.skywalking.oap.server.core.alarm.IndicatorAlarmListener; import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorTypeListener; import org.apache.skywalking.oap.server.core.annotation.AnnotationScan; import org.apache.skywalking.oap.server.core.cache.*; @@ -108,6 +109,7 @@ public class CoreModuleProvider extends ModuleProvider { annotationScan.registerListener(streamAnnotationListener); annotationScan.registerListener(new IndicatorTypeListener(getManager())); annotationScan.registerListener(new InventoryTypeListener(getManager())); + annotationScan.registerListener(IndicatorAlarmListener.INSTANCE); this.remoteClientManager = new RemoteClientManager(getManager()); this.registerServiceImplementation(RemoteClientManager.class, remoteClientManager); diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmModule.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmModule.java new file mode 100644 index 000000000..e7cb96daf --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/AlarmModule.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.oap.server.core.alarm; + +import org.apache.skywalking.oap.server.library.module.ModuleDefine; + +/** + * Alarm module define the main bridge entrance of the alarm implementor. + * + * SkyWalking supports alarm implementation pluggable. + * + * @author wusheng + */ +public class AlarmModule extends ModuleDefine { + public static final String NAME = "alarm"; + + @Override public String name() { + return NAME; + } + + @Override public Class[] services() { + return new Class[] {IndicatorNotify.class}; + } +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/IndicatorAlarmDataType.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/IndicatorAlarmDataType.java new file mode 100644 index 000000000..96c3ee753 --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/IndicatorAlarmDataType.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.oap.server.core.alarm; + +/** + * Indicator Alarm data type represents the indicator result data time, based on this, the core drives the {@link + * IndicatorNotify} to notify the alarm implementor. + * + * @author wusheng + */ +public enum IndicatorAlarmDataType { + LONG, INT, DOUBLE +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/IndicatorAlarmListener.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/IndicatorAlarmListener.java new file mode 100644 index 000000000..3c496e1f5 --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/IndicatorAlarmListener.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.oap.server.core.alarm; + +import java.lang.annotation.Annotation; +import java.util.HashMap; +import org.apache.skywalking.oap.server.core.analysis.indicator.DoubleValueHolder; +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.analysis.indicator.annotation.IndicatorType; +import org.apache.skywalking.oap.server.core.annotation.AnnotationListener; +import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntity; + +/** + * Indicator Alarm listener does the pre-analysis of each indicator implementation, when alarm happens, it drives + * notification based on indicator value data type. + * + * @author wusheng + */ +public class IndicatorAlarmListener implements AnnotationListener { + public static final IndicatorAlarmListener INSTANCE = new IndicatorAlarmListener(); + + private final HashMap notifyTarget; + + IndicatorAlarmListener() { + notifyTarget = new HashMap<>(); + } + + @Override public Class annotation() { + return IndicatorType.class; + } + + @Override public void notify(Class aClass) { + StorageEntity storageEntityAnnotation = (StorageEntity)aClass.getAnnotation(StorageEntity.class); + if (storageEntityAnnotation == null) { + return; + } + String indicatorName = storageEntityAnnotation.name(); + + NotifyTarget target = new NotifyTarget(); + target.setIndicatorName(indicatorName); + if (DoubleValueHolder.class.isAssignableFrom(aClass)) { + target.setDataType(IndicatorAlarmDataType.DOUBLE); + } else if (LongValueHolder.class.isAssignableFrom(aClass)) { + target.setDataType(IndicatorAlarmDataType.LONG); + } else if (IntValueHolder.class.isAssignableFrom(aClass)) { + target.setDataType(IndicatorAlarmDataType.INT); + } else { + // If don't declare as any value holder, this is not an alarm candidate value. + return; + } + + notifyTarget.put(aClass, target); + } + + public NotifyTarget getTarget(Class indicatorClass) { + return notifyTarget.get(indicatorClass); + } +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/IndicatorNotify.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/IndicatorNotify.java new file mode 100644 index 000000000..a281f0c17 --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/IndicatorNotify.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.oap.server.core.alarm; + +import org.apache.skywalking.oap.server.library.module.Service; + +/** + * Indicator notify service should be provided by Alarm Module provider, which can receive the indicator value, driven + * by storage core. + * + * The alarm module provider could choose whether or how to do the alarm. Meanwhile, the storage core will provide the + * standard persistence service for generated alarm, if the alarm engine wants the alarm to show in UI, please call + * those to save. + * + * @author wusheng + */ +public interface IndicatorNotify extends Service { + void notify(String indicatorName, double value); + + void notify(String indicatorName, int value); + + void notify(String indicatorName, long value); +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/NotifyTarget.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/NotifyTarget.java new file mode 100644 index 000000000..4919d50c9 --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/alarm/NotifyTarget.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.oap.server.core.alarm; + +import lombok.Getter; +import lombok.Setter; + +/** + * @author wusheng + */ +public class NotifyTarget { + @Setter @Getter private String indicatorName; + @Setter @Getter private IndicatorAlarmDataType dataType; +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/DoubleAvgIndicator.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/DoubleAvgIndicator.java index 895fa871a..341029bad 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/DoubleAvgIndicator.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/DoubleAvgIndicator.java @@ -26,7 +26,7 @@ import org.apache.skywalking.oap.server.core.storage.annotation.Column; * @author peng-yongsheng */ @IndicatorOperator -public abstract class DoubleAvgIndicator extends Indicator { +public abstract class DoubleAvgIndicator extends Indicator implements DoubleValueHolder { protected static final String SUMMATION = "summation"; protected static final String COUNT = "count"; @@ -50,4 +50,8 @@ public abstract class DoubleAvgIndicator extends Indicator { @Override public final void calculate() { this.value = this.summation / this.count; } + + @Override public double getValue() { + return value; + } } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/DoubleValueHolder.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/DoubleValueHolder.java new file mode 100644 index 000000000..645ed76ce --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/DoubleValueHolder.java @@ -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.oap.server.core.analysis.indicator; + +/** + * DoubleValueHolder always holds a value of double. + * + * @author wusheng + */ +public interface DoubleValueHolder { + double getValue(); +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/IntValueHolder.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/IntValueHolder.java new file mode 100644 index 000000000..44f46b2ba --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/IntValueHolder.java @@ -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.oap.server.core.analysis.indicator; + +/** + * IntValueHolder always holds a value of int. + * + * @author wusheng + */ +public interface IntValueHolder { + int getValue(); +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/LongAvgIndicator.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/LongAvgIndicator.java index 1649af3ac..ecb1b6644 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/LongAvgIndicator.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/LongAvgIndicator.java @@ -18,15 +18,19 @@ package org.apache.skywalking.oap.server.core.analysis.indicator; -import lombok.*; -import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.*; +import lombok.Getter; +import lombok.Setter; +import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.ConstOne; +import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.Entrance; +import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorOperator; +import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.SourceFrom; import org.apache.skywalking.oap.server.core.storage.annotation.Column; /** * @author peng-yongsheng */ @IndicatorOperator -public abstract class LongAvgIndicator extends Indicator { +public abstract class LongAvgIndicator extends Indicator implements LongValueHolder { protected static final String SUMMATION = "summation"; protected static final String COUNT = "count"; @@ -50,4 +54,8 @@ public abstract class LongAvgIndicator extends Indicator { @Override public final void calculate() { this.value = this.summation / this.count; } + + @Override public long getValue() { + return value; + } } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/LongValueHolder.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/LongValueHolder.java new file mode 100644 index 000000000..59b580845 --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/LongValueHolder.java @@ -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.oap.server.core.analysis.indicator; + +/** + * LongValueHolder always holds a value of long. + * + * @author wusheng + */ +public interface LongValueHolder { + long getValue(); +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/PercentIndicator.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/PercentIndicator.java index 113551219..44b6bfe47 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/PercentIndicator.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/indicator/PercentIndicator.java @@ -27,7 +27,7 @@ import org.apache.skywalking.oap.server.core.storage.annotation.Column; * @author wusheng */ @IndicatorOperator -public abstract class PercentIndicator extends Indicator { +public abstract class PercentIndicator extends Indicator implements IntValueHolder { protected static final String TOTAL = "total"; protected static final String MATCH = "match"; protected static final String PERCENTAGE = "percentage"; @@ -53,6 +53,10 @@ public abstract class PercentIndicator extends Indicator { } @Override public void calculate() { - percentage = (int)(match / total); + percentage = (int)(match * 100 / total); + } + + @Override public int getValue() { + return percentage; } } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/AlarmNotifyWorker.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/AlarmNotifyWorker.java new file mode 100644 index 000000000..9400b7b47 --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/AlarmNotifyWorker.java @@ -0,0 +1,37 @@ +/* + * 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.worker; + +import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator; +import org.apache.skywalking.oap.server.core.worker.AbstractWorker; + +/** + * Alarm notify worker, do a simple route to alarm core after the aggregation persistence. + * + * @author wusheng + */ +public class AlarmNotifyWorker extends AbstractWorker { + public AlarmNotifyWorker(int workerId) { + super(workerId); + } + + @Override public void in(Indicator indicator) { + + } +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/IndicatorPersistentWorker.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/IndicatorPersistentWorker.java index 1ac53e76e..3a5bbe503 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/IndicatorPersistentWorker.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/IndicatorPersistentWorker.java @@ -40,15 +40,17 @@ public class IndicatorPersistentWorker extends AbstractWorker { private final IBatchDAO batchDAO; private final IIndicatorDAO indicatorDAO; private final int blockBatchPersistenceSize; + private final AbstractWorker nextWorker; IndicatorPersistentWorker(int workerId, String modelName, int batchSize, ModuleManager moduleManager, - IIndicatorDAO indicatorDAO) { + IIndicatorDAO indicatorDAO, AbstractWorker nextWorker) { super(workerId); this.modelName = modelName; this.blockBatchPersistenceSize = batchSize; this.mergeDataCache = new MergeDataCache<>(); this.batchDAO = moduleManager.find(StorageModule.NAME).getService(IBatchDAO.class); this.indicatorDAO = indicatorDAO; + this.nextWorker = nextWorker; } public final Window> getCache() { @@ -100,19 +102,17 @@ public class IndicatorPersistentWorker extends AbstractWorker { } catch (Throwable t) { logger.error(t.getMessage(), t); } - if (nonNull(dbData)) { - dbData.combine(data); - try { - batchCollection.add(indicatorDAO.prepareBatchUpdate(modelName, dbData)); - } catch (Throwable t) { - logger.error(t.getMessage(), t); - } - } else { - try { + try { + if (nonNull(dbData)) { + data.combine(dbData); + batchCollection.add(indicatorDAO.prepareBatchUpdate(modelName, data)); + } else { batchCollection.add(indicatorDAO.prepareBatchInsert(modelName, data)); - } catch (Throwable t) { - logger.error(t.getMessage(), t); } + + nextWorker.in(data); + } catch (Throwable t) { + logger.error(t.getMessage(), t); } }); diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/IndicatorProcess.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/IndicatorProcess.java index 398d61d18..62c335fae 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/IndicatorProcess.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/IndicatorProcess.java @@ -50,7 +50,11 @@ public enum IndicatorProcess { throw new UnexpectedException(""); } - IndicatorPersistentWorker persistentWorker = new IndicatorPersistentWorker(WorkerIdGenerator.INSTANCES.generate(), modelName, 1000, moduleManager, indicatorDAO); + AlarmNotifyWorker alarmNotifyWorker = new AlarmNotifyWorker(WorkerIdGenerator.INSTANCES.generate()); + WorkerInstances.INSTANCES.put(alarmNotifyWorker.getWorkerId(), alarmNotifyWorker); + + IndicatorPersistentWorker persistentWorker = new IndicatorPersistentWorker(WorkerIdGenerator.INSTANCES.generate(), modelName, + 1000, moduleManager, indicatorDAO, alarmNotifyWorker); WorkerInstances.INSTANCES.put(persistentWorker.getWorkerId(), persistentWorker); IndicatorRemoteWorker remoteWorker = new IndicatorRemoteWorker(WorkerIdGenerator.INSTANCES.generate(), moduleManager, persistentWorker); diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/annotation/AnnotationScan.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/annotation/AnnotationScan.java index 94d67cd77..7d9cd8af8 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/annotation/AnnotationScan.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/annotation/AnnotationScan.java @@ -21,6 +21,7 @@ package org.apache.skywalking.oap.server.core.annotation; import com.google.common.collect.ImmutableSet; import com.google.common.reflect.ClassPath; import java.io.IOException; +import java.lang.annotation.Annotation; import java.util.*; /** @@ -28,14 +29,14 @@ import java.util.*; */ public class AnnotationScan { - private final List listeners; + private final List listeners; public AnnotationScan() { this.listeners = new LinkedList<>(); } public void registerListener(AnnotationListener listener) { - listeners.add(listener); + listeners.add(new AnnotationListenerCache(listener)); } public void scan(Runnable callBack) throws IOException { @@ -44,13 +45,40 @@ public class AnnotationScan { for (ClassPath.ClassInfo classInfo : classes) { Class aClass = classInfo.load(); - for (AnnotationListener listener : listeners) { + for (AnnotationListenerCache listener : listeners) { if (aClass.isAnnotationPresent(listener.annotation())) { - listener.notify(aClass); + listener.addMatch(aClass); } } } + listeners.forEach(listener -> + listener.complete() + ); + callBack.run(); } + + public class AnnotationListenerCache { + private AnnotationListener listener; + private List> matchedClass; + + private AnnotationListenerCache(AnnotationListener listener) { + this.listener = listener; + matchedClass = new LinkedList<>(); + } + + private Class annotation() { + return this.listener.annotation(); + } + + private void addMatch(Class aClass) { + matchedClass.add(aClass); + } + + private void complete() { + matchedClass.sort(Comparator.comparing(Class::getName)); + matchedClass.forEach(aClass -> listener.notify(aClass)); + } + } } diff --git a/oap-server/server-core/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine b/oap-server/server-core/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine index af910c0f3..3c8629fc2 100644 --- a/oap-server/server-core/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine +++ b/oap-server/server-core/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.library.module.ModuleDefine @@ -19,4 +19,5 @@ org.apache.skywalking.oap.server.core.storage.StorageModule org.apache.skywalking.oap.server.core.cluster.ClusterModule org.apache.skywalking.oap.server.core.CoreModule -org.apache.skywalking.oap.server.core.query.QueryModule \ No newline at end of file +org.apache.skywalking.oap.server.core.query.QueryModule +org.apache.skywalking.oap.server.core.alarm.AlarmModule \ No newline at end of file diff --git a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/alarm/IndicatorAlarmListenerTest.java b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/alarm/IndicatorAlarmListenerTest.java new file mode 100644 index 000000000..f1ce098ae --- /dev/null +++ b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/alarm/IndicatorAlarmListenerTest.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.oap.server.core.alarm; + +import java.util.Map; +import org.apache.skywalking.oap.server.core.analysis.indicator.LongValueHolder; +import org.apache.skywalking.oap.server.core.analysis.indicator.annotation.IndicatorType; +import org.apache.skywalking.oap.server.core.storage.StorageBuilder; +import org.apache.skywalking.oap.server.core.storage.StorageData; +import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntity; +import org.junit.Assert; +import org.junit.Test; + +public class IndicatorAlarmListenerTest { + @Test + public void testIndicatorPreAnalysis() { + IndicatorAlarmListener listener = new IndicatorAlarmListener(); + listener.notify(ATestClass.class); + listener.notify(UnCompleteIndicator.class); + listener.notify(MockIndicator.class); + + Assert.assertNull(listener.getTarget(ATestClass.class)); + Assert.assertNull(listener.getTarget(UnCompleteIndicator.class)); + Assert.assertNotNull(listener.getTarget(MockIndicator.class)); + } + + public class ATestClass { + + } + + @IndicatorType + public class UnCompleteIndicator { + + } + + @IndicatorType + @StorageEntity(name = "mock_indicator", builder = MockBuilder.class) + public class MockIndicator implements LongValueHolder { + + @Override public long getValue() { + return 0; + } + } + + public class MockBuilder implements StorageBuilder { + + @Override public StorageData map2Data(Map dbMap) { + return null; + } + + @Override public Map data2Map(StorageData storageData) { + return null; + } + } +}