-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 5시간 이내의 HTTP 요청 10분 별로 집계 - 메트릭 데이터 수집 및 저장
- Loading branch information
1 parent
fa4f47b
commit 85a6d2d
Showing
30 changed files
with
625 additions
and
27 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...din-application/app-api/src/main/java/com/univ/tracedin/api/metric/ServiceMetricsApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.univ.tracedin.api.metric; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import com.univ.tracedin.api.global.dto.Response; | ||
import com.univ.tracedin.api.metric.dto.AppendServiceMetricsRequest; | ||
import com.univ.tracedin.api.metric.dto.HttpRequestCountResponse; | ||
import com.univ.tracedin.domain.metric.ServiceMetricsService; | ||
import com.univ.tracedin.domain.project.ServiceNode; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/metrics") | ||
@RequiredArgsConstructor | ||
public class ServiceMetricsApi implements ServiceMetricsApiDocs { | ||
|
||
private final ServiceMetricsService serviceMetricService; | ||
|
||
@PostMapping | ||
public void appendMetrics(@RequestBody AppendServiceMetricsRequest requests) { | ||
serviceMetricService.appendMetrics(requests.toDomain()); | ||
} | ||
|
||
@GetMapping("/http-request-count") | ||
public Response<List<HttpRequestCountResponse>> getHttpRequestCount(ServiceNode serviceNode) { | ||
List<HttpRequestCountResponse> responses = | ||
serviceMetricService.getHttpRequestCount(serviceNode).stream() | ||
.map(HttpRequestCountResponse::from) | ||
.toList(); | ||
return Response.success(responses); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...application/app-api/src/main/java/com/univ/tracedin/api/metric/ServiceMetricsApiDocs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.univ.tracedin.api.metric; | ||
|
||
import java.util.List; | ||
|
||
import com.univ.tracedin.api.global.dto.Response; | ||
import com.univ.tracedin.api.metric.dto.AppendServiceMetricsRequest; | ||
import com.univ.tracedin.api.metric.dto.HttpRequestCountResponse; | ||
import com.univ.tracedin.domain.project.ServiceNode; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
@Tag(name = "메트릭 API") | ||
public interface ServiceMetricsApiDocs { | ||
|
||
@Operation(summary = "메트릭 추가(라이브러리 전용)") | ||
void appendMetrics(AppendServiceMetricsRequest requests); | ||
|
||
@Operation( | ||
summary = "5시간 이내의 10분 별로 HTTP 요청 횟수 조회", | ||
description = "5시간 이내의 10분 별로 HTTP 요청 횟수 조회, 개발 기간에는 5시간 이내 조건 없음") | ||
Response<List<HttpRequestCountResponse>> getHttpRequestCount(ServiceNode serviceNode); | ||
} |
50 changes: 50 additions & 0 deletions
50
...n/app-api/src/main/java/com/univ/tracedin/api/metric/dto/AppendServiceMetricsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.univ.tracedin.api.metric.dto; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.univ.tracedin.domain.metric.Metric; | ||
import com.univ.tracedin.domain.metric.MetricType; | ||
import com.univ.tracedin.domain.metric.ServiceMetrics; | ||
|
||
public record AppendServiceMetricsRequest( | ||
String projectKey, String serviceName, List<MetricRequest> metrics) { | ||
|
||
public record MetricRequest( | ||
String name, | ||
String description, | ||
String unit, | ||
String type, | ||
Double value, | ||
Long count, | ||
Double sum, | ||
Double min, | ||
Double max, | ||
Map<String, Object> attributes) { | ||
|
||
public Metric toDomain() { | ||
return Metric.builder() | ||
.name(name) | ||
.description(description) | ||
.unit(unit) | ||
.type(MetricType.valueOf(type)) | ||
.value(value) | ||
.count(count) | ||
.sum(sum) | ||
.min(min) | ||
.max(max) | ||
.attributes(attributes) | ||
.timestamp(LocalDateTime.now()) | ||
.build(); | ||
} | ||
} | ||
|
||
public ServiceMetrics toDomain() { | ||
return ServiceMetrics.builder() | ||
.projectKey(projectKey) | ||
.serviceName(serviceName) | ||
.metrics(metrics.stream().map(MetricRequest::toDomain).toList()) | ||
.build(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...tion/app-api/src/main/java/com/univ/tracedin/api/metric/dto/HttpRequestCountResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.univ.tracedin.api.metric.dto; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import com.univ.tracedin.domain.metric.HttpRequestCount; | ||
|
||
public record HttpRequestCountResponse(LocalDateTime timestamp, Long httpRequestCount) { | ||
|
||
public static HttpRequestCountResponse from(HttpRequestCount httpRequestCount) { | ||
return new HttpRequestCountResponse( | ||
httpRequestCount.timestamp(), httpRequestCount.httpRequestCount()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/HttpRequestCount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.univ.tracedin.domain.metric; | ||
|
||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
|
||
public record HttpRequestCount(LocalDateTime timestamp, Long httpRequestCount) { | ||
|
||
public static HttpRequestCount of(long endEpochMillis, Long httpRequestCount) { | ||
LocalDateTime timestamp = | ||
LocalDateTime.ofInstant( | ||
Instant.ofEpochMilli(endEpochMillis), ZoneId.systemDefault()); | ||
return new HttpRequestCount(timestamp, httpRequestCount); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/Metric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.univ.tracedin.domain.metric; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Map; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class Metric { | ||
|
||
private String name; | ||
private String description; | ||
private String unit; | ||
private MetricType type; | ||
private Double value; | ||
private Long count; | ||
private Double sum; | ||
private Double min; | ||
private Double max; | ||
private Map<String, Object> attributes; | ||
private LocalDateTime timestamp; | ||
} |
20 changes: 20 additions & 0 deletions
20
tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/MetricType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.univ.tracedin.domain.metric; | ||
|
||
public enum MetricType { | ||
LONG_GAUGE, | ||
DOUBLE_GAUGE, | ||
LONG_SUM, | ||
DOUBLE_SUM, | ||
SUMMARY, | ||
HISTOGRAM, | ||
EXPONENTIAL_HISTOGRAM; | ||
|
||
public static MetricType fromValue(String value) { | ||
for (MetricType type : MetricType.values()) { | ||
if (type.name().equalsIgnoreCase(value)) { | ||
return type; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown MetricType: " + value); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.univ.tracedin.domain.metric; | ||
|
||
import java.util.List; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class ServiceMetrics { | ||
|
||
private String projectKey; | ||
private String serviceName; | ||
List<Metric> metrics; | ||
} |
16 changes: 16 additions & 0 deletions
16
tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsAppender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.univ.tracedin.domain.metric; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ServiceMetricsAppender { | ||
|
||
private final ServiceMetricsRepository serviceMetricsRepository; | ||
|
||
public void append(ServiceMetrics metrics) { | ||
serviceMetricsRepository.save(metrics); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.univ.tracedin.domain.metric; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import com.univ.tracedin.domain.project.ServiceNode; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ServiceMetricsReader { | ||
|
||
private final ServiceMetricsRepository serviceMetricsRepository; | ||
|
||
public List<HttpRequestCount> readHttpRequestCount(ServiceNode serviceNode) { | ||
return serviceMetricsRepository.getHttpRequestCount(serviceNode); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.univ.tracedin.domain.metric; | ||
|
||
import java.util.List; | ||
|
||
import com.univ.tracedin.domain.project.ServiceNode; | ||
|
||
public interface ServiceMetricsRepository { | ||
|
||
void save(ServiceMetrics metrics); | ||
|
||
List<HttpRequestCount> getHttpRequestCount(ServiceNode serviceNode); | ||
} |
25 changes: 25 additions & 0 deletions
25
tracedin-domain/src/main/java/com/univ/tracedin/domain/metric/ServiceMetricsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.univ.tracedin.domain.metric; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import com.univ.tracedin.domain.project.ServiceNode; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ServiceMetricsService { | ||
|
||
private final ServiceMetricsAppender serviceMetricAppender; | ||
private final ServiceMetricsReader serviceMetricReader; | ||
|
||
public void appendMetrics(ServiceMetrics metrics) { | ||
serviceMetricAppender.append(metrics); | ||
} | ||
|
||
public List<HttpRequestCount> getHttpRequestCount(ServiceNode serviceNode) { | ||
return serviceMetricReader.readHttpRequestCount(serviceNode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../user/cache/RefreshTokenCacheAdapter.java → .../auth/cache/RefreshTokenCacheAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...n/infra/user/config/TokenRedisConfig.java → ...n/infra/auth/config/TokenRedisConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...din/infra/span/repository/ESSupplier.java → ...cedin/infra/elasticsearch/ESSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.