Skip to content

Commit

Permalink
Support query Alarm message Tag for auto-complete. (#12665)
Browse files Browse the repository at this point in the history
  • Loading branch information
wankai123 authored Sep 29, 2024
1 parent 22c9519 commit 21e0149
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/en/api/query-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ Trace query fetches trace segment lists and spans of given trace IDs.
extend type Query {
getAlarmTrend(duration: Duration!): AlarmTrend!
getAlarm(duration: Duration!, scope: Scope, keyword: String, paging: Pagination!, tags: [AlarmTag]): Alarms
# Read the list of searchable keys
queryAlarmTagAutocompleteKeys(duration: Duration!):[String!]
# Search the available value options of the given key.
queryAlarmTagAutocompleteValues(tagKey: String! , duration: Duration!):[String!]
}
```

Expand Down
1 change: 1 addition & 0 deletions docs/en/changes/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
* BanyanDB: use `TimestampRange` to improve "events" query for BanyanDB.
* Optimize `network_address_alias` table to reduce the number of the index.
* PromQL service: support round brackets operator.
* Support query Alarm message Tag for auto-complete.

#### UI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.Tag;
import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.TagType;
import org.apache.skywalking.oap.server.core.analysis.worker.RecordStreamProcessor;
import org.apache.skywalking.oap.server.core.config.ConfigService;
import org.apache.skywalking.oap.server.core.source.SourceReceiver;
import org.apache.skywalking.oap.server.core.source.TagAutocomplete;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -42,6 +45,7 @@ public class AlarmStandardPersistence implements AlarmCallback {
private static final Logger LOGGER = LoggerFactory.getLogger(AlarmStandardPersistence.class);
private final Gson gson = new Gson();
private final ModuleManager manager;
private SourceReceiver receiver;

public AlarmStandardPersistence(ModuleManager manager) {
this.manager = manager;
Expand All @@ -64,12 +68,20 @@ public void doAlarm(List<AlarmMessage> alarmMessage) {
record.setTimeBucket(TimeBucket.getRecordTimeBucket(message.getStartTime()));
record.setRuleName(message.getRuleName());
Collection<Tag> tags = appendSearchableTags(message.getTags());
addAutocompleteTags(tags, TimeBucket.getMinuteTimeBucket(message.getStartTime()));
record.setTagsRawData(gson.toJson(message.getTags()).getBytes(Charsets.UTF_8));
record.setTagsInString(Tag.Util.toStringList(new ArrayList<>(tags)));
RecordStreamProcessor.getInstance().in(record);
});
}

private SourceReceiver getReceiver() {
if (receiver == null) {
receiver = manager.find(CoreModule.NAME).provider().getService(SourceReceiver.class);
}
return receiver;
}

private Collection<Tag> appendSearchableTags(List<Tag> tags) {
final ConfigService configService = manager.find(CoreModule.NAME)
.provider()
Expand All @@ -90,4 +102,15 @@ private Collection<Tag> appendSearchableTags(List<Tag> tags) {
});
return alarmTags;
}

private void addAutocompleteTags(Collection<Tag> alarmTags, long minuteTimeBucket) {
alarmTags.forEach(tag -> {
TagAutocomplete tagAutocomplete = new TagAutocomplete();
tagAutocomplete.setTagKey(tag.getKey());
tagAutocomplete.setTagValue(tag.getValue());
tagAutocomplete.setTagType(TagType.ALARM);
tagAutocomplete.setTimeBucket(minuteTimeBucket);
getReceiver().receive(tagAutocomplete);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
public enum TagType {
TRACE,
LOG,
ZIPKIN
ZIPKIN,
ALARM
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
import java.util.List;
import java.util.Map;

import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.analysis.IDManager;
import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.Tag;
import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.TagType;
import org.apache.skywalking.oap.server.core.query.AlarmQueryService;
import org.apache.skywalking.oap.server.core.query.EventQueryService;
import org.apache.skywalking.oap.server.core.query.TagAutoCompleteQueryService;
import org.apache.skywalking.oap.server.core.query.enumeration.Scope;
import org.apache.skywalking.oap.server.core.query.input.Duration;
import org.apache.skywalking.oap.server.core.query.type.AlarmMessage;
Expand Down Expand Up @@ -59,6 +62,8 @@ public class AlarmQuery implements GraphQLQueryResolver {

private EventQueryService eventQueryService;

private TagAutoCompleteQueryService tagQueryService;

public AlarmQuery(ModuleManager moduleManager) {
this.moduleManager = moduleManager;
}
Expand All @@ -77,6 +82,13 @@ private EventQueryService getEventQueryService() {
return eventQueryService;
}

private TagAutoCompleteQueryService getTagQueryService() {
if (tagQueryService == null) {
this.tagQueryService = moduleManager.find(CoreModule.NAME).provider().getService(TagAutoCompleteQueryService.class);
}
return tagQueryService;
}

public AlarmTrend getAlarmTrend(final Duration duration) {
return new AlarmTrend();
}
Expand Down Expand Up @@ -108,6 +120,14 @@ public CompletableFuture<Alarms> getAlarm(final Duration duration, final Scope s
});
}

public CompletableFuture<Set<String>> queryAlarmTagAutocompleteKeys(final Duration queryDuration) {
return queryAsync(() -> getTagQueryService().queryTagAutocompleteKeys(TagType.ALARM, queryDuration));
}

public CompletableFuture<Set<String>> queryAlarmTagAutocompleteValues(final String tagKey, final Duration queryDuration) {
return queryAsync(() -> getTagQueryService().queryTagAutocompleteValues(TagType.ALARM, tagKey, queryDuration));
}

private Alarms findRelevantEvents(
final Alarms alarms,
final EventQueryCondition.EventQueryConditionBuilder conditionPrototype
Expand Down

0 comments on commit 21e0149

Please sign in to comment.