Makes the scope of alarm message more semantic. (#3680)
* Makes the scope of alarm information more semantic. * update md. * update md. * add ruleName in AlarmMsg. * update md. * update test case. * fix coveralls. * fix coveralls. * fix ci.
This commit is contained in:
parent
26b1d4156a
commit
2f3d009e63
|
|
@ -65,10 +65,11 @@ Submit issue or pull request if you want to support any other scope in alarm.
|
|||
|
||||
## Webhook
|
||||
Webhook requires the peer is a web container. The alarm message will send through HTTP post by `application/json` content type. The JSON format is based on `List<org.apache.skywalking.oap.server.core.alarm.AlarmMessage` with following key information.
|
||||
- **scopeId**. All scopes are defined in org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.
|
||||
- **scopeId**, **scope**. All scopes are defined in org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.
|
||||
- **name**. Target scope entity name.
|
||||
- **id0**. The ID of scope entity, matched the name.
|
||||
- **id1**. Not used today.
|
||||
- **ruleName**. The rule name you configured in `alarm-settings.yml`.
|
||||
- **alarmMessage**. Alarm text message.
|
||||
- **startTime**. Alarm time measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
|
||||
|
||||
|
|
@ -76,16 +77,20 @@ Example as following
|
|||
```json
|
||||
[{
|
||||
"scopeId": 1,
|
||||
"scope": "SERVICE",
|
||||
"name": "serviceA",
|
||||
"id0": 12,
|
||||
"id1": 0,
|
||||
"ruleName": "service_resp_time_rule",
|
||||
"alarmMessage": "alarmMessage xxxx",
|
||||
"startTime": 1560524171000
|
||||
}, {
|
||||
"scopeId": 1,
|
||||
"scope": "SERVICE",
|
||||
"name": "serviceB",
|
||||
"id0": 23,
|
||||
"id1": 0,
|
||||
"ruleName": "service_resp_time_rule",
|
||||
"alarmMessage": "alarmMessage yyy",
|
||||
"startTime": 1560524171000
|
||||
}]
|
||||
|
|
|
|||
|
|
@ -148,9 +148,11 @@ public class RunningRule {
|
|||
AlarmMessage alarmMessage = window.checkAlarm();
|
||||
if (alarmMessage != AlarmMessage.NONE) {
|
||||
alarmMessage.setScopeId(meta.getScopeId());
|
||||
alarmMessage.setScope(meta.getScope());
|
||||
alarmMessage.setName(meta.getName());
|
||||
alarmMessage.setId0(meta.getId0());
|
||||
alarmMessage.setId1(meta.getId1());
|
||||
alarmMessage.setRuleName(this.ruleName);
|
||||
alarmMessage.setAlarmMessage(formatter.format(meta));
|
||||
alarmMessage.setStartTime(System.currentTimeMillis());
|
||||
alarmMessageList.add(alarmMessage);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@ public class AlarmMessageFormatterTest {
|
|||
AlarmMessageFormatter formatter = new AlarmMessageFormatter("abc words {sdf");
|
||||
String message = formatter.format(new MetaInAlarm() {
|
||||
|
||||
@Override public String getScope() {
|
||||
return "SERVICE";
|
||||
}
|
||||
|
||||
@Override public int getScopeId() {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -56,6 +60,10 @@ public class AlarmMessageFormatterTest {
|
|||
AlarmMessageFormatter formatter = new AlarmMessageFormatter("abc} words {name} - {id} .. {");
|
||||
String message = formatter.format(new MetaInAlarm() {
|
||||
|
||||
@Override public String getScope() {
|
||||
return "SERVICE";
|
||||
}
|
||||
|
||||
@Override public int getScopeId() {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ public class NotifyHandlerTest {
|
|||
|
||||
assertTrue(metaInAlarm instanceof EndpointMetaInAlarm);
|
||||
assertEquals(mockId, metaInAlarm.getId0());
|
||||
assertEquals(DefaultScopeDefine.ENDPOINT_CATALOG_NAME, metaInAlarm.getScope());
|
||||
assertEquals(metricsName, metaInAlarm.getMetricsName());
|
||||
assertEquals(endpointInventoryName + " in " + serviceInventoryName, metaInAlarm.getName());
|
||||
assertEquals(DefaultScopeDefine.ENDPOINT, metaInAlarm.getScopeId());
|
||||
|
|
@ -129,6 +130,7 @@ public class NotifyHandlerTest {
|
|||
assertTrue(metaInAlarm instanceof ServiceInstanceMetaInAlarm);
|
||||
assertEquals(metricsName, metaInAlarm.getMetricsName());
|
||||
assertEquals(mockId, metaInAlarm.getId0());
|
||||
assertEquals(DefaultScopeDefine.SERVICE_INSTANCE_CATALOG_NAME, metaInAlarm.getScope());
|
||||
assertEquals(instanceInventoryName, metaInAlarm.getName());
|
||||
assertEquals(DefaultScopeDefine.SERVICE_INSTANCE, metaInAlarm.getScopeId());
|
||||
}
|
||||
|
|
@ -157,6 +159,7 @@ public class NotifyHandlerTest {
|
|||
assertTrue(metaInAlarm instanceof ServiceMetaInAlarm);
|
||||
assertEquals(metricsName, metaInAlarm.getMetricsName());
|
||||
assertEquals(mockId, metaInAlarm.getId0());
|
||||
assertEquals(DefaultScopeDefine.SERVICE_CATALOG_NAME, metaInAlarm.getScope());
|
||||
assertEquals(serviceInventoryName, metaInAlarm.getName());
|
||||
assertEquals(DefaultScopeDefine.SERVICE, metaInAlarm.getScopeId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,6 +183,10 @@ public class RunningRuleTest {
|
|||
|
||||
private MetaInAlarm getMetaInAlarm(int id) {
|
||||
return new MetaInAlarm() {
|
||||
@Override public String getScope() {
|
||||
return "SERVICE";
|
||||
}
|
||||
|
||||
@Override public int getScopeId() {
|
||||
return DefaultScopeDefine.SERVICE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,9 +87,11 @@ public class WebhookCallbackTest implements Servlet {
|
|||
List<AlarmMessage> alarmMessages = new ArrayList<>(2);
|
||||
AlarmMessage alarmMessage = new AlarmMessage();
|
||||
alarmMessage.setScopeId(DefaultScopeDefine.ALL);
|
||||
alarmMessage.setRuleName("service_resp_time_rule");
|
||||
alarmMessage.setAlarmMessage("alarmMessage with [DefaultScopeDefine.All]");
|
||||
alarmMessages.add(alarmMessage);
|
||||
AlarmMessage anotherAlarmMessage = new AlarmMessage();
|
||||
anotherAlarmMessage.setRuleName("service_resp_time_rule_2");
|
||||
anotherAlarmMessage.setScopeId(DefaultScopeDefine.ENDPOINT);
|
||||
anotherAlarmMessage.setAlarmMessage("anotherAlarmMessage with [DefaultScopeDefine.Endpoint]");
|
||||
alarmMessages.add(anotherAlarmMessage);
|
||||
|
|
|
|||
|
|
@ -32,9 +32,11 @@ public class AlarmMessage {
|
|||
public static AlarmMessage NONE = new NoAlarm();
|
||||
|
||||
private int scopeId;
|
||||
private String scope;
|
||||
private String name;
|
||||
private int id0;
|
||||
private int id1;
|
||||
private String ruleName;
|
||||
private String alarmMessage;
|
||||
private long startTime;
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ public class EndpointMetaInAlarm extends MetaInAlarm {
|
|||
private String[] tags;
|
||||
private String[] properties;
|
||||
|
||||
@Override public String getScope() {
|
||||
return DefaultScopeDefine.ENDPOINT_CATALOG_NAME;
|
||||
}
|
||||
|
||||
@Override public int getScopeId() {
|
||||
return DefaultScopeDefine.ENDPOINT;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ package org.apache.skywalking.oap.server.core.alarm;
|
|||
import java.util.Objects;
|
||||
|
||||
public abstract class MetaInAlarm {
|
||||
|
||||
public abstract String getScope();
|
||||
|
||||
public abstract int getScopeId();
|
||||
|
||||
public abstract String getName();
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ public class ServiceInstanceMetaInAlarm extends MetaInAlarm {
|
|||
private String[] tags;
|
||||
private String[] properties;
|
||||
|
||||
@Override public String getScope() {
|
||||
return DefaultScopeDefine.SERVICE_INSTANCE_CATALOG_NAME;
|
||||
}
|
||||
|
||||
@Override public int getScopeId() {
|
||||
return DefaultScopeDefine.SERVICE_INSTANCE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ public class ServiceMetaInAlarm extends MetaInAlarm {
|
|||
private String[] tags;
|
||||
private String[] properties;
|
||||
|
||||
@Override public String getScope() {
|
||||
return DefaultScopeDefine.SERVICE_CATALOG_NAME;
|
||||
}
|
||||
|
||||
@Override public int getScopeId() {
|
||||
return DefaultScopeDefine.SERVICE;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue