Skip to content

Commit

Permalink
feat : 임시 이상치 탐지 객체 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
JiwonKKang committed Oct 28, 2024
1 parent 3701670 commit 0c45b99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ public class AnomalyDetector implements AnomalyDetectionClient {

@Override
public AnomalyTraceResult detect(List<Span> traceSpans) {

List<Span> anomalySpans =
traceSpans.stream().filter(span -> span.getTiming().duration() > 1000).toList();

boolean isAnomaly = !anomalySpans.isEmpty();

return new AnomalyTraceResult(
true,
"1206887328-a7863a66-528e-4f37-b805-04e1314fb924",
traceSpans.stream().map(span -> span.getId().getValue()).toList());
isAnomaly,
traceSpans.stream()
.map(Span::getProjectKey)
.findAny()
.orElse("1206887328-a7863a66-528e-4f37-b805-04e1314fb924"),
anomalySpans.stream().map(span -> span.getId().getValue()).toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ void process(KStream<TraceId, SpanCollectedEvent> stream) {
JsonSerde<List<Span>> listOfSpanSerde = new JsonSerde<>(new TypeReference<>() {});

// Stream processor - SpanCollectedEvent를 받아서 TraceId로 그루핑한뒤 각 TraceId에 대한 Span들을 List로 묶어서
// KTable로 만듦
KStream<TraceId, Span> spanStream =
stream.flatMap(
(key, value) -> {
Expand All @@ -57,6 +56,7 @@ void process(KStream<TraceId, SpanCollectedEvent> stream) {
TimeWindows timeWindows =
TimeWindows.ofSizeAndGrace(Duration.ofMinutes(1), Duration.ofSeconds(30));

// KTable로 만듦
KTable<Windowed<TraceId>, List<Span>> traceTable =
spanStream
.groupByKey()
Expand Down

0 comments on commit 0c45b99

Please sign in to comment.