Skip to content

Commit

Permalink
feat: enable ceramic nodejs inspection (#176)
Browse files Browse the repository at this point in the history
* feat: enable ceramic nodejs inspection

* feat: enable ceramic nodejs inspection
  • Loading branch information
smrz2001 authored May 14, 2024
1 parent 13e96fb commit 4e466b4
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 32 deletions.
11 changes: 7 additions & 4 deletions operator/src/monitoring/opentelemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ use rand::RngCore;

use crate::{
labels::selector_labels,
network::{ipfs_rpc::IpfsRpcClient, resource_limits::ResourceLimitsConfig},
network::{
controller::DEFAULT_METRICS_PORT, ipfs_rpc::IpfsRpcClient,
resource_limits::ResourceLimitsConfig,
},
utils::{
apply_account, apply_cluster_role, apply_cluster_role_binding, apply_config_map,
apply_service, apply_stateful_set, Clock, Context,
Expand Down Expand Up @@ -97,9 +100,9 @@ fn service_spec() -> ServiceSpec {
},
ServicePort {
name: Some("all-metrics".to_owned()),
port: 9464,
port: DEFAULT_METRICS_PORT,
protocol: Some("TCP".to_owned()),
target_port: Some(IntOrString::Int(9464)),
target_port: Some(IntOrString::Int(DEFAULT_METRICS_PORT)),
..Default::default()
},
ServicePort {
Expand Down Expand Up @@ -178,7 +181,7 @@ fn stateful_set_spec(config: &OtelConfig) -> StatefulSetSpec {
..Default::default()
},
ContainerPort {
container_port: 9464,
container_port: DEFAULT_METRICS_PORT,
name: Some("all-metrics".to_owned()),
..Default::default()
},
Expand Down
8 changes: 4 additions & 4 deletions operator/src/network/cas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use crate::{
ceramic::NetworkConfig,
controller::{
CAS_APP, CAS_IPFS_APP, CAS_IPFS_SERVICE_NAME, CAS_POSTGRES_APP,
CAS_POSTGRES_SECRET_NAME, CAS_POSTGRES_SERVICE_NAME, CAS_SERVICE_NAME, GANACHE_APP,
GANACHE_SERVICE_NAME, LOCALSTACK_APP, LOCALSTACK_SERVICE_NAME,
NETWORK_DEV_MODE_RESOURCES,
CAS_POSTGRES_SECRET_NAME, CAS_POSTGRES_SERVICE_NAME, CAS_SERVICE_NAME,
DEFAULT_METRICS_PORT, GANACHE_APP, GANACHE_SERVICE_NAME, LOCALSTACK_APP,
LOCALSTACK_SERVICE_NAME, NETWORK_DEV_MODE_RESOURCES,
},
datadog::DataDogConfig,
ipfs::{IpfsConfig, IpfsInfo, IPFS_DATA_PV_CLAIM},
Expand Down Expand Up @@ -299,7 +299,7 @@ pub fn cas_stateful_set_spec(
},
EnvVar {
name: "METRICS_PORT".to_owned(),
value: Some("9464".to_owned()),
value: Some(DEFAULT_METRICS_PORT.to_string()),
..Default::default()
},
],
Expand Down
49 changes: 33 additions & 16 deletions operator/src/network/ceramic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::{
network::{
controller::{
CAS_SERVICE_NAME, CERAMIC_APP, CERAMIC_POSTGRES_SECRET_NAME, CERAMIC_SERVICE_API_PORT,
CERAMIC_SERVICE_IPFS_PORT, GANACHE_SERVICE_NAME, INIT_CONFIG_MAP_NAME,
NETWORK_DEV_MODE_RESOURCES,
CERAMIC_SERVICE_IPFS_PORT, DEFAULT_METRICS_PORT, GANACHE_SERVICE_NAME,
INIT_CONFIG_MAP_NAME, NETWORK_DEV_MODE_RESOURCES, NODE_INSPECTION_PORT,
},
datadog::DataDogConfig,
ipfs::{IpfsConfig, IpfsInfo, IPFS_DATA_PV_CLAIM},
Expand Down Expand Up @@ -401,6 +401,14 @@ pub fn stateful_set_spec(ns: &str, bundle: &CeramicBundle<'_>) -> StatefulSetSpe
})
}

if bundle.net_config.debug_mode {
ceramic_env.push(EnvVar {
name: "NODE_OPTIONS".to_owned(),
value: Some("--inspect".to_owned()),
..Default::default()
});
}

// Apply env overrides, if specified.
override_and_sort_env_vars(&mut ceramic_env, &bundle.config.env);

Expand Down Expand Up @@ -463,6 +471,28 @@ pub fn stateful_set_spec(ns: &str, bundle: &CeramicBundle<'_>) -> StatefulSetSpe

volumes.append(&mut bundle.config.ipfs.volumes(&bundle.info));

let mut ceramic_ports = vec![
ContainerPort {
container_port: CERAMIC_SERVICE_API_PORT,
name: Some("api".to_owned()),
..Default::default()
},
ContainerPort {
container_port: DEFAULT_METRICS_PORT,
name: Some("metrics".to_owned()),
protocol: Some("TCP".to_owned()),
..Default::default()
},
];
if bundle.net_config.debug_mode {
ceramic_ports.push(ContainerPort {
container_port: NODE_INSPECTION_PORT,
name: Some("inspect".to_owned()),
protocol: Some("TCP".to_owned()),
..Default::default()
});
}

StatefulSetSpec {
pod_management_policy: Some("Parallel".to_owned()),
replicas: Some(bundle.info.replicas),
Expand Down Expand Up @@ -509,19 +539,7 @@ pub fn stateful_set_spec(ns: &str, bundle: &CeramicBundle<'_>) -> StatefulSetSpe
image: Some(bundle.config.image.clone()),
image_pull_policy: Some(bundle.config.image_pull_policy.clone()),
name: "ceramic".to_owned(),
ports: Some(vec![
ContainerPort {
container_port: CERAMIC_SERVICE_API_PORT,
name: Some("api".to_owned()),
..Default::default()
},
ContainerPort {
container_port: 9464,
name: Some("metrics".to_owned()),
protocol: Some("TCP".to_owned()),
..Default::default()
},
]),
ports: Some(ceramic_ports),
readiness_probe: Some(Probe {
http_get: Some(HTTPGetAction {
path: Some("/api/v0/node/healthcheck".to_owned()),
Expand All @@ -544,7 +562,6 @@ pub fn stateful_set_spec(ns: &str, bundle: &CeramicBundle<'_>) -> StatefulSetSpe
timeout_seconds: Some(30),
..Default::default()
}),

resources: Some(ResourceRequirements {
limits: Some(bundle.config.resource_limits.clone().into()),
requests: Some(bundle.config.resource_limits.clone().into()),
Expand Down
52 changes: 45 additions & 7 deletions operator/src/network/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ const CERAMIC_SERVICE_SELECTOR: &str = "ceramic-role=service";
const CERAMIC_STATEFUL_SET_VALUE: &str = "stateful_set";
const CERAMIC_STATEFUL_SET_SELECTOR: &str = "ceramic-role=stateful_set";

pub(crate) const DEFAULT_METRICS_PORT: i32 = 9464;

pub(crate) const NODE_INSPECTION_PORT: i32 = 9229;

/// Handle errors during reconciliation.
fn on_error(
_network: Arc<Network>,
Expand Down Expand Up @@ -290,7 +294,7 @@ async fn reconcile_(
cx.clone(),
network.clone(),
"ceramic",
9464,
DEFAULT_METRICS_PORT,
"ceramic",
monitoring_config.pod_monitor.pod_target_labels.clone(),
)
Expand All @@ -308,7 +312,7 @@ async fn reconcile_(
cx.clone(),
network.clone(),
"otel",
9464,
DEFAULT_METRICS_PORT,
"otel",
monitoring_config.pod_monitor.pod_target_labels,
)
Expand Down Expand Up @@ -1021,7 +1025,7 @@ async fn apply_pod_monitor(
cx: Arc<Context<impl IpfsRpcClient, impl RngCore, impl Clock>>,
network: Arc<Network>,
monitor_name: &str,
monitor_port: u32,
monitor_port: i32,
monitor_selector: &str,
monitor_labels: Vec<String>,
) -> Result<(), Error> {
Expand Down Expand Up @@ -4345,7 +4349,30 @@ mod tests {
stub.ceramics[0].stateful_set.patch(expect![[r#"
--- original
+++ modified
@@ -148,6 +148,13 @@
@@ -82,6 +82,10 @@
"value": "http://ganache:8545"
},
{
+ "name": "NODE_OPTIONS",
+ "value": "--inspect"
+ },
+ {
"name": "POSTGRES_DB",
"value": "ceramic"
},
@@ -125,6 +129,11 @@
"containerPort": 9464,
"name": "metrics",
"protocol": "TCP"
+ },
+ {
+ "containerPort": 9229,
+ "name": "inspect",
+ "protocol": "TCP"
}
],
"readinessProbe": {
@@ -148,6 +157,13 @@
"memory": "1Gi"
}
},
Expand All @@ -4359,7 +4386,7 @@ mod tests {
"volumeMounts": [
{
"mountPath": "/config",
@@ -252,6 +259,10 @@
@@ -252,6 +268,10 @@
"value": "/ip4/0.0.0.0/tcp/4001"
},
{
Expand All @@ -4370,7 +4397,7 @@ mod tests {
"name": "RUST_LOG",
"value": "info,ceramic_one=debug,multipart=error"
}
@@ -274,6 +285,11 @@
@@ -274,6 +294,11 @@
"containerPort": 9465,
"name": "metrics",
"protocol": "TCP"
Expand All @@ -4382,7 +4409,7 @@ mod tests {
}
],
"resources": {
@@ -288,6 +304,13 @@
@@ -288,6 +313,13 @@
"memory": "512Mi"
}
},
Expand All @@ -4396,6 +4423,17 @@ mod tests {
"volumeMounts": [
{
"mountPath": "/data/ipfs",
@@ -350,6 +382,10 @@
"value": "http://ganache:8545"
},
{
+ "name": "NODE_OPTIONS",
+ "value": "--inspect"
+ },
+ {
"name": "POSTGRES_DB",
"value": "ceramic"
},
"#]]);
stub.cas_ipfs_stateful_set.patch(expect![[r#"
--- original
Expand Down
2 changes: 1 addition & 1 deletion operator/src/network/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ pub struct PodMetricsEndpointSpec {
/// Monitoring path
pub path: Option<String>,
/// Monitoring port
pub target_port: Option<u32>,
pub target_port: Option<i32>,
}

/// Describes the selector for the pod monitor
Expand Down

0 comments on commit 4e466b4

Please sign in to comment.