diff --git a/config/side-infra/config.alloy.tftpl b/config/side-infra/config.alloy.tftpl index 2c2eafd..c9b4c9d 100644 --- a/config/side-infra/config.alloy.tftpl +++ b/config/side-infra/config.alloy.tftpl @@ -7,25 +7,112 @@ logging { format = "logfmt" } -local.file_match "spring_logs" { - path_targets = [{ __path__ = "/var/log/spring/*.log" }] // 서비스 로그 파일 경로 +// <1. 각 로그 레벨별로 파일 매칭 +local.file_match "spring_info" { + path_targets = [{ + __path__ = "/var/log/spring/info/*.log", + level = "info", + }] } -loki.source.file "spring_source" { - targets = local.file_match.spring_logs.targets // 위에서 정의한 로그 파일 경로 사용 - forward_to = [loki.process.spring_labels.receiver] // 읽은 로그를 처리 단계로 전달 +local.file_match "spring_warn" { + path_targets = [{ + __path__ = "/var/log/spring/warn/*.log", + level = "warn", + }] } -loki.process "spring_labels" { - forward_to = [loki.write.grafana_loki.receiver] // 처리된 로그를 Loki로 전송 +local.file_match "spring_error" { + path_targets = [{ + __path__ = "/var/log/spring/error/*.log", + level = "error", + }] +} + +local.file_match "spring_api_perf" { + path_targets = [{ + __path__ = "/var/log/spring/api-perf/*.log", + level = "info", + log_type = "performance", + }] +} +// 1> + +// <2. 각 소스 정의 +loki.source.file "spring_info" { + targets = local.file_match.spring_info.targets + forward_to = [loki.process.spring_info_labels.receiver] +} + +loki.source.file "spring_warn" { + targets = local.file_match.spring_warn.targets + forward_to = [loki.process.spring_warn_labels.receiver] +} + +loki.source.file "spring_error" { + targets = local.file_match.spring_error.targets + forward_to = [loki.process.spring_error_labels.receiver] +} + +loki.source.file "spring_api_perf" { + targets = local.file_match.spring_api_perf.targets + forward_to = [loki.process.spring_api_perf_labels.receiver] +} +// 2> + +// <3. 각 프로세서 정의 (레벨별 라벨 추가) +loki.process "spring_info_labels" { + forward_to = [loki.write.grafana_loki.receiver] + + stage.static_labels { + values = { + service = "backend", + env = sys.env("ALLOY_ENV"), + level = "info", + log_type = "application", + } + } +} + +loki.process "spring_warn_labels" { + forward_to = [loki.write.grafana_loki.receiver] + + stage.static_labels { + values = { + service = "backend", + env = sys.env("ALLOY_ENV"), + level = "warn", + log_type = "application", + } + } +} + +loki.process "spring_error_labels" { + forward_to = [loki.write.grafana_loki.receiver] + + stage.static_labels { + values = { + service = "backend", + env = sys.env("ALLOY_ENV"), + level = "error", + log_type = "application", + } + } +} + +loki.process "spring_api_perf_labels" { + forward_to = [loki.write.grafana_loki.receiver] stage.static_labels { values = { service = "backend", env = sys.env("ALLOY_ENV"), + level = "info", + log_type = "performance", } } } +// 3> loki.write "grafana_loki" { endpoint {