Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Exports stats (#57)
Browse files Browse the repository at this point in the history
* Export stats

* Add new fixture

* Add unit test

* Do not update existing fixture

* Apply suggestions from code review

---------

Co-authored-by: Joe Grund <jgrund@whamcloud.io>
  • Loading branch information
RDruon and jgrund authored May 7, 2024
1 parent 44b440c commit 9261318
Show file tree
Hide file tree
Showing 12 changed files with 16,459 additions and 16 deletions.
28 changes: 20 additions & 8 deletions src/base_parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ where
take_until(period())
}

pub(crate) fn till_equals<I>() -> impl Parser<I, Output = String>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
take_until(equals())
}

pub(crate) fn string_to<I>(x: &'static str, y: &'static str) -> impl Parser<I, Output = String>
where
I: Stream<Token = char>,
Expand Down Expand Up @@ -120,6 +112,16 @@ where
.message("while getting param")
}

pub(crate) fn param_period<I>(x: &'static str) -> impl Parser<I, Output = Param>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
attempt(string(x).skip(token('.')))
.map(|x| Param(x.to_string()))
.message("while getting param")
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -131,4 +133,14 @@ mod tests {

assert_eq!(result, Ok((Param("memused".to_string()), "77991501\n")))
}

#[test]
fn test_param_period() {
let result = param_period("exports").parse("exports.1.2.3.130@o2ib.stats=Y\n");

assert_eq!(
result,
Ok((Param("exports".to_string()), "1.2.3.130@o2ib.stats=Y\n"))
)
}
}
56 changes: 56 additions & 0 deletions src/exports_parser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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::{equals, period},
stats_parser::stats,
ExportStats,
};
use combine::{
attempt,
error::ParseError,
many, many1,
parser::char::{alpha_num, string},
stream::Stream,
token, Parser,
};

/// Parses a single nid
pub(crate) fn nid<I>() -> impl Parser<I, Output = String>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
(
many1::<String, _, _>(alpha_num().or(period())),
token('@'),
many1::<String, _, _>(alpha_num()),
)
.map(|(ip, _, lnet)| format!("{ip}@{lnet}"))
.message("while parsing nid")
}

/// Parses a single obdfilter.*OST*.exports.*.stats line
fn exports_stat<I>() -> impl Parser<I, Output = ExportStats>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
attempt((
nid().skip(period()),
string("stats").skip(equals()),
stats(),
))
.map(|(nid, _, stats)| ExportStats { nid, stats })
.message("while parsing export_stats")
}

/// Parses multiple obdfilter.*OST*.exports.*.stats lines
pub(crate) fn exports_stats<I>() -> impl Parser<I, Output = Vec<ExportStats>>
where
I: Stream<Token = char>,
I::Error: ParseError<I::Token, I::Range, I::Position>,
{
(many(exports_stat())).map(|x| x)
}
Loading

0 comments on commit 9261318

Please sign in to comment.