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.
Implement osd quota stats Fix test Add fixtures Add QuotaManager enum and removed "glb-" from qmt_stat Fix typo in QMTStat::Prj assignement Fix wording Signed-off-by: Joe Grund <jgrund@whamcloud.io>
- Loading branch information
Showing
12 changed files
with
8,463 additions
and
7 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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::period, Record}; | ||
use combine::{parser::char::string, ParseError, Parser, Stream}; | ||
|
||
pub(crate) mod quota_parser; | ||
|
||
pub(crate) const QMT: &str = "qmt"; | ||
|
||
pub(crate) fn params() -> Vec<String> { | ||
quota_parser::params() | ||
} | ||
|
||
pub(crate) fn parse<I>() -> impl Parser<I, Output = Record> | ||
where | ||
I: Stream<Token = char>, | ||
I::Error: ParseError<I::Token, I::Range, I::Position>, | ||
{ | ||
(string(QMT), period()).with(quota_parser::qmt_parse()) | ||
} |
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,214 @@ | ||
// 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::{param, period, target}, | ||
quota::QMT, | ||
types::{Param, Record, Target, TargetStats}, | ||
QuotaKind, QuotaStat, QuotaStatOsd, QuotaStats, TargetQuotaStat, | ||
}; | ||
use combine::{ | ||
attempt, choice, eof, | ||
error::{ParseError, StreamError}, | ||
many, one_of, optional, | ||
parser::{ | ||
char::{alpha_num, newline, string}, | ||
repeat::take_until, | ||
}, | ||
stream::{Stream, StreamErrorFor}, | ||
token, Parser, | ||
}; | ||
|
||
pub(crate) const USR_QUOTAS: &str = "usr"; | ||
pub(crate) const PRJ_QUOTAS: &str = "prj"; | ||
pub(crate) const GRP_QUOTAS: &str = "grp"; | ||
pub(crate) const QMT_STATS: [&str; 3] = [USR_QUOTAS, PRJ_QUOTAS, GRP_QUOTAS]; | ||
|
||
/// Takes QMT_STATS and produces a list of params for | ||
/// consumption in proper ltcl get_param format. | ||
pub(crate) fn params() -> Vec<String> { | ||
QMT_STATS | ||
.iter() | ||
.map(|x| format!("{QMT}.*.*.glb-{x}")) | ||
.collect() | ||
} | ||
|
||
/// Parses a target name | ||
pub(crate) fn qmt_pool<I>() -> impl Parser<I, Output = (Target, Target)> | ||
where | ||
I: Stream<Token = char>, | ||
I::Error: ParseError<I::Token, I::Range, I::Position>, | ||
{ | ||
( | ||
choice(( | ||
string("md").skip(token('-')).map(|x| Target(x.to_string())), | ||
string("dt").skip(token('-')).map(|x| Target(x.to_string())), | ||
)), | ||
target(), | ||
) | ||
} | ||
|
||
/// Parses the name of a target | ||
fn qmt_target<I>() -> impl Parser<I, Output = (Target, Target, Target)> | ||
where | ||
I: Stream<Token = char>, | ||
I::Error: ParseError<I::Token, I::Range, I::Position>, | ||
{ | ||
(target().skip(period()), qmt_pool().skip(period())) | ||
.map(|(target, (manager, pool))| (target, manager, pool)) | ||
.message("while parsing target_name") | ||
} | ||
|
||
pub(crate) fn quota_stats<I>() -> impl Parser<I, Output = Vec<QuotaStat>> | ||
where | ||
I: Stream<Token = char>, | ||
I::Error: ParseError<I::Token, I::Range, I::Position>, | ||
{ | ||
( | ||
optional(newline()), // If quota stats are present, the whole yaml blob will start on a newline | ||
many::<Vec<_>, _, _>(alpha_num().or(one_of("_-:".chars()))), // But yaml header might not be indented, ignore it | ||
newline(), | ||
take_until(attempt((newline(), alpha_num()).map(drop).or(eof()))), | ||
) | ||
.skip(optional(newline())) | ||
.skip(optional(eof())) | ||
.and_then(|(_, _, _, x): (_, _, _, String)| { | ||
serde_yaml::from_str::<Vec<QuotaStat>>(&x).map_err(StreamErrorFor::<I>::other) | ||
}) | ||
} | ||
|
||
pub(crate) fn quota_stats_osd<I>() -> impl Parser<I, Output = Vec<QuotaStatOsd>> | ||
where | ||
I: Stream<Token = char>, | ||
I::Error: ParseError<I::Token, I::Range, I::Position>, | ||
{ | ||
( | ||
optional(newline()), // If quota stats are present, the whole yaml blob will start on a newline | ||
many::<Vec<_>, _, _>(alpha_num().or(one_of("_-:".chars()))), // But yaml header might not be indented, ignore it | ||
newline(), | ||
take_until(attempt((newline(), alpha_num()).map(drop).or(eof()))), | ||
) | ||
.skip(optional(newline())) | ||
.skip(optional(eof())) | ||
.and_then(|(_, _, _, x): (_, _, _, String)| { | ||
serde_yaml::from_str::<Vec<QuotaStatOsd>>(&x).map_err(StreamErrorFor::<I>::other) | ||
}) | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum QMTStat { | ||
Usr(Vec<QuotaStat>), | ||
Prj(Vec<QuotaStat>), | ||
Grp(Vec<QuotaStat>), | ||
} | ||
|
||
pub(crate) fn qmt_stat<I>() -> impl Parser<I, Output = (Param, QMTStat)> | ||
where | ||
I: Stream<Token = char>, | ||
I::Error: ParseError<I::Token, I::Range, I::Position>, | ||
{ | ||
( | ||
string("glb-"), | ||
choice(( | ||
(param(USR_QUOTAS), quota_stats().map(QMTStat::Usr)), | ||
(param(PRJ_QUOTAS), quota_stats().map(QMTStat::Prj)), | ||
(param(GRP_QUOTAS), quota_stats().map(QMTStat::Grp)), | ||
)), | ||
) | ||
.map(|(_, param)| (param)) | ||
} | ||
pub(crate) fn qmt_parse<I>() -> impl Parser<I, Output = Record> | ||
where | ||
I: Stream<Token = char>, | ||
I::Error: ParseError<I::Token, I::Range, I::Position>, | ||
{ | ||
(qmt_target(), qmt_stat()) | ||
.map( | ||
|((target, Target(manager), Target(pool)), (param, value))| match value { | ||
QMTStat::Usr(stats) => TargetStats::QuotaStats(TargetQuotaStat { | ||
pool, | ||
manager, | ||
target, | ||
param, | ||
value: QuotaStats { | ||
kind: QuotaKind::Usr, | ||
stats, | ||
}, | ||
}), | ||
QMTStat::Prj(stats) => TargetStats::QuotaStats(TargetQuotaStat { | ||
pool, | ||
manager, | ||
target, | ||
param, | ||
value: QuotaStats { | ||
kind: QuotaKind::Prj, | ||
stats, | ||
}, | ||
}), | ||
QMTStat::Grp(stats) => TargetStats::QuotaStats(TargetQuotaStat { | ||
pool, | ||
manager, | ||
target, | ||
param, | ||
value: QuotaStats { | ||
kind: QuotaKind::Grp, | ||
stats, | ||
}, | ||
}), | ||
}, | ||
) | ||
.map(Record::Target) | ||
.message("while parsing qmt") | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::{QuotaStat, QuotaStatLimits}; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_qmt_params() { | ||
assert_eq!( | ||
params(), | ||
vec![ | ||
"qmt.*.*.glb-usr".to_string(), | ||
"qmt.*.*.glb-prj".to_string(), | ||
"qmt.*.*.glb-grp".to_string(), | ||
] | ||
) | ||
} | ||
|
||
#[test] | ||
fn test_yaml_deserialize() { | ||
let x = r#" | ||
- id: 0 | ||
limits: { hard: 0, soft: 0, granted: 0, time: 604800 } | ||
- id: 1337 | ||
limits: { hard: 309200, soft: 307200, granted: 1025032, time: 1687277628 }"#; | ||
|
||
let expected = vec![ | ||
QuotaStat { | ||
id: 0, | ||
limits: QuotaStatLimits { | ||
hard: 0, | ||
soft: 0, | ||
granted: 0, | ||
time: 604800, | ||
}, | ||
}, | ||
QuotaStat { | ||
id: 1337, | ||
limits: QuotaStatLimits { | ||
hard: 309200, | ||
soft: 307200, | ||
granted: 1025032, | ||
time: 1687277628, | ||
}, | ||
}, | ||
]; | ||
|
||
assert_eq!(serde_yaml::from_str::<Vec<QuotaStat>>(x).unwrap(), expected) | ||
} | ||
} |
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
Oops, something went wrong.