Skip to content

Commit

Permalink
fix: enable metrics export in ECS (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
xav authored Aug 30, 2023
1 parent f89432d commit db61e22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::{config::Configuration, state::AppState},
::log::info,
::log::{info, warn},
axum::{
routing::{get, post},
Router,
Expand Down Expand Up @@ -32,10 +32,10 @@ pub async fn bootstrap(
mut shutdown: broadcast::Receiver<()>,
config: Configuration,
) -> error::Result<()> {
let keys_persitent_storage: Arc<MongoPersistentStorage> =
let keys_persistent_storage: Arc<MongoPersistentStorage> =
Arc::new(MongoPersistentStorage::new(&config).await?);

let mut state = AppState::new(config, keys_persitent_storage)?;
let mut state = AppState::new(config, keys_persistent_storage)?;

if state.config.telemetry_prometheus_port.is_some() {
state.set_metrics(metrics::Metrics::new(Resource::new(vec![
Expand All @@ -45,6 +45,8 @@ pub async fn bootstrap(
state.build_info.crate_info.version.clone().to_string(),
),
]))?);
} else {
warn!("Telemetry is disabled")
}

let port = state.config.port;
Expand Down
14 changes: 9 additions & 5 deletions terraform/ecs/cluster.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
locals {
image = "${var.ecr_repository_url}:${var.image_version}"
image = "${var.ecr_repository_url}:${var.image_version}"
telemetry_port = var.port + 1

otel_cpu = 128
otel_memory = 128
Expand Down Expand Up @@ -73,7 +74,8 @@ resource "aws_ecs_task_definition" "app_task" {

environment = [
{ "name" = "DATABASE_URL", "value" = var.keystore_addr },
{ "name" = "LOG_LEVEL", "value" = var.log_level }
{ "name" = "LOG_LEVEL", "value" = var.log_level },
{ "name" = "TELEMETRY_PROMETHEUS_PORT", "value" = tostring(local.telemetry_port) },
],

portMappings = [
Expand Down Expand Up @@ -105,13 +107,15 @@ resource "aws_ecs_task_definition" "app_task" {
essential = true,

command = [
"--config=/etc/ecs/ecs-amp-prometheus.yaml"
"--config=/etc/ecs/ecs-amp-prometheus.yaml",
# Uncomment to enable debug logging in otel-collector
"--set=service.telemetry.logs.level=DEBUG"
],

environment = [
{ name : "AWS_PROMETHEUS_SCRAPING_ENDPOINT", value : "0.0.0.0:${var.port + 1}" },
{ name : "AWS_PROMETHEUS_SCRAPING_ENDPOINT", value : "0.0.0.0:${local.telemetry_port}" },
{ name : "AWS_PROMETHEUS_ENDPOINT", value : "${var.prometheus_endpoint}api/v1/remote_write" },
{ name = "AWS_REGION", value = "eu-central-1" },
{ name = "AWS_REGION", value = module.this.region },
],

logConfiguration = {
Expand Down

0 comments on commit db61e22

Please sign in to comment.