This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add mdd metrics Add missing snapshot * Update src/mdd_parser.rs --------- Co-authored-by: Joe Grund <jgrund@whamcloud.io>
- Loading branch information
Showing
11 changed files
with
273 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mdd.ai400x2-MDT0000.changelog_users= | ||
current_index: 0 | ||
ID index (idle) mask | ||
cl1 0 (327) | ||
mdd.ai400x2-MDT0001.changelog_users= | ||
current_index: 0 | ||
ID index (idle) mask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// Copyright (c) 2024 DDN. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
use crate::{ | ||
base_parsers::{digits, param, period, target, till_newline, till_period}, | ||
types::{Param, Record, Target, TargetStat, TargetStats, TargetVariant}, | ||
ChangeLogUser, ChangelogStat, | ||
}; | ||
use combine::{ | ||
attempt, choice, | ||
error::{ParseError, StreamError}, | ||
many, | ||
parser::char::{newline, spaces, string}, | ||
stream::{Stream, StreamErrorFor}, | ||
token, Parser, | ||
}; | ||
|
||
pub(crate) const MDD: &str = "mdd"; | ||
pub(crate) const CHANGELOG_USERS: &str = "changelog_users"; | ||
pub(crate) fn params() -> Vec<String> { | ||
vec![format!("{MDD}.*.{CHANGELOG_USERS}")] | ||
} | ||
|
||
#[derive(Debug)] | ||
enum MddStat { | ||
/// Changelog stat | ||
ChangeLog(ChangelogStat), | ||
} | ||
|
||
fn target_and_variant<I>() -> impl Parser<I, Output = (Target, TargetVariant)> | ||
where | ||
I: Stream<Token = char>, | ||
I::Error: ParseError<I::Token, I::Range, I::Position>, | ||
{ | ||
( | ||
attempt(string("mdd").skip(till_period())).skip(period()), | ||
target().skip(period()), | ||
) | ||
.and_then(move |(_, x)| -> Result<_, _> { | ||
let variant = match (&x).try_into() { | ||
Ok(x) => x, | ||
Err(e) => return Err(StreamErrorFor::<I>::other(e)), | ||
}; | ||
|
||
Ok((x, variant)) | ||
}) | ||
.message("while parsing target_and_variant") | ||
} | ||
|
||
fn table_headers<I>() -> impl Parser<I, Output = ()> | ||
where | ||
I: Stream<Token = char>, | ||
I::Error: ParseError<I::Token, I::Range, I::Position>, | ||
{ | ||
(string("ID"), till_newline()).map(|_| ()) | ||
} | ||
|
||
fn table_rows<I>() -> impl Parser<I, Output = Vec<ChangeLogUser>> | ||
where | ||
I: Stream<Token = char>, | ||
I::Error: ParseError<I::Token, I::Range, I::Position>, | ||
{ | ||
many(attempt(( | ||
target(), | ||
spaces(), | ||
digits(), | ||
spaces(), | ||
token('('), | ||
digits(), | ||
token(')'), | ||
till_newline().skip(newline()), | ||
))) | ||
.map(|x: Vec<_>| { | ||
x.iter() | ||
.map(|x| ChangeLogUser { | ||
user: x.0.to_string(), | ||
index: x.2, | ||
idle_secs: x.5, | ||
}) | ||
.collect() | ||
}) | ||
} | ||
|
||
fn mdd_stat<I>() -> impl Parser<I, Output = (Param, MddStat)> | ||
where | ||
I: Stream<Token = char>, | ||
I::Error: ParseError<I::Token, I::Range, I::Position>, | ||
{ | ||
choice((( | ||
param(CHANGELOG_USERS), | ||
( | ||
newline(), | ||
string("current_index: "), | ||
digits(), | ||
newline(), | ||
table_headers(), | ||
newline(), | ||
table_rows(), | ||
) | ||
.map(|(_, _, x, _, _, _, y)| { | ||
MddStat::ChangeLog(ChangelogStat { | ||
current_index: x, | ||
users: y, | ||
}) | ||
}), | ||
) | ||
.message("while parsing changelog"),)) | ||
} | ||
|
||
pub(crate) fn parse<I>() -> impl Parser<I, Output = Record> | ||
where | ||
I: Stream<Token = char>, | ||
I::Error: ParseError<I::Token, I::Range, I::Position>, | ||
{ | ||
(target_and_variant(), mdd_stat()) | ||
.map(|((target, kind), (param, stat))| match stat { | ||
MddStat::ChangeLog(value) => TargetStats::Changelog(TargetStat { | ||
kind, | ||
target, | ||
param, | ||
value, | ||
}), | ||
}) | ||
.map(Record::Target) | ||
.message("while parsing mdd") | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use combine::{many, EasyParser}; | ||
use insta::assert_debug_snapshot; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_mdd_stats() { | ||
static FIXTURE: &str = include_str!("../fixtures/mdd.txt"); | ||
|
||
let result = many::<Vec<_>, _, _>(parse()) | ||
.easy_parse(FIXTURE) | ||
.map_err(|err| err.map_position(|p| p.translate_position(FIXTURE))) | ||
.unwrap(); | ||
|
||
assert_debug_snapshot!(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/snapshots/lustre_collector__mdd_parser__tests__mdd_stats.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
source: src/mdd_parser.rs | ||
expression: result | ||
--- | ||
( | ||
[ | ||
Target( | ||
Changelog( | ||
TargetStat { | ||
kind: Mdt, | ||
param: Param( | ||
"changelog_users", | ||
), | ||
target: Target( | ||
"ai400x2-MDT0000", | ||
), | ||
value: ChangelogStat { | ||
current_index: 0, | ||
users: [ | ||
ChangeLogUser { | ||
user: "cl1", | ||
index: 0, | ||
idle_secs: 327, | ||
}, | ||
], | ||
}, | ||
}, | ||
), | ||
), | ||
Target( | ||
Changelog( | ||
TargetStat { | ||
kind: Mdt, | ||
param: Param( | ||
"changelog_users", | ||
), | ||
target: Target( | ||
"ai400x2-MDT0001", | ||
), | ||
value: ChangelogStat { | ||
current_index: 0, | ||
users: [], | ||
}, | ||
}, | ||
), | ||
), | ||
], | ||
"", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters