Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
33 changes: 26 additions & 7 deletions lustre-collector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ pub use node_stats_parsers::{parse_cpustats_output, parse_meminfo_output};
use std::{io, str};
pub use types::*;

fn check_output(records: Vec<Record>, state: &str) -> Result<Vec<Record>, LustreCollectorError> {
let params = crate::parser::params().join(" ");

fn check_output(
records: Vec<Record>,
state: &str,
params: &str,
) -> Result<Vec<Record>, LustreCollectorError> {
if !state.is_empty() {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
Expand All @@ -53,7 +55,9 @@ pub fn parse_lctl_output(lctl_output: &[u8]) -> Result<Vec<Record>, LustreCollec
.easy_parse(lctl_stats)
.map_err(|err| err.map_position(|p| p.translate_position(lctl_stats)))?;

check_output(lctl_record, state)
let params = parser::params().join(" ");

check_output(lctl_record, state, &params)
}

pub fn parse_mgs_fs_output(mgs_fs_output: &[u8]) -> Result<Vec<Record>, LustreCollectorError> {
Expand All @@ -63,7 +67,9 @@ pub fn parse_mgs_fs_output(mgs_fs_output: &[u8]) -> Result<Vec<Record>, LustreCo
.easy_parse(mgs_fs)
.map_err(|err| err.map_position(|p| p.translate_position(mgs_fs)))?;

check_output(mgs_fs_record, state)
let params = mgs::mgs_fs_parser::params().join(" ");

check_output(mgs_fs_record, state, &params)
}

pub fn parse_recovery_status_output(
Expand All @@ -76,12 +82,14 @@ pub fn parse_recovery_status_output(
.easy_parse(recovery_status)
.map_err(|err| err.map_position(|p| p.translate_position(recovery_status)))?;

check_output(recovery_statuses, state)
let params = recovery_status_parser::params().join(" ");

check_output(recovery_statuses, state, &params)
}

#[cfg(test)]
mod tests {
use super::{Record, parse_lctl_output};
use crate::{Record, parse_lctl_output, parse_recovery_status_output};

#[test]
fn ex8761_job_stats() {
Expand All @@ -94,6 +102,17 @@ mod tests {
assert_eq!(expected, z);
}

#[test]
fn test_parse_recovery_status_output() {
let xs = include_bytes!("./fixtures/recovery-multiple.txt");
let expected = parse_recovery_status_output(xs).unwrap();

let y = serde_json::to_string(&expected).unwrap();
let z: Vec<Record> = serde_json::from_str(&y).unwrap();

assert_eq!(expected, z);
}

#[test]
fn es_6_2_0_job_stats_unhealthy() {
let xs = include_bytes!("./fixtures/valid/params-6.2.0-r9.txt");
Expand Down
11 changes: 7 additions & 4 deletions lustre-collector/src/recovery_status_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,14 @@ where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
(
target_status(),
skip_until(attempt(ost_or_mdt().map(drop)).or(eof())),
many1(
(
target_status(),
skip_until(attempt(ost_or_mdt().map(drop)).or(eof())),
)
.map(|(x, _)| x),
)
.map(|(x, _)| x.into_iter().map(Record::Target).collect())
.map(|xs: Vec<Vec<TargetStats>>| xs.into_iter().flatten().map(Record::Target).collect())
}

#[cfg(test)]
Expand Down
Loading