-
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.
- 기존 HTTP 로 받던 Trace 및 Metric 데이터를 GRPC로 리팩토링
- Loading branch information
1 parent
5b1e7cd
commit 5d92e8b
Showing
19 changed files
with
375 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
start: | ||
docker compose -f kafka/common.yml -f kafka/zookeeper.yml -f kafka/kafka_cluster.yml up -d | ||
docker compose -f es/docker-compose.yml up -d | ||
docker compose -f infra/kafka/common.yml -f infra/kafka/zookeeper.yml -f infra/kafka/kafka_cluster.yml up -d | ||
docker compose -f infra/es/docker-compose.yml up -d | ||
|
||
stop: | ||
docker compose -f kafka/common.yml -f kafka/zookeeper.yml -f kafka/kafka_cluster.yml down | ||
docker compose -f es/docker-compose.yml down | ||
docker compose -f infra/kafka/common.yml -f infra/kafka/zookeeper.yml -f infra/kafka/kafka_cluster.yml down | ||
docker compose -f infra/es/docker-compose.yml down |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,44 @@ | ||
listen 80; | ||
http2 on; | ||
server_name tracedin.p-e.kr; | ||
server_tokens off; | ||
|
||
location /.well-known/acme-challenge/ { | ||
root /var/www/certbot; | ||
} | ||
|
||
location / { | ||
return 301 https://$server_name$request_uri; | ||
} | ||
} | ||
|
||
server { | ||
listen 443 ssl; | ||
http2 on; | ||
server_name tracedin.p-e.kr; | ||
server_tokens off; | ||
|
||
access_log /var/log/nginx/access.log main; | ||
error_log /var/log/nginx/error.log; | ||
|
||
ssl_certificate /etc/letsencrypt/live/tracedin.p-e.kr/fullchain.pem; # managed by Certbot | ||
ssl_certificate_key /etc/letsencrypt/live/tracedin.p-e.kr/privkey.pem; # managed by Certbot | ||
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot | ||
|
||
location / { | ||
proxy_pass http://tracedin-green; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header Host $http_host; | ||
proxy_set_header Connection ''; | ||
proxy_http_version 1.1; | ||
} | ||
|
||
location /SpanGrpcAppender/AppendSpans { | ||
grpc_pass grpc://grpcserver; | ||
} | ||
|
||
location /ServiceMetricsGrpcAppender/AppendServiceMetrics { | ||
grpc_pass grpc://grpcserver; | ||
} | ||
} |
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,9 @@ | ||
services: | ||
nginx: | ||
image: nginx:latest | ||
container_name: nginx | ||
ports: | ||
- "80:80" | ||
volumes: | ||
- ./conf.d:/etc/nginx/conf.d # Nginx 설정 파일 | ||
- ./nginx/log:/var/log/nginx # 로그 파일 |
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
73 changes: 73 additions & 0 deletions
73
...plication/app-api/src/main/java/com/univ/tracedin/api/metric/grpc/ServiceMetricsGrpc.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,73 @@ | ||
package com.univ.tracedin.api.metric.grpc; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import com.univ.tracedin.api.metric.grpc.ServiceMetricsGrpcAppenderGrpc.ServiceMetricsGrpcAppenderImplBase; | ||
import com.univ.tracedin.api.metric.grpc.ServiceMetricsProto.AppendServiceMetricsRequest; | ||
import com.univ.tracedin.api.metric.grpc.ServiceMetricsProto.AppendServiceMetricsResponse; | ||
import com.univ.tracedin.api.metric.grpc.ServiceMetricsProto.MetricRequest; | ||
import com.univ.tracedin.domain.metric.Metric; | ||
import com.univ.tracedin.domain.metric.MetricType; | ||
import com.univ.tracedin.domain.metric.ServiceMetrics; | ||
import com.univ.tracedin.domain.metric.ServiceMetricsService; | ||
import com.univ.tracedin.domain.project.ProjectKey; | ||
|
||
import io.grpc.stub.StreamObserver; | ||
import net.devh.boot.grpc.server.service.GrpcService; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@GrpcService | ||
public class ServiceMetricsGrpc extends ServiceMetricsGrpcAppenderImplBase { | ||
|
||
private final ServiceMetricsService serviceMetricsService; | ||
|
||
@Override | ||
public void appendServiceMetrics( | ||
AppendServiceMetricsRequest request, | ||
StreamObserver<AppendServiceMetricsResponse> responseObserver) { | ||
try { | ||
log.info("appendServiceMetrics request: {}", request.toString()); | ||
serviceMetricsService.appendMetrics(toServiceMetrics(request)); | ||
responseObserver.onNext( | ||
AppendServiceMetricsResponse.newBuilder().setStatusCode(200).build()); | ||
} catch (Exception e) { | ||
log.error("Failed to append service metrics", e); | ||
responseObserver.onNext( | ||
AppendServiceMetricsResponse.newBuilder().setStatusCode(500).build()); | ||
} finally { | ||
responseObserver.onCompleted(); | ||
} | ||
} | ||
|
||
private ServiceMetrics toServiceMetrics(AppendServiceMetricsRequest request) { | ||
return ServiceMetrics.builder() | ||
.projectKey(ProjectKey.from(request.getProjectKey())) | ||
.serviceName(request.getServiceName()) | ||
.metrics(request.getMetricsList().stream().map(this::toMetric).toList()) | ||
.build(); | ||
} | ||
|
||
private Metric toMetric(MetricRequest metricRequest) { | ||
return Metric.builder() | ||
.name(metricRequest.getName()) | ||
.description(metricRequest.getDescription()) | ||
.unit(metricRequest.getUnit()) | ||
.type(MetricType.fromValue(metricRequest.getType())) | ||
.value(metricRequest.getValue()) | ||
.count(metricRequest.getCount()) | ||
.sum(metricRequest.getSum()) | ||
.min(metricRequest.getMin()) | ||
.max(metricRequest.getMax()) | ||
.attributes( | ||
metricRequest.getAttributesMap().entrySet().stream() | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))) | ||
.timestamp(LocalDateTime.now()) | ||
.build(); | ||
} | ||
} |
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
95 changes: 95 additions & 0 deletions
95
tracedin-application/app-api/src/main/java/com/univ/tracedin/api/span/grpc/SpanGrpc.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,95 @@ | ||
package com.univ.tracedin.api.span.grpc; | ||
|
||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import com.univ.tracedin.api.span.grpc.SpanGrpcAppenderGrpc.SpanGrpcAppenderImplBase; | ||
import com.univ.tracedin.api.span.grpc.SpanProto.AppendSpanResponse; | ||
import com.univ.tracedin.api.span.grpc.SpanProto.AppendSpansRequest; | ||
import com.univ.tracedin.domain.span.Span; | ||
import com.univ.tracedin.domain.span.SpanAttributes; | ||
import com.univ.tracedin.domain.span.SpanEvent; | ||
import com.univ.tracedin.domain.span.SpanId; | ||
import com.univ.tracedin.domain.span.SpanKind; | ||
import com.univ.tracedin.domain.span.SpanService; | ||
import com.univ.tracedin.domain.span.SpanStatus; | ||
import com.univ.tracedin.domain.span.SpanTiming; | ||
import com.univ.tracedin.domain.span.SpanType; | ||
import com.univ.tracedin.domain.span.TraceId; | ||
|
||
import io.grpc.stub.StreamObserver; | ||
import net.devh.boot.grpc.server.service.GrpcService; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@GrpcService | ||
public class SpanGrpc extends SpanGrpcAppenderImplBase { | ||
|
||
private final SpanService spanService; | ||
|
||
@Override | ||
public void appendSpans( | ||
AppendSpansRequest request, StreamObserver<AppendSpanResponse> responseObserver) { | ||
try { | ||
log.info("appendSpans request: {}", request.toString()); | ||
spanService.publishSpans(request.getSpansList().stream().map(this::toSpan).toList()); | ||
responseObserver.onNext(AppendSpanResponse.newBuilder().setStatusCode(200).build()); | ||
} catch (Exception e) { | ||
log.error("Failed to append spans", e); | ||
responseObserver.onNext(AppendSpanResponse.newBuilder().setStatusCode(500).build()); | ||
} finally { | ||
responseObserver.onCompleted(); | ||
} | ||
} | ||
|
||
private Span toSpan(SpanProto.Span span) { | ||
return Span.builder() | ||
.id(SpanId.from(span.getSpanId())) | ||
.traceId(TraceId.from(span.getTraceId())) | ||
.parentId(SpanId.from(span.getParentSpanId())) | ||
.name(span.getName()) | ||
.serviceName(span.getServiceName()) | ||
.projectKey(span.getProjectKey()) | ||
.spanType(SpanType.fromValue(span.getSpanType())) | ||
.kind(SpanKind.fromValue(span.getKind())) | ||
.timing( | ||
SpanTiming.builder() | ||
.startEpochMillis(nanosToMillis(span.getStartEpochNanos())) | ||
.endEpochMillis(nanosToMillis(span.getEndEpochNanos())) | ||
.build()) | ||
.status(SpanStatus.fromValue(span.getSpanStatus())) | ||
.attributes( | ||
SpanAttributes.builder() | ||
.data( | ||
span.getAttributes().getDataMap().entrySet().stream() | ||
.collect( | ||
Collectors.toMap( | ||
Map.Entry::getKey, | ||
Map.Entry::getValue))) | ||
.capacity(span.getAttributes().getCapacity()) | ||
.totalAddedValues(span.getAttributes().getTotalAddedValues()) | ||
.build()) | ||
.events( | ||
span.getEventsList().stream() | ||
.map( | ||
event -> | ||
new SpanEvent( | ||
event.getName(), | ||
event.getAttributesMap().entrySet().stream() | ||
.collect( | ||
Collectors.toMap( | ||
Map.Entry::getKey, | ||
Map.Entry | ||
::getValue)), | ||
event.getEpochNanos())) | ||
.toList()) | ||
.build(); | ||
} | ||
|
||
private long nanosToMillis(long nanos) { | ||
return nanos / 1_000_000; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
tracedin-application/app-api/src/main/proto/service-metrics.proto
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,31 @@ | ||
syntax = "proto3"; | ||
|
||
option java_package = "com.univ.tracedin.api.metric.grpc"; | ||
option java_outer_classname = "ServiceMetricsProto"; | ||
|
||
message AppendServiceMetricsRequest { | ||
string project_key = 1; | ||
string service_name = 2; | ||
repeated MetricRequest metrics = 3; | ||
} | ||
|
||
message MetricRequest { | ||
string name = 1; | ||
string description = 2; | ||
string unit = 3; | ||
string type = 4; | ||
double value = 5; // GAUGE 및 SUM 타입의 단일 값 | ||
int64 count = 6; // HISTOGRAM 타입의 카운트 | ||
double sum = 7; // HISTOGRAM 타입의 합계 | ||
double min = 8; // HISTOGRAM 타입의 최소값 | ||
double max = 9; // HISTOGRAM 타입의 최대값 | ||
map<string, string> attributes = 10; // 속성 정보 | ||
} | ||
message AppendServiceMetricsResponse { | ||
int64 status_code = 1; | ||
} | ||
|
||
|
||
service ServiceMetricsGrpcAppender { | ||
rpc AppendServiceMetrics (AppendServiceMetricsRequest) returns (AppendServiceMetricsResponse); | ||
} |
Oops, something went wrong.