未验证 提交 7c192b19 编写于 作者: 彭勇升 pengys 提交者: GitHub

Alarm query and alarm persistence test. (#1753)

* Alarm query and alarm persistence test.

* Fixed the package error.
上级 3f8af95d
......@@ -18,26 +18,15 @@
package org.apache.skywalking.oap.server.core.alarm.provider;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
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.DoubleValueHolder;
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.alarm.*;
import org.apache.skywalking.oap.server.core.analysis.indicator.*;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.library.util.TimeBucketUtils;
import org.joda.time.LocalDateTime;
import org.joda.time.Minutes;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.joda.time.*;
import org.joda.time.format.*;
import org.slf4j.*;
/**
* RunningRule represents each rule in running status. Based on the {@link AlarmRule} definition,
......@@ -149,7 +138,7 @@ public class RunningRule {
alarmMessage.setId0(meta.getId0());
alarmMessage.setId1(meta.getId1());
alarmMessage.setAlarmMessage(formatter.format(meta));
alarmMessage.setTimeBucket(TimeBucketUtils.INSTANCE.getTime(LocalDateTime.now()));
alarmMessage.setStartTime(System.currentTimeMillis());
alarmMessageList.add(alarmMessage);
}
});
......
......@@ -62,6 +62,7 @@ public class CoreModule extends ModuleDefine {
classes.add(TraceQueryService.class);
classes.add(MetadataQueryService.class);
classes.add(AggregationQueryService.class);
classes.add(AlarmQueryService.class);
}
private void addServerInterface(List<Class> classes) {
......
......@@ -115,6 +115,7 @@ public class CoreModuleProvider extends ModuleProvider {
this.registerServiceImplementation(TraceQueryService.class, new TraceQueryService(getManager()));
this.registerServiceImplementation(MetadataQueryService.class, new MetadataQueryService(getManager()));
this.registerServiceImplementation(AggregationQueryService.class, new AggregationQueryService(getManager()));
this.registerServiceImplementation(AlarmQueryService.class, new AlarmQueryService(getManager()));
annotationScan.registerListener(storageAnnotationListener);
annotationScan.registerListener(streamAnnotationListener);
......
......@@ -37,7 +37,7 @@ public class AlarmMessage {
private int id0;
private int id1;
private String alarmMessage;
private long timeBucket;
private long startTime;
private static class NoAlarm extends AlarmMessage {
......
......@@ -36,11 +36,12 @@ import org.apache.skywalking.oap.server.core.storage.annotation.*;
public class AlarmRecord extends Record {
public static final String INDEX_NAME = "alarm_record";
private static final String SCOPE = "scope";
public static final String SCOPE = "scope";
private static final String NAME = "name";
private static final String ID0 = "id0";
private static final String ID1 = "id1";
private static final String ALARM_MESSAGE = "alarm_message";
private static final String START_TIME = "start_time";
public static final String ALARM_MESSAGE = "alarm_message";
@Override public String id() {
return getTimeBucket() + Const.ID_SPLIT + scope + Const.ID_SPLIT + id0 + Const.ID_SPLIT + id1;
......@@ -50,6 +51,7 @@ public class AlarmRecord extends Record {
@Column(columnName = NAME) private String name;
@Column(columnName = ID0) private int id0;
@Column(columnName = ID1) private int id1;
@Column(columnName = START_TIME) private long startTime;
@Column(columnName = ALARM_MESSAGE, matchQuery = true) private String alarmMessage;
public static class Builder implements StorageBuilder<AlarmRecord> {
......@@ -61,6 +63,7 @@ public class AlarmRecord extends Record {
map.put(ID0, storageData.getId0());
map.put(ID1, storageData.getId1());
map.put(ALARM_MESSAGE, storageData.getAlarmMessage());
map.put(START_TIME, storageData.getStartTime());
map.put(TIME_BUCKET, storageData.getTimeBucket());
return map;
}
......@@ -72,6 +75,7 @@ public class AlarmRecord extends Record {
record.setId0(((Number)dbMap.get(ID0)).intValue());
record.setId1(((Number)dbMap.get(ID1)).intValue());
record.setAlarmMessage((String)dbMap.get(ALARM_MESSAGE));
record.setStartTime(((Number)dbMap.get(START_TIME)).longValue());
record.setTimeBucket(((Number)dbMap.get(TIME_BUCKET)).longValue());
return record;
}
......
......@@ -20,6 +20,8 @@ package org.apache.skywalking.oap.server.core.alarm;
import java.util.List;
import org.apache.skywalking.oap.server.core.analysis.worker.RecordProcess;
import org.apache.skywalking.oap.server.library.util.TimeBucketUtils;
import org.slf4j.*;
/**
* Save the alarm info into storage for UI query.
......@@ -28,15 +30,22 @@ import org.apache.skywalking.oap.server.core.analysis.worker.RecordProcess;
*/
public class AlarmStandardPersistence implements AlarmCallback {
private static final Logger logger = LoggerFactory.getLogger(AlarmStandardPersistence.class);
@Override public void doAlarm(List<AlarmMessage> alarmMessage) {
alarmMessage.forEach(message -> {
if (logger.isDebugEnabled()) {
logger.debug("Alarm message: {}", message.getAlarmMessage());
}
AlarmRecord record = new AlarmRecord();
record.setScope(message.getScope().ordinal());
record.setId0(message.getId0());
record.setId1(message.getId1());
record.setName(message.getName());
record.setAlarmMessage(message.getAlarmMessage());
record.setTimeBucket(message.getTimeBucket());
record.setStartTime(message.getStartTime());
record.setTimeBucket(TimeBucketUtils.INSTANCE.getMinuteTimeBucket(message.getStartTime()));
RecordProcess.INSTANCE.in(record);
});
......
/*
* 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;
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.*;
import org.apache.skywalking.oap.server.library.module.Service;
import org.slf4j.*;
/**
* @author peng-yongsheng
*/
public class AlarmQueryService implements Service {
private static final Logger logger = LoggerFactory.getLogger(AlarmQueryService.class);
private final ModuleManager moduleManager;
private IAlarmQueryDAO alarmQueryDAO;
public AlarmQueryService(ModuleManager moduleManager) {
this.moduleManager = moduleManager;
}
private IAlarmQueryDAO getAlarmQueryDAO() {
if (alarmQueryDAO == null) {
alarmQueryDAO = moduleManager.find(StorageModule.NAME).getService(IAlarmQueryDAO.class);
}
return alarmQueryDAO;
}
public Alarms getAlarm(final Scope scope, 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);
}
}
......@@ -16,10 +16,16 @@
*
*/
package org.apache.skywalking.oap.query.graphql.type;
package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*;
import org.apache.skywalking.oap.server.core.source.Scope;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class AlarmMessage {
private Scope scope;
private String id;
......
......@@ -16,11 +16,20 @@
*
*/
package org.apache.skywalking.oap.query.graphql.type;
package org.apache.skywalking.oap.server.core.query.entity;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import lombok.Getter;
/**
* @author peng-yongsheng
*/
@Getter
public class AlarmTrend {
private List<Integer> numOfAlarm = new ArrayList<>();
private final List<Integer> numOfAlarm;
public AlarmTrend() {
this.numOfAlarm = new ArrayList<>();
}
}
......@@ -16,11 +16,21 @@
*
*/
package org.apache.skywalking.oap.query.graphql.type;
package org.apache.skywalking.oap.server.core.query.entity;
import java.util.List;
import java.util.*;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
public class Alarms {
private List<AlarmMessage> msgs;
private int total;
private final List<AlarmMessage> msgs;
@Setter private int total;
public Alarms() {
this.msgs = new ArrayList<>();
}
}
......@@ -18,6 +18,13 @@
package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class Attribute {
private String name;
private String value;
......
......@@ -21,13 +21,20 @@ package org.apache.skywalking.oap.server.core.query.entity;
import java.util.*;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class BasicTrace {
private String segmentId;
private List<String> endpointNames = new ArrayList<>();
private int duration;
private String start;
private boolean isError;
private List<String> traceIds = new ArrayList<>();
@Setter private String segmentId;
private final List<String> endpointNames;
@Setter private int duration;
@Setter private String start;
@Setter private boolean isError;
private final List<String> traceIds;
public BasicTrace() {
this.endpointNames = new ArrayList<>();
this.traceIds = new ArrayList<>();
}
}
......@@ -21,6 +21,9 @@ package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*;
import org.apache.skywalking.oap.server.core.source.DetectPoint;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class Call {
......
......@@ -20,6 +20,9 @@ package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class ClusterBrief {
......
......@@ -20,6 +20,9 @@ package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class Endpoint {
......
......@@ -21,6 +21,14 @@ package org.apache.skywalking.oap.server.core.query.entity;
import java.util.*;
import lombok.Getter;
/**
* @author peng-yongsheng
*/
public class IntValues {
@Getter private List<KVInt> values = new LinkedList<>();
@Getter private final List<KVInt> values;
public IntValues() {
this.values = new LinkedList<>();
}
}
......@@ -20,6 +20,9 @@ package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Setter
@Getter
public class KVInt {
......
......@@ -20,6 +20,9 @@ package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class KeyValue {
......
......@@ -18,6 +18,9 @@
package org.apache.skywalking.oap.server.core.query.entity;
/**
* @author peng-yongsheng
*/
public enum Language {
UNKNOWN,
JAVA,
......
......@@ -21,9 +21,15 @@ package org.apache.skywalking.oap.server.core.query.entity;
import java.util.*;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class LogEntity {
private long time;
private List<KeyValue> data = new ArrayList<>();
@Setter private long time;
private final List<KeyValue> data;
public LogEntity() {
this.data = new ArrayList<>();
}
}
......@@ -20,6 +20,9 @@ package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class Node {
......
......@@ -18,6 +18,9 @@
package org.apache.skywalking.oap.server.core.query.entity;
/**
* @author peng-yongsheng
*/
public enum Order {
ASC,
DES
......
......@@ -20,6 +20,9 @@ package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class Pagination {
......
......@@ -18,6 +18,9 @@
package org.apache.skywalking.oap.server.core.query.entity;
/**
* @author peng-yongsheng
*/
public enum QueryOrder {
BY_START_TIME,
BY_DURATION
......
......@@ -20,6 +20,9 @@ package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Setter
@Getter
public class Ref {
......
......@@ -18,6 +18,9 @@
package org.apache.skywalking.oap.server.core.query.entity;
/**
* @author peng-yongsheng
*/
public enum RefType {
CROSS_PROCESS,
CROSS_THREAD
......
......@@ -20,6 +20,9 @@ package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class Service {
......
......@@ -21,11 +21,17 @@ package org.apache.skywalking.oap.server.core.query.entity;
import java.util.*;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class ServiceInstance {
private String id;
private String name;
private List<Attribute> attributes = new ArrayList<>();
private Language language;
@Setter private String id;
@Setter private String name;
private final List<Attribute> attributes;
@Setter private Language language;
public ServiceInstance() {
this.attributes = new ArrayList<>();
}
}
......@@ -21,26 +21,34 @@ package org.apache.skywalking.oap.server.core.query.entity;
import java.util.*;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class Span {
private String traceId;
private String segmentId;
private int spanId;
private int parentSpanId;
private List<Ref> refs = new ArrayList<>();
private String serviceCode;
private long startTime;
private long endTime;
private String endpointName;
private String type;
private String peer;
private String component;
private boolean isError;
private String layer;
private List<KeyValue> tags = new ArrayList<>();
private List<LogEntity> logs = new ArrayList<>();
private boolean isRoot;
private String segmentSpanId;
private String segmentParentSpanId;
@Setter private String traceId;
@Setter private String segmentId;
@Setter private int spanId;
@Setter private int parentSpanId;
private final List<Ref> refs;
@Setter private String serviceCode;
@Setter private long startTime;
@Setter private long endTime;
@Setter private String endpointName;
@Setter private String type;
@Setter private String peer;
@Setter private String component;
@Setter private boolean isError;
@Setter private String layer;
private final List<KeyValue> tags;
private final List<LogEntity> logs;
@Setter private boolean isRoot;
@Setter private String segmentSpanId;
@Setter private String segmentParentSpanId;
public Span() {
this.refs = new ArrayList<>();
this.tags = new ArrayList<>();
this.logs = new ArrayList<>();
}
}
......@@ -18,6 +18,9 @@
package org.apache.skywalking.oap.server.core.query.entity;
/**
* @author peng-yongsheng
*/
public enum Step {
MONTH,
DAY,
......
......@@ -21,11 +21,17 @@ package org.apache.skywalking.oap.server.core.query.entity;
import java.util.*;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class Thermodynamic {
private List<List<Long>> nodes = new ArrayList<>();
private int axisYStep;
private final List<List<Long>> nodes;
@Setter private int axisYStep;
public Thermodynamic() {
this.nodes = new ArrayList<>();
}
public void setNodeValue(int columnNum, int rowNum, Long value) {
List<Long> element = new ArrayList<>(3);
......@@ -34,5 +40,4 @@ public class Thermodynamic {
element.add(value);
nodes.add(element);
}
}
\ No newline at end of file
......@@ -20,6 +20,9 @@ package org.apache.skywalking.oap.server.core.query.entity;
import lombok.*;
/**
* @author peng-yongsheng
*/
@Getter
@Setter
public class TopNEntity {
......
......@@ -21,8 +21,16 @@ package org.apache.skywalking.oap.server.core.query.entity;
import java.util.*;
import lombok.Getter;
/**
* @author peng-yongsheng
*/
@Getter
public class Topology {
private List<Node> nodes = new ArrayList<>();
private List<Call> calls = new ArrayList<>();
private final List<Node> nodes;
private final List<Call> calls;
public Topology() {
this.nodes = new ArrayList<>();
this.calls = new ArrayList<>();
}
}
......@@ -21,7 +21,14 @@ package org.apache.skywalking.oap.server.core.query.entity;
import java.util.*;
import lombok.Getter;
/**
* @author peng-yongsheng
*/
@Getter
public class Trace {
private List<Span> spans = new ArrayList<>();
private final List<Span> spans;
public Trace() {
this.spans = new ArrayList<>();
}
}
......@@ -21,9 +21,15 @@ package org.apache.skywalking.oap.server.core.query.entity;
import java.util.*;
import lombok.*;
@Setter
/**
* @author peng-yongsheng
*/
@Getter
public class TraceBrief {
private List<BasicTrace> traces = new ArrayList<>();
private int total;
private final List<BasicTrace> traces;
@Setter private int total;
public TraceBrief() {
this.traces = new ArrayList<>();
}
}
......@@ -18,6 +18,9 @@
package org.apache.skywalking.oap.server.core.query.entity;
/**
* @author peng-yongsheng
*/
public enum TraceState {
ALL,
SUCCESS,
......
......@@ -25,5 +25,12 @@ public enum Scope {
All, Service, ServiceInstance, Endpoint, ServiceRelation, ServiceInstanceRelation, EndpointRelation, NetworkAddress,
ServiceInstanceJVMCPU, ServiceInstanceJVMMemory, ServiceInstanceJVMMemoryPool, ServiceInstanceJVMGC,
ServiceComponent, ServiceMapping,
Segment
Segment;
public static Scope valueOf(int ordinal) {
if (ordinal < 0 || ordinal >= values().length) {
throw new IndexOutOfBoundsException("Invalid ordinal");
}
return values()[ordinal];
}
}
......@@ -38,6 +38,6 @@ public class StorageModule extends ModuleDefine {
IBatchDAO.class, StorageDAO.class, IRegisterLockDAO.class,
IServiceInventoryCacheDAO.class, IServiceInstanceInventoryCacheDAO.class,
IEndpointInventoryCacheDAO.class, INetworkAddressInventoryCacheDAO.class,
ITopologyQueryDAO.class, IMetricQueryDAO.class, ITraceQueryDAO.class, IMetadataQueryDAO.class, IAggregationQueryDAO.class};
ITopologyQueryDAO.class, IMetricQueryDAO.class, ITraceQueryDAO.class, IMetadataQueryDAO.class, IAggregationQueryDAO.class, IAlarmQueryDAO.class};
}
}
/*
* 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.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.storage.DAO;
/**
* @author peng-yongsheng
*/
public interface IAlarmQueryDAO extends DAO {
Alarms getAlarm(final Scope scope, final String keyword, final int limit, final int from, final long startTB,
final long endTB) throws IOException;
}
......@@ -65,7 +65,7 @@ public class GraphQLQueryProvider extends ModuleProvider {
.file("query-protocol/aggregation.graphqls")
.resolvers(new AggregationQuery(getManager()))
.file("query-protocol/alarm.graphqls")
.resolvers(new AlarmQuery())
.resolvers(new AlarmQuery(getManager()))
.build()
.makeExecutableSchema();
this.graphQL = GraphQL.newGraphQL(schema).build();
......
......@@ -27,6 +27,9 @@ import org.apache.skywalking.oap.server.core.query.*;
import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
/**
* @author peng-yongsheng
*/
public class AggregationQuery implements GraphQLQueryResolver {
private final ModuleManager moduleManager;
......
......@@ -19,16 +19,42 @@
package org.apache.skywalking.oap.query.graphql.resolver;
import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import org.apache.skywalking.oap.query.graphql.type.*;
import org.apache.skywalking.oap.server.core.query.entity.Pagination;
import java.io.IOException;
import org.apache.skywalking.oap.query.graphql.type.Duration;
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;
/**
* @author peng-yongsheng
*/
public class AlarmQuery implements GraphQLQueryResolver {
private final ModuleManager moduleManager;
private AlarmQueryService queryService;
public AlarmQuery(ModuleManager moduleManager) {
this.moduleManager = moduleManager;
}
private AlarmQueryService getQueryService() {
if (queryService == null) {
this.queryService = moduleManager.find(CoreModule.NAME).getService(AlarmQueryService.class);
}
return queryService;
}
public AlarmTrend getAlarmTrend(final Duration duration) {
return new AlarmTrend();
}
public Alarms getAlarm(final Duration duration, final Scope scope, final String keyword, final Pagination paging) {
return new Alarms();
public Alarms getAlarm(final Duration duration, final Scope scope, final String keyword,
final Pagination paging) throws IOException {
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
return getQueryService().getAlarm(scope, keyword, paging, startTimeBucket, endTimeBucket);
}
}
......@@ -28,6 +28,9 @@ import org.apache.skywalking.oap.server.core.query.*;
import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
/**
* @author peng-yongsheng
*/
public class MetadataQuery implements GraphQLQueryResolver {
private final ModuleManager moduleManager;
......
......@@ -27,6 +27,9 @@ import org.apache.skywalking.oap.server.core.query.*;
import org.apache.skywalking.oap.server.core.query.entity.*;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
/**
* @author peng-yongsheng
*/
public class MetricQuery implements GraphQLQueryResolver {
private final ModuleManager moduleManager;
......
......@@ -26,6 +26,9 @@ import org.apache.skywalking.oap.server.core.query.*;
import org.apache.skywalking.oap.server.core.query.entity.Topology;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
/**
* @author peng-yongsheng
*/
public class TopologyQuery implements GraphQLQueryResolver {
private final ModuleManager moduleManager;
......
......@@ -29,6 +29,9 @@ import org.apache.skywalking.oap.server.library.util.StringUtils;
import static java.util.Objects.nonNull;
/**
* @author peng-yongsheng
*/
public class TraceQuery implements GraphQLQueryResolver {
private final ModuleManager moduleManager;
......
......@@ -15,8 +15,8 @@
# limitations under the License.
# Sample alarm rules.
#rules:
# # Rule unique name, must be ended with `_rule`.
rules:
# Rule unique name, must be ended with `_rule`.
# endpoint_percent_rule:
# # Indicator value need to be long, double or int
# indicator-name: endpoint_percent
......@@ -29,16 +29,16 @@
# # How many times of checks, the alarm keeps silence after alarm triggered, default as same as period.
# silence-period: 10
# message: Successful rate of endpoint {name} is lower than 75%
# service_percent_rule:
# indicator-name: service_percent
# # [Optional] Default, match all services in this indicator
# include-names:
# - service_a
# - service_b
# threshold: 85
# op: <
# period: 10
# count: 4
service_resp_time_rule:
indicator-name: service_resp_time
# [Optional] Default, match all services in this indicator
include-names:
- dubbox-provider
- dubbox-consumer
threshold: 1000
op: ">"
period: 10
count: 1
#webhooks:
# - http://127.0.0.1/notify/
......
......@@ -32,6 +32,7 @@
<logger name="io.netty" level="INFO"/>
<logger name="org.apache.http" level="INFO"/>
<logger name="org.apache.skywalking.oap.server.receiver.istio.telemetry" level="DEBUG"/>
<logger name="org.apache.skywalking.oap.server.core.alarm.AlarmStandardPersistence" level="DEBUG"/>
<logger name="org.apache.skywalking.oap.server.core.remote" level="INFO"/>
<Root level="INFO">
<AppenderRef ref="Console"/>
......
......@@ -80,6 +80,7 @@ public class StorageModuleElasticsearchProvider extends ModuleProvider {
this.registerServiceImplementation(ITraceQueryDAO.class, new TraceQueryEsDAO(elasticSearchClient));
this.registerServiceImplementation(IMetadataQueryDAO.class, new MetadataQueryEsDAO(elasticSearchClient));
this.registerServiceImplementation(IAggregationQueryDAO.class, new AggregationQueryEsDAO(elasticSearchClient));
this.registerServiceImplementation(IAlarmQueryDAO.class, new AlarmQueryEsDAO(elasticSearchClient));
}
@Override
......
/*
* 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.storage.plugin.elasticsearch.query;
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.library.util.StringUtils;
import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.*;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.*;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
/**
* @author peng-yongsheng
*/
public class AlarmQueryEsDAO extends EsDAO implements IAlarmQueryDAO {
public AlarmQueryEsDAO(ElasticSearchClient client) {
super(client);
}
public Alarms getAlarm(final Scope scope, 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 (StringUtils.isNotEmpty(keyword)) {
String matchCName = MatchCNameBuilder.INSTANCE.build(AlarmRecord.ALARM_MESSAGE);
boolQueryBuilder.must().add(QueryBuilders.matchQuery(matchCName, keyword));
}
sourceBuilder.query(boolQueryBuilder);
sourceBuilder.size(limit);
sourceBuilder.from(from);
SearchResponse response = getClient().search(AlarmRecord.INDEX_NAME, sourceBuilder);
Alarms alarms = new Alarms();
alarms.setTotal((int)response.getHits().totalHits);
for (SearchHit searchHit : response.getHits().getHits()) {
AlarmRecord.Builder builder = new AlarmRecord.Builder();
AlarmRecord alarmRecord = builder.map2Data(searchHit.getSourceAsMap());
AlarmMessage message = new AlarmMessage();
message.setId(String.valueOf(alarmRecord.getId0()));
message.setMessage(alarmRecord.getAlarmMessage());
message.setStartTime(alarmRecord.getStartTime());
message.setScope(Scope.valueOf(alarmRecord.getScope()));
alarms.getMsgs().add(message);
}
return alarms;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册