Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 261 additions & 8 deletions lustre-collector/src/mds/client_count_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,25 @@ use std::{collections::BTreeMap, ops::Add};
pub(crate) const EXPORTS: &str = "exports";

pub(crate) fn params() -> Vec<String> {
vec![format!("mdt.*.{}.*.uuid", EXPORTS)]
vec![
format!("mdt.*.{}.*.uuid", EXPORTS),
format!("obdfilter.*.{}.*.uuid", EXPORTS),
format!("mgs.MGS.{}.*.uuid", EXPORTS),
]
}

/// Derives the TargetVariant from the target name.
/// Target names contain their type: "-MDT" for MDT, "-OST" for OST, and "MGS" for MGT.
fn target_kind(target: &str) -> TargetVariant {
match target {
t if t.contains("-MDT") => TargetVariant::Mdt,
t if t.contains("-OST") => TargetVariant::Ost,
_ => TargetVariant::Mgt,
}
}

/// Parses client count data for MDT, OST, and MGT exports.
/// Aggregates client counts by target name and returns records for connected_clients metric.
pub(crate) fn parse<I>() -> impl Parser<I, Output = Vec<Record>>
where
I: Stream<Token = char>,
Expand All @@ -33,14 +49,13 @@ where
.map(|xs: Vec<_>| {
xs.into_iter().fold(BTreeMap::new(), |mut acc, (k, v)| {
acc.entry(k).and_modify(|x| *x += v).or_insert(v);

acc
})
})
.map(|hm| {
hm.into_iter()
.map(|(k, value)| TargetStat {
kind: TargetVariant::Mdt,
kind: target_kind(&k),
target: Target(k),
param: Param("connected_clients".into()),
value,
Expand All @@ -51,13 +66,19 @@ where
})
}

/// Parses a single interface export entry and returns the target name with client count.
/// Handles MDT (mdt.*), OST (obdfilter.*), and MGT (mgs.MGS) export formats.
fn interface_clients<I>() -> impl Parser<I, Output = (String, u64)>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
(
attempt(mdt_interface()),
choice((
attempt(mdt_interface()),
attempt(ost_interface()),
attempt(mgt_interface()),
)),
choice((
newline()
.with(sep_end_by(attempt(is_client()), newline()))
Expand Down Expand Up @@ -94,6 +115,7 @@ where
.map(drop)
}

/// Parses MDT interface export entry (e.g., "mdt.fs-MDT0000.exports.*.uuid").
fn mdt_interface<I>() -> impl Parser<I, Output = String>
where
I: Stream<Token = char>,
Expand All @@ -107,6 +129,34 @@ where
.map(|(_, x, _)| x)
}

/// Parses OST interface export entry (e.g., "obdfilter.fs-OST0000.exports.*.uuid").
fn ost_interface<I>() -> impl Parser<I, Output = String>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
(
string("obdfilter").skip(period()),
many1::<String, _, _>(alpha_num().or(one_of("_-".chars()))),
period().skip(exports()),
)
.map(|(_, x, _)| x)
}

/// Parses MGT interface export entry (e.g., "mgs.MGS.exports.*.uuid").
fn mgt_interface<I>() -> impl Parser<I, Output = String>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
(
string("mgs").skip(period()),
string("MGS"),
period().skip(exports()),
)
.map(|(_, x, _)| x.to_string())
}

