Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Remove "Other" bucket (#2306)
Browse files Browse the repository at this point in the history
Latest version of lipe does not return Other bucket.
Update IML to not account for it on agent-side.

Signed-off-by: Joe Grund <jgrund@whamcloud.io>
  • Loading branch information
jgrund authored Oct 6, 2020
1 parent 3a7da93 commit 4dd86e5
Showing 1 changed file with 160 additions and 25 deletions.
185 changes: 160 additions & 25 deletions iml-agent/src/action_plugins/stratagem/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

use crate::{agent_error::ImlAgentError, http_comms::streaming_client};
use crate::{agent_error::ImlAgentError, agent_error::RequiredError, http_comms::streaming_client};
use futures::{future, stream, StreamExt, TryStreamExt};
use iml_cmd::{CheckedCommandExt, Command};
use iml_fs::{read_file_to_end, stream_dir_lines, write_tempfile};
Expand Down Expand Up @@ -289,7 +289,7 @@ pub fn get_mailbox_files(
base_dir: &str,
stratagem_data: &StratagemConfig,
stratagem_result: &StratagemResult,
) -> MailboxFiles {
) -> Result<MailboxFiles, ImlAgentError> {
stratagem_result
.group_counters
.iter()
Expand All @@ -303,22 +303,30 @@ pub fn get_mailbox_files(
.map(move |(idx, counter)| {
let group = stratagem_data
.get_group_by_name(&group.name)
.unwrap_or_else(|| panic!("did not find group by name {}", group.name));

let rule = group
.get_rule_by_idx(idx - 1)
.unwrap_or_else(|| panic!("did not find rule by idx {}", idx - 1));
.ok_or_else(|| {
ImlAgentError::RequiredError(RequiredError(format!(
"Did not find group by name {}",
group.name
)))
})?;

let rule = group.get_rule_by_idx(idx).ok_or_else(|| {
ImlAgentError::RequiredError(RequiredError(format!(
"did not find rule by idx {}",
idx
)))
})?;

let p = [base_dir, &group.name, &counter.name()]
.iter()
.cloned()
.collect::<PathBuf>();

(p, format!("{}-{}", group.name, rule.argument))
Ok((p, format!("{}-{}", group.name, rule.argument)))
})
})
.flatten()
.collect()
.collect::<Result<Vec<_>, _>>()
}

