Skip to content

Commit 0c00e16

Browse files
authored
Merge branch 'master' into codex/fix-node-permission-codec
2 parents a047da9 + 2ec7d89 commit 0c00e16

79 files changed

Lines changed: 3755 additions & 1528 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ members = [
6464
"core/shard",
6565
"core/shard_allocator",
6666
"core/simulator",
67+
"core/system_stats",
6768
"core/tools",
6869
"examples/rust",
6970
]
@@ -305,6 +306,7 @@ strum = { version = "0.28.0", features = ["derive"] }
305306
strum_macros = "0.28.0"
306307
syn = { version = "2", features = ["full", "extra-traits"] }
307308
sysinfo = "0.39.5"
309+
system_stats = { path = "core/system_stats" }
308310
tempfile = "3.27.0"
309311
terminal_size = { version = "0.4.4" }
310312
test-case = "3.3.1"

core/common/src/error/iggy_error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ pub enum IggyError {
122122
InvalidPersonalAccessTokenExpiry = 56,
123123
#[error("Request transiently not committed; retry")]
124124
TransientNotCommitted = 57,
125+
#[error("Request transiently not accepted; retry, on any replica")]
126+
TransientNotAccepted = 58,
125127
#[error("Not connected")]
126128
NotConnected = 61,
127129
#[error("Client shutdown")]

core/common/src/traits/binary_impls/cluster.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use crate::traits::binary_auth::fail_if_not_authenticated;
1918
use crate::wire_conversions::cluster_metadata_from_wire;
2019
use crate::{BinaryClient, ClusterClient, ClusterMetadata, IggyError};
2120
use iggy_binary_protocol::codec::WireEncode;
@@ -26,7 +25,6 @@ use iggy_binary_protocol::responses::system::get_cluster_metadata::ClusterMetada
2625
#[async_trait::async_trait]
2726
impl<B: BinaryClient> ClusterClient for B {
2827
async fn get_cluster_metadata(&self) -> Result<ClusterMetadata, IggyError> {
29-
fail_if_not_authenticated(self).await?;
3028
let response = self
3129
.send_raw_with_response(
3230
GET_CLUSTER_METADATA_CODE,

core/common/src/traits/cluster_client.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use async_trait::async_trait;
2323
pub trait ClusterClient {
2424
/// Get the metadata of the cluster including node information, roles, and status.
2525
///
26-
/// Authentication is required.
26+
/// Served pre-auth so an unauthenticated client can locate the cluster
27+
/// leader before signing in; the server applies its own policy.
2728
async fn get_cluster_metadata(&self) -> Result<ClusterMetadata, IggyError>;
2829
}

core/connectors/runtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ serde_with = { workspace = true }
7070
serde_yaml_ng = { workspace = true }
7171
strum = { workspace = true }
7272
sysinfo = { workspace = true }
73+
system_stats = { workspace = true }
7374
thiserror = { workspace = true }
7475
tokio = { workspace = true }
7576
toml = { workspace = true }

core/connectors/runtime/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use std::{
3939
env,
4040
sync::{Arc, atomic::AtomicU32},
4141
};
42+
use system_stats::capture_allowed_cpus;
4243
use tracing::{error, info};
4344

4445
mod api;
@@ -114,6 +115,7 @@ fn print_ascii_art(text: &str) {
114115

115116
#[tokio::main]
116117
async fn main() -> Result<(), RuntimeError> {
118+
capture_allowed_cpus();
117119
Args::parse();
118120
print_ascii_art("Iggy Connectors");
119121

core/connectors/runtime/src/stats.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,17 @@ use crate::metrics::ConnectorType;
2020
use iggy_common::{IggyTimestamp, SemanticVersion};
2121
use iggy_connector_sdk::api::{ConnectorRuntimeStats, ConnectorStats};
2222
use std::str::FromStr;
23-
use std::sync::Arc;
23+
use std::sync::{Arc, Mutex, OnceLock, PoisonError};
2424
use sysinfo::System;
25+
use system_stats::SystemProbe;
2526

2627
const VERSION: &str = env!("CARGO_PKG_VERSION");
2728
const SEMANTIC_VERSION: SemanticVersion = SemanticVersion::parse_const(VERSION);
2829

29-
pub async fn get_runtime_stats(context: &Arc<RuntimeContext>) -> ConnectorRuntimeStats {
30-
let pid = std::process::id();
31-
32-
let mut system = System::new_all();
33-
system.refresh_cpu_all();
34-
system.refresh_memory();
35-
system.refresh_processes(
36-
sysinfo::ProcessesToUpdate::Some(&[sysinfo::Pid::from_u32(pid)]),
37-
true,
38-
);
39-
40-
let total_cpu_usage = system.global_cpu_usage();
41-
let total_memory = system.total_memory();
42-
let available_memory = system.available_memory();
30+
static SYSINFO: OnceLock<Mutex<System>> = OnceLock::new();
4331

44-
let (cpu_usage, memory_usage) = system
45-
.process(sysinfo::Pid::from_u32(pid))
46-
.map(|p| (p.cpu_usage(), p.memory()))
47-
.unwrap_or((0.0, 0));
32+
pub async fn get_runtime_stats(context: &Arc<RuntimeContext>) -> ConnectorRuntimeStats {
33+
let system = probe_system();
4834

4935
let sources = context.sources.get_all().await;
5036
let sinks = context.sinks.get_all().await;
@@ -113,12 +99,12 @@ pub async fn get_runtime_stats(context: &Arc<RuntimeContext>) -> ConnectorRuntim
11399
ConnectorRuntimeStats {
114100
connectors_runtime_version: VERSION.to_owned(),
115101
connectors_runtime_version_semver: SEMANTIC_VERSION.get_numeric_version().ok(),
116-
process_id: pid,
117-
cpu_usage,
118-
total_cpu_usage,
119-
memory_usage,
120-
total_memory,
121-
available_memory,
102+
process_id: system.process_id,
103+
cpu_usage: system.cpu_usage,
104+
total_cpu_usage: system.total_cpu_usage,
105+
memory_usage: system.memory_usage,
106+
total_memory: system.total_memory,
107+
available_memory: system.available_memory,
122108
run_time,
123109
start_time: start,
124110
sources_total,
@@ -128,3 +114,11 @@ pub async fn get_runtime_stats(context: &Arc<RuntimeContext>) -> ConnectorRuntim
128114
connectors,
129115
}
130116
}
117+
118+
fn probe_system() -> SystemProbe {
119+
let mut system = SYSINFO
120+
.get_or_init(|| Mutex::new(System::new()))
121+
.lock()
122+
.unwrap_or_else(PoisonError::into_inner);
123+
SystemProbe::capture(&mut system)
124+
}

core/connectors/sdk/src/api.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,39 @@ impl ConnectorError {
7373
/// Runtime statistics response from `/stats` endpoint.
7474
#[derive(Debug, Serialize, Deserialize)]
7575
pub struct ConnectorRuntimeStats {
76+
/// The version of the connectors runtime.
7677
pub connectors_runtime_version: String,
78+
/// The semantic version of the connectors runtime in the numeric format,
79+
/// e.g. 1.2.3 -> 1002003 (major followed by zero-padded three-digit minor and patch).
7780
#[serde(skip_serializing_if = "Option::is_none")]
7881
pub connectors_runtime_version_semver: Option<u32>,
82+
/// The unique identifier of the runtime process.
7983
pub process_id: u32,
84+
/// The CPU usage of the runtime process.
8085
pub cpu_usage: f32,
86+
/// The total CPU usage of the system, scoped to the cores this process may run on
87+
/// when confined by an affinity/cpuset mask.
8188
pub total_cpu_usage: f32,
89+
/// The memory usage of the runtime process in bytes.
8290
pub memory_usage: u64,
91+
/// The total memory of the system in bytes, or the effective cgroup memory limit when
92+
/// the runtime runs inside a memory-capped cgroup (container, systemd slice).
8393
pub total_memory: u64,
94+
/// The available memory of the system in bytes, scoped to the cgroup limit when one applies.
8495
pub available_memory: u64,
96+
/// The elapsed time since the runtime started, in microseconds.
8597
pub run_time: u64,
98+
/// The time the runtime started, in microseconds since the UNIX epoch.
8699
pub start_time: u64,
100+
/// The number of configured source connectors, including disabled and failed ones.
87101
pub sources_total: u32,
102+
/// The number of currently running source connectors.
88103
pub sources_running: u32,
104+
/// The number of configured sink connectors, including disabled and failed ones.
89105
pub sinks_total: u32,
106+
/// The number of currently running sink connectors.
90107
pub sinks_running: u32,
108+
/// Per-connector statistics for every configured source and sink.
91109
pub connectors: Vec<ConnectorStats>,
92110
}
93111

0 commit comments

Comments
 (0)