提交 975a06d1 编写于 作者: wu-sheng's avatar wu-sheng 提交者: 彭勇升 pengys

Add catalog to ScopeDeclaration annotation. Make the alarm adapt to it. Now...

Add catalog to ScopeDeclaration annotation. Make the alarm adapt to it. Now more metric could go through alarm, such as JVM, CLR. (#2391)
上级 34381516
......@@ -25,6 +25,8 @@ import org.apache.skywalking.oap.server.library.module.*;
import org.apache.skywalking.oap.server.library.util.ResourceUtils;
public class AlarmModuleProvider extends ModuleProvider {
private NotifyHandler notifyHandler;
@Override public String name() {
return "default";
}
......@@ -46,7 +48,7 @@ public class AlarmModuleProvider extends ModuleProvider {
}
RulesReader reader = new RulesReader(applicationReader);
Rules rules = reader.readRules();
NotifyHandler notifyHandler = new NotifyHandler(rules);
notifyHandler = new NotifyHandler(rules);
notifyHandler.init(new AlarmStandardPersistence());
this.registerServiceImplementation(IndicatorNotify.class, notifyHandler);
}
......@@ -55,7 +57,7 @@ public class AlarmModuleProvider extends ModuleProvider {
}
@Override public void notifyAfterCompleted() throws ServiceNotProvidedException, ModuleStartException {
notifyHandler.initCache(getManager());
}
@Override public String[] requiredModules() {
......
......@@ -18,16 +18,20 @@
package org.apache.skywalking.oap.server.core.alarm.provider;
import java.util.ArrayList;
import java.util.List;
import org.apache.skywalking.oap.server.core.alarm.AlarmCallback;
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.*;
import java.util.*;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.alarm.*;
import org.apache.skywalking.oap.server.core.analysis.indicator.*;
import org.apache.skywalking.oap.server.core.cache.*;
import org.apache.skywalking.oap.server.core.register.*;
import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
public class NotifyHandler implements IndicatorNotify {
private ServiceInventoryCache serviceInventoryCache;
private ServiceInstanceInventoryCache serviceInstanceInventoryCache;
private EndpointInventoryCache endpointInventoryCache;
private final AlarmCore core;
private final Rules rules;
......@@ -36,23 +40,58 @@ public class NotifyHandler implements IndicatorNotify {
core = new AlarmCore(rules);
}
@Override public void notify(MetaInAlarm meta, Indicator indicator) {
switch (meta.getScopeId()) {
case SERVICE:
break;
case SERVICE_INSTANCE:
break;
case ENDPOINT:
break;
default:
return;
@Override public void notify(Indicator indicator) {
WithMetadata withMetadata = (WithMetadata)indicator;
IndicatorMetaInfo meta = withMetadata.getMeta();
int scope = meta.getScope();
if (!DefaultScopeDefine.inServiceCatalog(scope)
&& !DefaultScopeDefine.inServiceInstanceCatalog(scope)
&& !DefaultScopeDefine.inEndpointCatalog(scope)) {
return;
}
MetaInAlarm metaInAlarm;
if (DefaultScopeDefine.inServiceCatalog(scope)) {
int serviceId = Integer.parseInt(meta.getId());
ServiceInventory serviceInventory = serviceInventoryCache.get(serviceId);
ServiceMetaInAlarm serviceMetaInAlarm = new ServiceMetaInAlarm();
serviceMetaInAlarm.setIndicatorName(meta.getIndicatorName());
serviceMetaInAlarm.setId(serviceId);
serviceMetaInAlarm.setName(serviceInventory.getName());
metaInAlarm = serviceMetaInAlarm;
} else if (DefaultScopeDefine.inServiceInstanceCatalog(scope)) {
int serviceInstanceId = Integer.parseInt(meta.getId());
ServiceInstanceInventory serviceInstanceInventory = serviceInstanceInventoryCache.get(serviceInstanceId);
ServiceInstanceMetaInAlarm instanceMetaInAlarm = new ServiceInstanceMetaInAlarm();
instanceMetaInAlarm.setIndicatorName(meta.getIndicatorName());
instanceMetaInAlarm.setId(serviceInstanceId);
instanceMetaInAlarm.setName(serviceInstanceInventory.getName());
metaInAlarm = instanceMetaInAlarm;
} else if (DefaultScopeDefine.inEndpointCatalog(scope)) {
int endpointId = Integer.parseInt(meta.getId());
EndpointInventory endpointInventory = endpointInventoryCache.get(endpointId);
EndpointMetaInAlarm endpointMetaInAlarm = new EndpointMetaInAlarm();
endpointMetaInAlarm.setIndicatorName(meta.getIndicatorName());
endpointMetaInAlarm.setId(endpointId);
int serviceId = endpointInventory.getServiceId();
ServiceInventory serviceInventory = serviceInventoryCache.get(serviceId);
String textName = endpointInventory.getName() + " in " + serviceInventory.getName();
endpointMetaInAlarm.setName(textName);
metaInAlarm = endpointMetaInAlarm;
} else {
return;
}
List<RunningRule> runningRules = core.findRunningRule(meta.getIndicatorName());
if (runningRules == null) {
return;
}
runningRules.forEach(rule -> rule.in(meta, indicator));
runningRules.forEach(rule -> rule.in(metaInAlarm, indicator));
}
public void init(AlarmCallback... callbacks) {
......@@ -64,4 +103,9 @@ public class NotifyHandler implements IndicatorNotify {
core.start(allCallbacks);
}
public void initCache(ModuleManager moduleManager) {
serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class);
endpointInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(EndpointInventoryCache.class);
}
}
......@@ -18,29 +18,18 @@
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.*;
import org.apache.skywalking.oap.server.core.cache.*;
import org.apache.skywalking.oap.server.core.register.*;
import org.apache.skywalking.oap.server.core.analysis.indicator.Indicator;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.*;
/**
* @author wusheng
*/
public class AlarmEntrance {
private ModuleManager moduleManager;
private ServiceInventoryCache serviceInventoryCache;
private ServiceInstanceInventoryCache serviceInstanceInventoryCache;
private EndpointInventoryCache endpointInventoryCache;
private IndicatorNotify indicatorNotify;
private ReentrantLock initLock;
public AlarmEntrance(ModuleManager moduleManager) {
this.moduleManager = moduleManager;
this.initLock = new ReentrantLock();
}
public void forward(Indicator indicator) {
......@@ -50,63 +39,12 @@ public class AlarmEntrance {
init();
IndicatorMetaInfo indicatorMetaInfo = ((WithMetadata)indicator).getMeta();
MetaInAlarm metaInAlarm;
switch (indicatorMetaInfo.getScope()) {
case SERVICE:
int serviceId = Integer.parseInt(indicatorMetaInfo.getId());
ServiceInventory serviceInventory = serviceInventoryCache.get(serviceId);
ServiceMetaInAlarm serviceMetaInAlarm = new ServiceMetaInAlarm();
serviceMetaInAlarm.setIndicatorName(indicatorMetaInfo.getIndicatorName());
serviceMetaInAlarm.setId(serviceId);
serviceMetaInAlarm.setName(serviceInventory.getName());
metaInAlarm = serviceMetaInAlarm;
break;
case SERVICE_INSTANCE:
int serviceInstanceId = Integer.parseInt(indicatorMetaInfo.getId());
ServiceInstanceInventory serviceInstanceInventory = serviceInstanceInventoryCache.get(serviceInstanceId);
ServiceInstanceMetaInAlarm instanceMetaInAlarm = new ServiceInstanceMetaInAlarm();
instanceMetaInAlarm.setIndicatorName(indicatorMetaInfo.getIndicatorName());
instanceMetaInAlarm.setId(serviceInstanceId);
instanceMetaInAlarm.setName(serviceInstanceInventory.getName());
metaInAlarm = instanceMetaInAlarm;
break;
case ENDPOINT:
int endpointId = Integer.parseInt(indicatorMetaInfo.getId());
EndpointInventory endpointInventory = endpointInventoryCache.get(endpointId);
EndpointMetaInAlarm endpointMetaInAlarm = new EndpointMetaInAlarm();
endpointMetaInAlarm.setIndicatorName(indicatorMetaInfo.getIndicatorName());
endpointMetaInAlarm.setId(endpointId);
serviceId = endpointInventory.getServiceId();
serviceInventory = serviceInventoryCache.get(serviceId);
String textName = endpointInventory.getName() + " in " + serviceInventory.getName();
endpointMetaInAlarm.setName(textName);
metaInAlarm = endpointMetaInAlarm;
break;
default:
return;
}
indicatorNotify.notify(metaInAlarm, indicator);
indicatorNotify.notify(indicator);
}
private void init() {
if (serviceInventoryCache == null) {
initLock.lock();
try {
if (serviceInventoryCache == null) {
serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class);
endpointInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(EndpointInventoryCache.class);
indicatorNotify = moduleManager.find(AlarmModule.NAME).provider().getService(IndicatorNotify.class);
}
} finally {
initLock.unlock();
}
if (indicatorNotify == null) {
indicatorNotify = moduleManager.find(AlarmModule.NAME).provider().getService(IndicatorNotify.class);
}
}
}
......@@ -32,5 +32,5 @@ import org.apache.skywalking.oap.server.library.module.Service;
* @author wusheng
*/
public interface IndicatorNotify extends Service {
void notify(MetaInAlarm indicatorName, Indicator indicator);
void notify(Indicator indicator);
}
......@@ -60,6 +60,17 @@ public class DefaultScopeDefine {
public static final int SERVICE_INSTANCE_CLR_THREAD = 21;
public static final int ENVOY_INSTANCE_METRIC = 22;
/**
* Catalog of scope, the indicator processor could use this to group all generated indicators by oal tool.
*/
public static final String SERVICE_CATALOG_NAME = "SERVICE";
public static final String SERVICE_INSTANCE_CATALOG_NAME = "SERVICE_INSTANCE";
public static final String ENDPOINT_CATALOG_NAME = "ENDPOINT";
private static final Map<Integer, Boolean> SERVICE_CATALOG = new HashMap<>();
private static final Map<Integer, Boolean> SERVICE_INSTANCE_CATALOG = new HashMap<>();
private static final Map<Integer, Boolean> ENDPOINT_CATALOG = new HashMap<>();
public static class Listener implements AnnotationListener {
@Override public Class<? extends Annotation> annotation() {
return ScopeDeclaration.class;
......@@ -84,6 +95,19 @@ public class DefaultScopeDefine {
}
ID_2_NAME.put(id, name);
NAME_2_ID.put(name, id);
String catalogName = declaration.catalog();
switch (catalogName) {
case SERVICE_CATALOG_NAME:
SERVICE_CATALOG.put(id, Boolean.TRUE);
break;
case SERVICE_INSTANCE_CATALOG_NAME:
SERVICE_INSTANCE_CATALOG.put(id, Boolean.TRUE);
break;
case ENDPOINT_CATALOG_NAME:
ENDPOINT_CATALOG.put(id, Boolean.TRUE);
break;
}
}
public static String nameOf(int id) {
......@@ -106,4 +130,16 @@ public class DefaultScopeDefine {
NAME_2_ID.clear();
ID_2_NAME.clear();
}
public static boolean inServiceCatalog(int scopeId) {
return SERVICE_CATALOG.containsKey(scopeId);
}
public static boolean inServiceInstanceCatalog(int scopeId) {
return SERVICE_INSTANCE_CATALOG.containsKey(scopeId);
}
public static boolean inEndpointCatalog(int scopeId) {
return ENDPOINT_CATALOG.containsKey(scopeId);
}
}
......@@ -21,11 +21,12 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENDPOINT;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENDPOINT_CATALOG_NAME;
/**
* @author peng-yongsheng
*/
@ScopeDeclaration(id = ENDPOINT, name = "Endpoint")
@ScopeDeclaration(id = ENDPOINT, name = "Endpoint", catalog = ENDPOINT_CATALOG_NAME)
public class Endpoint extends Source {
@Override public int scope() {
return DefaultScopeDefine.ENDPOINT;
......
......@@ -21,6 +21,7 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.ENVOY_INSTANCE_METRIC;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CATALOG_NAME;
/**
* The envoy metrics. This group of metrics are in Prometheus metric format family.
......@@ -29,7 +30,7 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.EN
*
* @author wusheng
*/
@ScopeDeclaration(id = ENVOY_INSTANCE_METRIC, name = "EnvoyInstanceMetric")
@ScopeDeclaration(id = ENVOY_INSTANCE_METRIC, name = "EnvoyInstanceMetric", catalog = SERVICE_INSTANCE_CATALOG_NAME)
public class EnvoyInstanceMetric extends Source {
@Override public int scope() {
return ENVOY_INSTANCE_METRIC;
......
......@@ -30,4 +30,5 @@ import java.lang.annotation.*;
public @interface ScopeDeclaration {
int id();
String name();
String catalog() default "";
}
......@@ -20,12 +20,12 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.*;
/**
* @author wusheng, peng-yongsheng
*/
@ScopeDeclaration(id = SERVICE, name = "Service")
@ScopeDeclaration(id = SERVICE, name = "Service", catalog = SERVICE_CATALOG_NAME)
public class Service extends Source {
@Override public int scope() {
return DefaultScopeDefine.SERVICE;
......
......@@ -21,11 +21,12 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CATALOG_NAME;
/**
* @author peng-yongsheng
*/
@ScopeDeclaration(id = SERVICE_INSTANCE, name = "ServiceInstance")
@ScopeDeclaration(id = SERVICE_INSTANCE, name = "ServiceInstance", catalog = SERVICE_INSTANCE_CATALOG_NAME)
public class ServiceInstance extends Source {
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE;
......
......@@ -21,12 +21,13 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.Getter;
import lombok.Setter;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CATALOG_NAME;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CLR_CPU;
/**
* @author liuhaoyang
**/
@ScopeDeclaration(id = SERVICE_INSTANCE_CLR_CPU, name = "ServiceInstanceCLRCPU")
@ScopeDeclaration(id = SERVICE_INSTANCE_CLR_CPU, name = "ServiceInstanceCLRCPU", catalog = SERVICE_INSTANCE_CATALOG_NAME)
public class ServiceInstanceCLRCPU extends Source {
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE_CLR_CPU;
......
......@@ -21,12 +21,13 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.Getter;
import lombok.Setter;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CATALOG_NAME;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CLR_GC;
/**
* @author liuhaoyang
**/
@ScopeDeclaration(id = SERVICE_INSTANCE_CLR_GC, name = "ServiceInstanceCLRGC")
@ScopeDeclaration(id = SERVICE_INSTANCE_CLR_GC, name = "ServiceInstanceCLRGC", catalog = SERVICE_INSTANCE_CATALOG_NAME)
public class ServiceInstanceCLRGC extends Source {
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE_CLR_GC;
......
......@@ -21,12 +21,13 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.Getter;
import lombok.Setter;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CATALOG_NAME;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CLR_THREAD;
/**
* @author liuhaoyang
**/
@ScopeDeclaration(id = SERVICE_INSTANCE_CLR_THREAD, name = "ServiceInstanceCLRThread")
@ScopeDeclaration(id = SERVICE_INSTANCE_CLR_THREAD, name = "ServiceInstanceCLRThread", catalog = SERVICE_INSTANCE_CATALOG_NAME)
public class ServiceInstanceCLRThread extends Source {
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE_CLR_THREAD;
......
......@@ -20,12 +20,13 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CATALOG_NAME;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_JVM_CPU;
/**
* @author peng-yongsheng
*/
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_CPU, name = "ServiceInstanceJVMCPU")
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_CPU, name = "ServiceInstanceJVMCPU", catalog = SERVICE_INSTANCE_CATALOG_NAME)
public class ServiceInstanceJVMCPU extends Source {
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE_JVM_CPU;
......
......@@ -20,12 +20,13 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CATALOG_NAME;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_JVM_GC;
/**
* @author peng-yongsheng
*/
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_GC, name = "ServiceInstanceJVMGC")
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_GC, name = "ServiceInstanceJVMGC", catalog = SERVICE_INSTANCE_CATALOG_NAME)
public class ServiceInstanceJVMGC extends Source {
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE_JVM_GC;
......
......@@ -20,12 +20,13 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CATALOG_NAME;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY;
/**
* @author peng-yongsheng
*/
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_MEMORY, name = "ServiceInstanceJVMMemory")
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_MEMORY, name = "ServiceInstanceJVMMemory", catalog = SERVICE_INSTANCE_CATALOG_NAME)
public class ServiceInstanceJVMMemory extends Source {
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY;
......
......@@ -20,12 +20,13 @@ package org.apache.skywalking.oap.server.core.source;
import lombok.*;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_CATALOG_NAME;
import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY_POOL;
/**
* @author peng-yongsheng
*/
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_MEMORY_POOL, name = "ServiceInstanceJVMMemoryPool")
@ScopeDeclaration(id = SERVICE_INSTANCE_JVM_MEMORY_POOL, name = "ServiceInstanceJVMMemoryPool", catalog = SERVICE_INSTANCE_CATALOG_NAME)
public class ServiceInstanceJVMMemoryPool extends Source {
@Override public int scope() {
return DefaultScopeDefine.SERVICE_INSTANCE_JVM_MEMORY_POOL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册