diff --git a/packages/common/runtime/src/otel.rs b/packages/common/runtime/src/otel.rs index b2509567b6..286ed98271 100644 --- a/packages/common/runtime/src/otel.rs +++ b/packages/common/runtime/src/otel.rs @@ -20,6 +20,9 @@ fn resource() -> Resource { SCHEMA_URL, ); + if let Ok(v) = std::env::var("RIVET_NAMESPACE") { + resource = resource.with_attribute(KeyValue::new("namespace", v)); + } if let Ok(v) = std::env::var("RIVET_CLUSTER_ID") { resource = resource.with_attribute(KeyValue::new("cluster_id", v)); } diff --git a/packages/core/services/cluster/src/workflows/server/install/install_scripts/components/rivet/guard.rs b/packages/core/services/cluster/src/workflows/server/install/install_scripts/components/rivet/guard.rs index 3436c22152..73b98642ea 100644 --- a/packages/core/services/cluster/src/workflows/server/install/install_scripts/components/rivet/guard.rs +++ b/packages/core/services/cluster/src/workflows/server/install/install_scripts/components/rivet/guard.rs @@ -156,6 +156,7 @@ pub fn configure(config: &rivet_config::Config) -> GlobalResult { .unwrap_or(0.001); Ok(include_str!("../../files/rivet_guard_configure.sh") + .replace("__NAMESPACE__", &server_config.rivet.namespace) .replace( "__RIVET_GUARD_CONFIG__", &serde_json::to_string_pretty(&guard_config_json)?, diff --git a/packages/core/services/cluster/src/workflows/server/install/install_scripts/components/rivet/worker.rs b/packages/core/services/cluster/src/workflows/server/install/install_scripts/components/rivet/worker.rs index d9314b72cd..75aea4db36 100644 --- a/packages/core/services/cluster/src/workflows/server/install/install_scripts/components/rivet/worker.rs +++ b/packages/core/services/cluster/src/workflows/server/install/install_scripts/components/rivet/worker.rs @@ -162,6 +162,7 @@ pub fn configure(config: &rivet_config::Config) -> GlobalResult { .unwrap_or(0.001); Ok(include_str!("../../files/rivet_worker_configure.sh") + .replace("__NAMESPACE__", &server_config.rivet.namespace) .replace( "__RIVET_EDGE_CONFIG__", &serde_json::to_string_pretty(&edge_config_json)?, diff --git a/packages/core/services/cluster/src/workflows/server/install/install_scripts/components/vector.rs b/packages/core/services/cluster/src/workflows/server/install/install_scripts/components/vector.rs index 6ea231287f..e493d9d97d 100644 --- a/packages/core/services/cluster/src/workflows/server/install/install_scripts/components/vector.rs +++ b/packages/core/services/cluster/src/workflows/server/install/install_scripts/components/vector.rs @@ -21,7 +21,7 @@ pub struct PrometheusTarget { pub scrape_interval: usize, } -pub fn configure(config: &Config, pool_type: PoolType) -> GlobalResult { +pub fn configure(namespace: &str, config: &Config, pool_type: PoolType) -> GlobalResult { let sources = config .prometheus_targets .keys() @@ -43,6 +43,7 @@ pub fn configure(config: &Config, pool_type: PoolType) -> GlobalResult { "inputs": ["filter_metrics"], "source": formatdoc!( r#" + .tags.namespace = "{namespace}" .tags.server_id = "___SERVER_ID___" .tags.datacenter_id = "___DATACENTER_ID___" .tags.cluster_id = "___CLUSTER_ID___" @@ -87,6 +88,7 @@ pub fn configure(config: &Config, pool_type: PoolType) -> GlobalResult { r#" .source = "pegboard_manager" + .namespace = "{namespace}" .client_id = "___SERVER_ID___" .server_id = "___SERVER_ID___" .datacenter_id = "___DATACENTER_ID___" @@ -109,6 +111,7 @@ pub fn configure(config: &Config, pool_type: PoolType) -> GlobalResult { r#" .source = "pegboard_isolate_v8_runner" + .namespace = "{namespace}" .client_id = "___SERVER_ID___" .server_id = "___SERVER_ID___" .datacenter_id = "___DATACENTER_ID___" @@ -132,6 +135,7 @@ pub fn configure(config: &Config, pool_type: PoolType) -> GlobalResult { .source = "pegboard_container_runner" .actor_id = parse_regex!(.file, r'/var/lib/rivet-client/actors/(?P[0-9a-fA-F-]+)/logs/').actor_id + .namespace = "{namespace}" .client_id = "___SERVER_ID___" .server_id = "___SERVER_ID___" .datacenter_id = "___DATACENTER_ID___" @@ -161,6 +165,7 @@ pub fn configure(config: &Config, pool_type: PoolType) -> GlobalResult { r#" .source = "worker" + .namespace = "{namespace}" .server_id = "___SERVER_ID___" .datacenter_id = "___DATACENTER_ID___" .cluster_id = "___CLUSTER_ID___" @@ -187,6 +192,7 @@ pub fn configure(config: &Config, pool_type: PoolType) -> GlobalResult { r#" .source = "guard" + .namespace = "{namespace}" .server_id = "___SERVER_ID___" .datacenter_id = "___DATACENTER_ID___" .cluster_id = "___CLUSTER_ID___" diff --git a/packages/core/services/cluster/src/workflows/server/install/install_scripts/files/rivet_guard_configure.sh b/packages/core/services/cluster/src/workflows/server/install/install_scripts/files/rivet_guard_configure.sh index df8aa06405..147ce52625 100644 --- a/packages/core/services/cluster/src/workflows/server/install/install_scripts/files/rivet_guard_configure.sh +++ b/packages/core/services/cluster/src/workflows/server/install/install_scripts/files/rivet_guard_configure.sh @@ -18,6 +18,7 @@ ConditionPathExists=/etc/rivet-server/ Environment="RIVET_OTEL_ENABLED=1" Environment="RIVET_OTEL_SAMPLER_RATIO=1" Environment="RIVET_SERVICE_NAME=guard" +Environment="RIVET_NAMESPACE=__NAMESPACE__" Environment="RIVET_CLUSTER_ID=___CLUSTER_ID___" Environment="RIVET_DATACENTER_ID=___DATACENTER_ID___" Environment="RIVET_SERVER_ID=___SERVER_ID___" diff --git a/packages/core/services/cluster/src/workflows/server/install/install_scripts/files/rivet_worker_configure.sh b/packages/core/services/cluster/src/workflows/server/install/install_scripts/files/rivet_worker_configure.sh index 4f0aef7314..46042eb9ef 100644 --- a/packages/core/services/cluster/src/workflows/server/install/install_scripts/files/rivet_worker_configure.sh +++ b/packages/core/services/cluster/src/workflows/server/install/install_scripts/files/rivet_worker_configure.sh @@ -19,6 +19,7 @@ ConditionPathExists=/etc/rivet-server/ Environment="RIVET_OTEL_ENABLED=1" Environment="RIVET_OTEL_SAMPLER_RATIO=1" Environment="RIVET_SERVICE_NAME=edge" +Environment="RIVET_NAMESPACE=__NAMESPACE__" Environment="RIVET_CLUSTER_ID=___CLUSTER_ID___" Environment="RIVET_DATACENTER_ID=___DATACENTER_ID___" Environment="RIVET_SERVER_ID=___SERVER_ID___" diff --git a/packages/core/services/cluster/src/workflows/server/install/install_scripts/mod.rs b/packages/core/services/cluster/src/workflows/server/install/install_scripts/mod.rs index 9674d00bd8..3c4b5c19c1 100644 --- a/packages/core/services/cluster/src/workflows/server/install/install_scripts/mod.rs +++ b/packages/core/services/cluster/src/workflows/server/install/install_scripts/mod.rs @@ -111,6 +111,8 @@ pub async fn gen_initialize( pool_type: PoolType, server_token: &str, ) -> GlobalResult { + let server_config = config.server()?; + let mut script = Vec::new(); let mut prometheus_targets = HashMap::new(); @@ -233,6 +235,7 @@ pub async fn gen_initialize( // MARK: Common (post) if !prometheus_targets.is_empty() { script.push(components::vector::configure( + &server_config.rivet.namespace, &components::vector::Config { prometheus_targets }, pool_type, )?); diff --git a/packages/core/services/service-log/db/service-log/migrations/20250530221342_add_namespace_column.down.sql b/packages/core/services/service-log/db/service-log/migrations/20250530221342_add_namespace_column.down.sql new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/core/services/service-log/db/service-log/migrations/20250530221342_add_namespace_column.up.sql b/packages/core/services/service-log/db/service-log/migrations/20250530221342_add_namespace_column.up.sql new file mode 100644 index 0000000000..01b2454558 --- /dev/null +++ b/packages/core/services/service-log/db/service-log/migrations/20250530221342_add_namespace_column.up.sql @@ -0,0 +1 @@ +ALTER TABLE service_logs ADD COLUMN namespace String DEFAULT ''; \ No newline at end of file