#[cfg(test)]
mod test {
use super::*;
Expand Down Expand Up @@ -137,7 +187,12 @@ mod test {
.easy_parse("mdt.es01a-MDT0000.exports.0@lo.uuid=")
.unwrap();

assert_debug_snapshot!(result)
insta::assert_debug_snapshot!(result, @r###"
(
"es01a-MDT0000",
"",
)
"###);
}

#[test]
Expand All @@ -146,7 +201,15 @@ mod test {
.easy_parse("mdt.fs-MDT0000.exports.0@lo.uuid=es01a-MDT0000-lwp-MDT0000_UUID\n")
.unwrap();

assert_debug_snapshot!(result)
insta::assert_debug_snapshot!(result, @r###"
(
(
"fs-MDT0000",
0,
),
"",
)
"###);
}

#[test]
Expand All @@ -155,7 +218,15 @@ mod test {
.easy_parse("mdt.fs-MDT0000.exports.0@lo.uuid=a01e9c48-52f7-0c50-ff15-5aa13684bb5b\n")
.unwrap();

assert_debug_snapshot!(result)
insta::assert_debug_snapshot!(result, @r###"
(
(
"fs-MDT0000",
1,
),
"",
)
"###);
}

#[test]
Expand All @@ -175,7 +246,15 @@ a01e9c48-52f7-0c50-ff15-5aa13684bb5c

let result = interface_clients().easy_parse(x).unwrap();

assert_debug_snapshot!(result)
insta::assert_debug_snapshot!(result, @r###"
(
(
"fs-MDT0000",
5,
),
"",
)
"###);
}

#[test]
Expand Down Expand Up @@ -219,6 +298,25 @@ fs-MDT0000-lwp-OST0005_UUID
assert_debug_snapshot!(result)
}

#[test]
fn test_client_count_parser_trevis158_format() {
// Test the exact format from Trevis-158 where 0@lo has client UUID on next line
// followed by multiple internal UUIDs
let x = r#"mdt.fs-MDT0000.exports.0@lo.uuid=
c7f6f6cb-06fd-4e06-b837-513a6ee08fb5
fs-MDT0000-lwp-OST0001_UUID
fs-MDT0000-lwp-MDT0000_UUID
fs-MDT0000-lwp-OST0000_UUID
mdt.fs-MDT0000.exports.10.73.20.12@tcp.uuid=
fs-MDT0000-lwp-OST0003_UUID
fs-MDT0000-lwp-OST0002_UUID
"#;

let result = parse().easy_parse(x).unwrap();

assert_debug_snapshot!(result)
}

#[test]
fn test_client_count_parser_two_clients() {
let x = r#"mdt.fs-MDT0000.exports.0@lo.uuid=fs-MDT0000-lwp-MDT0000_UUID
Expand Down Expand Up @@ -281,4 +379,159 @@ mdt.fs2-MDT0000.exports.10.73.20.22@tcp.uuid=fs2-MDT0000-lwp-OST0001_UUID

assert_debug_snapshot!(result)
}

#[test]
fn test_ost_interface() {
let result = ost_interface()
.easy_parse("obdfilter.fs-OST0000.exports.0@lo.uuid=")
.unwrap();

insta::assert_debug_snapshot!(result, @r###"
(
"fs-OST0000",
"",
)
"###);
}

#[test]
fn test_ost_interface_clients() {
let result = interface_clients()
.easy_parse(
"obdfilter.fs-OST0000.exports.0@lo.uuid=a01e9c48-52f7-0c50-ff15-5aa13684bb5b\n",
)
.unwrap();

insta::assert_debug_snapshot!(result, @r###"
(
(
"fs-OST0000",
1,
),
"",
)
"###);
}

#[test]
fn test_ost_client_count_parser() {
let x = r#"obdfilter.fs-OST0000.exports.0@lo.uuid=fs-OST0000_UUID
obdfilter.fs-OST0000.exports.10.0.2.15@tcp.uuid=
613beb43-5df2-2ace-4209-be66b4b509df
568acc64-085e-ada1-d493-6318930dfa74
obdfilter.fs-OST0001.exports.0@lo.uuid=fs-OST0001_UUID
obdfilter.fs-OST0001.exports.10.0.2.15@tcp.uuid=
613beb43-5df2-2ace-4209-be66b4b509df
"#;

let result = parse().easy_parse(x).unwrap();

assert_debug_snapshot!(result);
}

#[test]
fn test_mgt_interface() {
let result = mgt_interface()
.easy_parse("mgs.MGS.exports.0@lo.uuid=")
.unwrap();

insta::assert_debug_snapshot!(result, @r###"
(
"MGS",
"",
)
"###);
}

#[test]
fn test_mgt_interface_clients() {
let result = interface_clients()
.easy_parse("mgs.MGS.exports.0@lo.uuid=a01e9c48-52f7-0c50-ff15-5aa13684bb5b\n")
.unwrap();

insta::assert_debug_snapshot!(result, @r###"
(
(
"MGS",
1,
),
"",
)
"###);
}

#[test]
fn test_mgt_client_count_parser() {
let x = r#"mgs.MGS.exports.0@lo.uuid=MGS_UUID
mgs.MGS.exports.10.0.2.15@tcp.uuid=
613beb43-5df2-2ace-4209-be66b4b509df
568acc64-085e-ada1-d493-6318930dfa74
"#;

let result = parse().easy_parse(x).unwrap();

assert_debug_snapshot!(result);
}

#[test]
fn test_mixed_targets_client_count() {
let x = r#"mdt.fs-MDT0000.exports.0@lo.uuid=fs-MDT0000-lwp-MDT0000_UUID
mdt.fs-MDT0000.exports.10.0.2.15@tcp.uuid=
613beb43-5df2-2ace-4209-be66b4b509df
obdfilter.fs-OST0000.exports.0@lo.uuid=fs-OST0000_UUID
obdfilter.fs-OST0000.exports.10.0.2.15@tcp.uuid=
613beb43-5df2-2ace-4209-be66b4b509df
mgs.MGS.exports.0@lo.uuid=MGS_UUID
mgs.MGS.exports.10.0.2.15@tcp.uuid=
613beb43-5df2-2ace-4209-be66b4b509df
"#;

let result = parse().easy_parse(x).unwrap();

assert_debug_snapshot!(result);
}

#[test]
fn test_production_inline_uuid_format() {
// Real production data showing inline UUID format for OST exports
// This tests the case where UUIDs appear on the same line as the export path
let x = r#"obdfilter.sfa18k26-OST0000.exports.0@lo.uuid=sfa18k26-MDT0000-mdtlov_UUID
obdfilter.sfa18k26-OST0000.exports.172.25.80.30@tcp.uuid=326aea2c-009f-400b-b8f9-7df49504fbd0
obdfilter.sfa18k26-OST0000.exports.172.25.80.84@o2ib.uuid=sfa18k26-MDT0001-mdtlov_UUID
obdfilter.sfa18k26-OST0000.exports.172.25.80.90@o2ib.uuid=sfa18k26-MDT0002-mdtlov_UUID
obdfilter.sfa18k26-OST0000.exports.172.25.80.92@o2ib.uuid=sfa18k26-MDT0003-mdtlov_UUID
mgs.MGS.exports.0@lo.uuid=893f59e7-eb98-4898-a972-5f3b8273ed46
mgs.MGS.exports.172.25.80.29@tcp.uuid=c13b8c2a-f6cc-4b1d-a955-05e603f1ed26
mgs.MGS.exports.172.25.80.30@tcp.uuid=ccbde25b-bd34-4601-b3bf-cb8704ed9266
"#;

let result = parse().easy_parse(x).unwrap();

assert_debug_snapshot!(result);
}

#[test]
fn test_trevis158_actual_full_output() {
// EXACT production output from Trevis-158 node1
// This includes both MDT and OST exports
let x = r#"mdt.fs-MDT0000.exports.0@lo.uuid=
c7f6f6cb-06fd-4e06-b837-513a6ee08fb5
fs-MDT0000-lwp-OST0001_UUID
fs-MDT0000-lwp-MDT0000_UUID
fs-MDT0000-lwp-OST0000_UUID
mdt.fs-MDT0000.exports.10.73.20.12@tcp.uuid=
fs-MDT0000-lwp-OST0003_UUID
fs-MDT0000-lwp-OST0002_UUID
fs-MDT0001-mdtlov_UUID
fs-MDT0000-lwp-MDT0001_UUID
obdfilter.fs-OST0000.exports.0@lo.uuid=fs-MDT0000-mdtlov_UUID
obdfilter.fs-OST0000.exports.10.73.20.12@tcp.uuid=fs-MDT0001-mdtlov_UUID
obdfilter.fs-OST0001.exports.0@lo.uuid=fs-MDT0000-mdtlov_UUID
obdfilter.fs-OST0001.exports.10.73.20.12@tcp.uuid=fs-MDT0001-mdtlov_UUID
"#;

let result = parse().easy_parse(x).unwrap();

assert_debug_snapshot!(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: lustre-collector/src/mds/client_count_parser.rs
expression: result
---
(
[
Target(
ConnectedClients(
TargetStat {
kind: Mdt,
param: Param(
"connected_clients",
),
target: Target(
"fs-MDT0000",
),
value: 1,
},
),
),
],
"",
)

This file was deleted.

Loading
Loading