The prototype codes of alarm bridge only.

This commit is contained in:
Wu Sheng 2018-08-28 17:25:04 +08:00
parent 38212dc97c
commit 42eb8f7376
19 changed files with 491 additions and 31 deletions

View File

@ -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.
- [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.

View File

@ -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);

View File

@ -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};
}
}

View File

@ -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
}

View File

@ -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<Class, NotifyTarget> notifyTarget;
IndicatorAlarmListener() {
notifyTarget = new HashMap<>();
}
@Override public Class<? extends Annotation> 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);
}
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}
}

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.oap.server.core.analysis.indicator;
/**
* DoubleValueHolder always holds a value of double.
*
* @author wusheng
*/
public interface DoubleValueHolder {
double getValue();
}

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.oap.server.core.analysis.indicator;
/**
* IntValueHolder always holds a value of int.
*
* @author wusheng
*/
public interface IntValueHolder {
int getValue();
}

View File

@ -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;
}
}

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.oap.server.core.analysis.indicator;
/**
* LongValueHolder always holds a value of long.
*
* @author wusheng
*/
public interface LongValueHolder {
long getValue();
}

View File

@ -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;
}
}

View File

@ -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<Indicator> {
public AlarmNotifyWorker(int workerId) {
super(workerId);
}
@Override public void in(Indicator indicator) {
}
}

View File

@ -40,15 +40,17 @@ public class IndicatorPersistentWorker extends AbstractWorker<Indicator> {
private final IBatchDAO batchDAO;
private final IIndicatorDAO indicatorDAO;
private final int blockBatchPersistenceSize;
private final AbstractWorker<Indicator> nextWorker;
IndicatorPersistentWorker(int workerId, String modelName, int batchSize, ModuleManager moduleManager,
IIndicatorDAO indicatorDAO) {
IIndicatorDAO indicatorDAO, AbstractWorker<Indicator> 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<MergeDataCollection<Indicator>> getCache() {
@ -100,19 +102,17 @@ public class IndicatorPersistentWorker extends AbstractWorker<Indicator> {
} 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);
}
});

View File

@ -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);

View File

@ -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<AnnotationListener> listeners;
private final List<AnnotationListenerCache> 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<Class<?>> matchedClass;
private AnnotationListenerCache(AnnotationListener listener) {
this.listener = listener;
matchedClass = new LinkedList<>();
}
private Class<? extends Annotation> 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));
}
}
}

View File

@ -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
org.apache.skywalking.oap.server.core.query.QueryModule
org.apache.skywalking.oap.server.core.alarm.AlarmModule

View File

@ -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<String, Object> data2Map(StorageData storageData) {
return null;
}
}
}