/// Triggers a scan with Stratagem.
Expand Down Expand Up @@ -352,7 +360,7 @@ pub async fn trigger_scan(

let x = serde_json::from_slice(&xs)?;

let mailbox_files = get_mailbox_files(&tmp_dir, &data, &x);
let mailbox_files = get_mailbox_files(&tmp_dir, &data, &x)?;

Ok((tmp_dir, x, mailbox_files))
}
Expand Down Expand Up @@ -451,13 +459,6 @@ mod tests {
StratagemGroupResult {
name: "size_distribution".into(),
counters: vec![
StratagemCounters::StratagemCounter(StratagemCounter {
count: 1,
blocks: 0,
size: 0,
flist_type: "none".into(),
name: "Other".into(),
}),
StratagemCounters::StratagemCounter(StratagemCounter {
count: 0,
blocks: 0,
Expand Down Expand Up @@ -491,13 +492,6 @@ mod tests {
StratagemGroupResult {
name: "warn_purge_times".into(),
counters: vec![
StratagemCounters::StratagemCounter(StratagemCounter {
count: 2,
blocks: 0,
size: 0,
flist_type: "none".into(),
name: "Other".into(),
}),
StratagemCounters::StratagemCounter(StratagemCounter {
count: 0,
blocks: 0,
Expand All @@ -517,7 +511,7 @@ mod tests {
],
};

let actual = get_mailbox_files("foo_bar", &stratagem_data, &stratagem_result);
let actual = get_mailbox_files("foo_bar", &stratagem_data, &stratagem_result).unwrap();

assert_eq!(
actual,
Expand All @@ -533,4 +527,145 @@ mod tests {
]
);
}

#[test]
fn test_get_filesync() {
let stratagem_data = StratagemConfig {
flist_type: "none".into(),
device: StratagemDevice {
path: "/dev/mapper/vg_mdt0000_es01a-mdt0000".into(),
groups: vec![
"size_distribution".into(),
"user_distribution".into(),
"filesync".into(),
],
},
groups: vec![
StratagemGroup {
rules: vec![
StratagemRule {
action: "LAT_COUNTER_INC".into(),
expression: "&& < size 1048576 != type S_IFDIR".into(),
argument: "SIZE < 1M".into(),
counter_name: None,
},
StratagemRule {
action: "LAT_COUNTER_INC".into(),
expression: "&& >= size 1048576000000 != type S_IFDIR".into(),
argument: "SIZE >= 1T".into(),
counter_name: None,
},
StratagemRule {
action: "LAT_COUNTER_INC".into(),
expression: "&& >= size 1048576000 != type S_IFDIR".into(),
argument: "SIZE >= 1G".into(),
counter_name: None,
},
StratagemRule {
action: "LAT_COUNTER_INC".into(),
expression: "&& >= size 1048576 != type S_IFDIR".into(),
argument: "1M <= SIZE < 1G".into(),
counter_name: None,
},
],
name: "size_distribution".into(),
},
StratagemGroup {
rules: vec![StratagemRule {
action: "LAT_ATTR_CLASSIFY".into(),
counter_name: Some("top_inode_users".into()),
expression: "!= type S_IFDIR".into(),
argument: "uid".into(),
}],
name: "user_distribution".into(),
},
StratagemGroup {
rules: vec![StratagemRule {
action: "LAT_SHELL_CMD_FID".into(),
counter_name: Some("filesync".into()),
expression: "size > 1".into(),
argument: "filesync".into(),
}],
name: "filesync".into(),
},
],
summarize_size: true,
};

let stratagem_result = StratagemResult {
group_counters: vec![
StratagemGroupResult {
name: "size_distribution".into(),
counters: vec![
StratagemCounters::StratagemCounter(StratagemCounter {
name: "SIZE < 1M".into(),
count: 0,
flist_type: "none".into(),
size: 0,
blocks: 0,
}),
StratagemCounters::StratagemCounter(StratagemCounter {
name: "SIZE >= 1T".into(),
count: 0,
flist_type: "none".into(),
size: 0,
blocks: 0,
}),
StratagemCounters::StratagemCounter(StratagemCounter {
name: "SIZE >= 1G".into(),
count: 0,
flist_type: "none".into(),
size: 0,
blocks: 0,
}),
StratagemCounters::StratagemCounter(StratagemCounter {
name: "1M <= SIZE < 1G".into(),
count: 0,
flist_type: "none".into(),
size: 0,
blocks: 0,
}),
],
},
StratagemGroupResult {
name: "user_distribution".into(),
counters: vec![StratagemCounters::StratagemClassifyCounter(
StratagemClassifyCounter {
name: "top_inode_users".into(),
count: 0,
flist_type: "none".into(),
size: 0,
blocks: 0,
expression: "!= type S_IFDIR".into(),
classify: StratagemClassifyResult {
attr_type: "uid".into(),
flist_type: "none".into(),
counters: vec![],
},
},
)],
},
StratagemGroupResult {
name: "filesync".into(),
counters: vec![StratagemCounters::StratagemCounter(StratagemCounter {
name: "filesync".into(),
count: 0,
flist_type: "fid".into(),
size: 0,
blocks: 0,
})],
},
],
};

let actual = get_mailbox_files("foo_bar", &stratagem_data, &stratagem_result).unwrap();

assert_eq!(
actual,
vec![(
PathBuf::from("foo_bar/filesync/filesync"),
"filesync-filesync".into()
)]
);
}
}

0 comments on commit 4dd86e5

Please sign in to comment.