From 8a5c78335a760f2230cab2379490d799c6d2e37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=A7=80=EC=9B=90?= Date: Thu, 7 Nov 2024 02:19:30 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=97=94=EB=93=9C=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8URL=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tracedin/domain/project/EndPointUrl.java | 19 ++++++++++++++++--- .../domain/project/ProjectAnalyzer.java | 4 ++-- .../domain/project/ProjectService.java | 3 ++- .../tracedin/domain/span/SpanRepository.java | 3 ++- .../domain/span/SpanStatisticsAnalyzer.java | 4 ++-- .../span/repository/SpanCoreRepository.java | 3 ++- .../SpanElasticSearchRepositoryCustom.java | 3 ++- ...SpanElasticSearchRepositoryCustomImpl.java | 9 +++++---- 8 files changed, 33 insertions(+), 15 deletions(-) diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/EndPointUrl.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/EndPointUrl.java index 8e6fcd5..f79d7e9 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/EndPointUrl.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/EndPointUrl.java @@ -1,16 +1,29 @@ package com.univ.tracedin.domain.project; +import java.util.regex.Matcher; import java.util.regex.Pattern; public record EndPointUrl(String value) { private static final Pattern ENDPOINT_PATTERN = - Pattern.compile("^(https?://)([a-zA-Z0-9.-]+)(:[0-9]+)?(/[a-zA-Z0-9._-]+)*$"); + Pattern.compile("^(?:https?://)?(?:[a-zA-Z0-9.-]+)(?::[0-9]+)?(/.*)"); public static EndPointUrl from(String url) { - if (url == null || !ENDPOINT_PATTERN.matcher(url).matches()) { + if (url == null || !isValidUrl(url)) { throw new IllegalArgumentException("Invalid endpoint URL format: " + url); } - return new EndPointUrl(url); + return new EndPointUrl(extractEndpoint(url)); + } + + private static boolean isValidUrl(String url) { + return ENDPOINT_PATTERN.matcher(url).find(); + } + + private static String extractEndpoint(String url) { + final Matcher matcher = ENDPOINT_PATTERN.matcher(url); + if (matcher.find()) { + return matcher.group(1); + } + throw new IllegalArgumentException("Unable to extract endpoint from URL: " + url); } } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectAnalyzer.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectAnalyzer.java index 70c6782..4ed84d0 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectAnalyzer.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectAnalyzer.java @@ -1,11 +1,11 @@ package com.univ.tracedin.domain.project; -import java.util.List; +import java.util.Set; public interface ProjectAnalyzer { ProjectStatistic analyze( TraceSearchCondition cond, ProjectStatistic.StatisticsType statisticsType); - List getEndpoints(ServiceSearchCondition cond); + Set getEndpoints(ServiceSearchCondition cond); } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectService.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectService.java index 5ac7cb7..21c87f9 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectService.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/project/ProjectService.java @@ -5,6 +5,7 @@ import static com.univ.tracedin.domain.project.ProjectStatistic.*; import java.util.List; +import java.util.Set; import org.springframework.stereotype.Service; @@ -43,7 +44,7 @@ public List getServiceNodeList(ProjectKey projectKey) { return projectReader.readServiceNods(project); } - public List getServiceEndpoints(ServiceSearchCondition cond) { + public Set getServiceEndpoints(ServiceSearchCondition cond) { projectValidator.validate(cond.getProjectKey()); return projectAnalyzer.getEndpoints(cond); } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanRepository.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanRepository.java index 797873a..10a042c 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanRepository.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanRepository.java @@ -1,6 +1,7 @@ package com.univ.tracedin.domain.span; import java.util.List; +import java.util.Set; import com.univ.tracedin.common.dto.SearchCursor; import com.univ.tracedin.common.dto.SearchResult; @@ -33,5 +34,5 @@ List findByProjectKeyAndSpanKind( List getHttpTps(TraceSearchCondition cond); - List getEndpoints(ServiceSearchCondition cond); + Set getEndpoints(ServiceSearchCondition cond); } diff --git a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanStatisticsAnalyzer.java b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanStatisticsAnalyzer.java index 92b692b..6a22195 100644 --- a/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanStatisticsAnalyzer.java +++ b/tracedin-domain/src/main/java/com/univ/tracedin/domain/span/SpanStatisticsAnalyzer.java @@ -1,6 +1,6 @@ package com.univ.tracedin.domain.span; -import java.util.List; +import java.util.Set; import java.util.concurrent.CompletableFuture; import org.springframework.stereotype.Component; @@ -40,7 +40,7 @@ public ProjectStatistic analyze(TraceSearchCondition cond, StatisticsType sta } @Override - public List getEndpoints(ServiceSearchCondition cond) { + public Set getEndpoints(ServiceSearchCondition cond) { return spanRepository.getEndpoints(cond); } diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/repository/SpanCoreRepository.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/repository/SpanCoreRepository.java index 9aede08..8358f30 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/repository/SpanCoreRepository.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/repository/SpanCoreRepository.java @@ -1,6 +1,7 @@ package com.univ.tracedin.infra.span.repository; import java.util.List; +import java.util.Set; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -94,7 +95,7 @@ public List getHttpTps(TraceSearchCondition cond) { } @Override - public List getEndpoints(ServiceSearchCondition cond) { + public Set getEndpoints(ServiceSearchCondition cond) { return spanElasticSearchRepository.getEndpointUrls(cond); } } diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/repository/SpanElasticSearchRepositoryCustom.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/repository/SpanElasticSearchRepositoryCustom.java index 815f27c..ab7c08b 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/repository/SpanElasticSearchRepositoryCustom.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/repository/SpanElasticSearchRepositoryCustom.java @@ -2,6 +2,7 @@ import java.util.List; import java.util.Map; +import java.util.Set; import com.univ.tracedin.common.dto.SearchResult; import com.univ.tracedin.domain.project.EndPointUrl; @@ -32,5 +33,5 @@ SearchResult searchTracesByNode( List getHttpTps(TraceSearchCondition cond); - List getEndpointUrls(ServiceSearchCondition cond); + Set getEndpointUrls(ServiceSearchCondition cond); } diff --git a/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/repository/SpanElasticSearchRepositoryCustomImpl.java b/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/repository/SpanElasticSearchRepositoryCustomImpl.java index c0b4447..4c3791f 100644 --- a/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/repository/SpanElasticSearchRepositoryCustomImpl.java +++ b/tracedin-infra/src/main/java/com/univ/tracedin/infra/span/repository/SpanElasticSearchRepositoryCustomImpl.java @@ -6,6 +6,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import jakarta.json.JsonObject; @@ -212,7 +213,7 @@ public List getHttpTps(TraceSearchCondition cond) { } @Override - public List getEndpointUrls(ServiceSearchCondition cond) { + public Set getEndpointUrls(ServiceSearchCondition cond) { return executeESQuery( () -> { final SearchResponse response = @@ -230,7 +231,7 @@ public List getEndpointUrls(ServiceSearchCondition cond) { }); } - private static List parseEndpointUrls(SearchResponse response) { + private static Set parseEndpointUrls(SearchResponse response) { return response .aggregations() .get("nested_attributes") @@ -242,7 +243,7 @@ private static List parseEndpointUrls(SearchResponse response .array() .stream() .map(bucket -> EndPointUrl.from(bucket.key().stringValue())) - .toList(); + .collect(Collectors.toSet()); } private static Aggregation endpointsAggregation() { @@ -594,7 +595,7 @@ private static Query createSpanQuery(String projectKey, SpanType spanType, SpanK r.field("startEpochMillis") .gte( JsonData.of( - "now-5m")))))) + "now-1m")))))) ._toQuery(); }