Skip to content

Commit

Permalink
feat : 엔드포인트URL 도메인 제외
Browse files Browse the repository at this point in the history
  • Loading branch information
JiwonKKang committed Nov 6, 2024
1 parent 40e1ea4 commit 8a5c783
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<EndPointUrl> getEndpoints(ServiceSearchCondition cond);
Set<EndPointUrl> getEndpoints(ServiceSearchCondition cond);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -43,7 +44,7 @@ public List<Node> getServiceNodeList(ProjectKey projectKey) {
return projectReader.readServiceNods(project);
}

public List<EndPointUrl> getServiceEndpoints(ServiceSearchCondition cond) {
public Set<EndPointUrl> getServiceEndpoints(ServiceSearchCondition cond) {
projectValidator.validate(cond.getProjectKey());
return projectAnalyzer.getEndpoints(cond);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,5 +34,5 @@ List<Span> findByProjectKeyAndSpanKind(

List<HttpTps> getHttpTps(TraceSearchCondition cond);

List<EndPointUrl> getEndpoints(ServiceSearchCondition cond);
Set<EndPointUrl> getEndpoints(ServiceSearchCondition cond);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -40,7 +40,7 @@ public ProjectStatistic<?> analyze(TraceSearchCondition cond, StatisticsType sta
}

@Override
public List<EndPointUrl> getEndpoints(ServiceSearchCondition cond) {
public Set<EndPointUrl> getEndpoints(ServiceSearchCondition cond) {
return spanRepository.getEndpoints(cond);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -94,7 +95,7 @@ public List<HttpTps> getHttpTps(TraceSearchCondition cond) {
}

@Override
public List<EndPointUrl> getEndpoints(ServiceSearchCondition cond) {
public Set<EndPointUrl> getEndpoints(ServiceSearchCondition cond) {
return spanElasticSearchRepository.getEndpointUrls(cond);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,5 +33,5 @@ SearchResult<Trace> searchTracesByNode(

List<HttpTps> getHttpTps(TraceSearchCondition cond);

List<EndPointUrl> getEndpointUrls(ServiceSearchCondition cond);
Set<EndPointUrl> getEndpointUrls(ServiceSearchCondition cond);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -212,7 +213,7 @@ public List<HttpTps> getHttpTps(TraceSearchCondition cond) {
}

@Override
public List<EndPointUrl> getEndpointUrls(ServiceSearchCondition cond) {
public Set<EndPointUrl> getEndpointUrls(ServiceSearchCondition cond) {
return executeESQuery(
() -> {
final SearchResponse<Void> response =
Expand All @@ -230,7 +231,7 @@ public List<EndPointUrl> getEndpointUrls(ServiceSearchCondition cond) {
});
}

private static List<EndPointUrl> parseEndpointUrls(SearchResponse<Void> response) {
private static Set<EndPointUrl> parseEndpointUrls(SearchResponse<Void> response) {
return response
.aggregations()
.get("nested_attributes")
Expand All @@ -242,7 +243,7 @@ private static List<EndPointUrl> parseEndpointUrls(SearchResponse<Void> response
.array()
.stream()
.map(bucket -> EndPointUrl.from(bucket.key().stringValue()))
.toList();
.collect(Collectors.toSet());
}

private static Aggregation endpointsAggregation() {
Expand Down Expand Up @@ -594,7 +595,7 @@ private static Query createSpanQuery(String projectKey, SpanType spanType, SpanK
r.field("startEpochMillis")
.gte(
JsonData.of(
"now-5m"))))))
"now-1m"))))))
._toQuery();
}

Expand Down

0 comments on commit 8a5c783

Please sign in to comment.