Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of labeled hosts by pbench-postprocess-tools (fwd port of #3456) #3472

Merged
merged 7 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion agent/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.72.0
dbutenhof marked this conversation as resolved.
Show resolved Hide resolved
0.72.1
25 changes: 25 additions & 0 deletions agent/util-scripts/gold/pbench-postprocess-tools/test-07.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
+++ Running test-07.1 pbench-postprocess-tools --group=foobar --dir=/var/tmp/pbench-test-utils/pbench/42-iter/sample42
--- Finished test-07.1 pbench-postprocess-tools (status=0)
iostat: post-processing data
+++ pbench tree state
/var/tmp/pbench-test-utils/pbench
/var/tmp/pbench-test-utils/pbench/42-iter
/var/tmp/pbench-test-utils/pbench/42-iter/sample42
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com/iostat
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com/iostat/csv
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com/iostat/iostat-postprocess.err
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com/iostat/iostat-postprocess.out
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com/iostat/iostat-stdout.txt
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com/postprocess.log
/var/tmp/pbench-test-utils/pbench/tmp
/var/tmp/pbench-test-utils/pbench/tools-v1-foobar
/var/tmp/pbench-test-utils/pbench/tools-v1-foobar/testhost.example.com
/var/tmp/pbench-test-utils/pbench/tools-v1-foobar/testhost.example.com/foo
/var/tmp/pbench-test-utils/pbench/tools-v1-foobar/testhost.example.com/iostat
=== /var/tmp/pbench-test-utils/pbench/tools-v1-foobar/testhost.example.com/foo:
--interval=10
=== /var/tmp/pbench-test-utils/pbench/tools-v1-foobar/testhost.example.com/iostat:
--interval=10
--- pbench tree state
14 changes: 7 additions & 7 deletions agent/util-scripts/gold/pbench-postprocess-tools/test-07.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ iostat: post-processing data
/var/tmp/pbench-test-utils/pbench/42-iter
/var/tmp/pbench-test-utils/pbench/42-iter/sample42
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com/iostat
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com/iostat/csv
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com/iostat/iostat-postprocess.err
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com/iostat/iostat-postprocess.out
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com/iostat/iostat-stdout.txt
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/testhost.example.com/postprocess.log
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/bar:testhost.example.com
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/bar:testhost.example.com/iostat
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/bar:testhost.example.com/iostat/csv
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/bar:testhost.example.com/iostat/iostat-postprocess.err
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/bar:testhost.example.com/iostat/iostat-postprocess.out
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/bar:testhost.example.com/iostat/iostat-stdout.txt
/var/tmp/pbench-test-utils/pbench/42-iter/sample42/tools-foobar/bar:testhost.example.com/postprocess.log
/var/tmp/pbench-test-utils/pbench/tmp
/var/tmp/pbench-test-utils/pbench/tools-v1-foobar
/var/tmp/pbench-test-utils/pbench/tools-v1-foobar/testhost.example.com
Expand Down
14 changes: 10 additions & 4 deletions agent/util-scripts/pbench-postprocess-tools
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@ fi
let failures=0
pbench-list-tools --group ${group} --with-option 2>/dev/null | while read hostentry ;do
# Parse an entry from the output of `pbench-list-tools` above.
# The format is: "group: <group>; host: <host>; tools: <tool> <options, <tool> <options>, ...
# The format is: "group: <group>; host: <host> [, label: <label>]; tools: <tool> <options, <tool> <options>, ...
webbnh marked this conversation as resolved.
Show resolved Hide resolved
IFS=';' read group_spec host_spec tools_spec <<<"${hostentry}"
IFS=':' read dummy host junk <<<"${host_spec}"
IFS=',' read hostpart labelpart <<<"${host_spec}"
IFS=':' read dummy host junk <<<"${hostpart}"
IFS=':' read dummy label junk <<<"${labelpart}"
IFS=':' read dummy tools_entry junk <<<"${tools_spec}"
host=${host# *}
label=${label# *}
# Associative array: the keys are the tool names, and the values are the options
declare -A tools=()
IFS=',' read -a otools <<<"${tools_entry# *}"
Expand All @@ -100,8 +103,11 @@ pbench-list-tools --group ${group} --with-option 2>/dev/null | while read hosten
tools[${atool[0]}]=${atool[@]:1}
done

# FIXME: add support for label applied to the hostname directory.
host_tool_output_dir="${tool_output_dir}/${host}"
if [[ -z "${label}" ]] ;then
host_tool_output_dir="${tool_output_dir}/${host}"
else
host_tool_output_dir="${tool_output_dir}/${label}:${host}"
fi
if [[ -d "${host_tool_output_dir}" ]]; then
for tool_name in ${!tools[@]} ;do
if [[ ! -x "${pbench_bin}/tool-scripts/${tool_name}" ]]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--interval=10
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--interval=10
12 changes: 10 additions & 2 deletions agent/util-scripts/unittests
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ declare -A tools=(
[test-05]="pbench-start-tools"
[test-06]="pbench-stop-tools"
[test-07]="pbench-postprocess-tools"
[test-07.1]="pbench-postprocess-tools"
[test-08]="pbench-kill-tools"
[test-09]="pbench-kill-tools"
[test-10]="pbench-kill-tools"
Expand Down Expand Up @@ -451,6 +452,7 @@ declare -A options=(
[test-05]="--group=default --dir=42-iter/sample42"
[test-06]="--group=default --dir=42-iter/sample42"
[test-07]="--group=foobar --dir=${_testdir}/42-iter/sample42"
[test-07.1]="--group=foobar --dir=${_testdir}/42-iter/sample42"
[test-08]="--group=barfoo --dir=42-iter/sample42"
[test-09]="--group=barfoo"
[test-10]="--dir=barfoo"
Expand Down Expand Up @@ -566,7 +568,10 @@ declare -A expected_status=(
declare -A pre_hooks=(
[test-05]='ln -s mock-pbench-tool-meister-client ${_testopt}/unittest-scripts/pbench-tool-meister-client'
[test-06]='ln -s mock-pbench-tool-meister-client ${_testopt}/unittest-scripts/pbench-tool-meister-client; mkdir -p ${_testdir}/42-iter/sample42/tools-default/testhost.example.com/iostat; touch ${_testdir}/42-iter/sample42/tools-default/testhost.example.com/iostat/iostat-stdout.txt'
[test-07]='mkdir -p ${_testdir}/42-iter/sample42/tools-foobar/testhost.example.com/iostat; touch ${_testdir}/42-iter/sample42/tools-foobar/testhost.example.com/iostat/iostat-stdout.txt'
# with labeled host
[test-07]='mkdir -p ${_testdir}/42-iter/sample42/tools-foobar/bar:testhost.example.com/iostat; touch ${_testdir}/42-iter/sample42/tools-foobar/bar:testhost.example.com/iostat/iostat-stdout.txt'
# with unlabeled host
[test-07.1]='mkdir -p ${_testdir}/42-iter/sample42/tools-foobar/testhost.example.com/iostat; touch ${_testdir}/42-iter/sample42/tools-foobar/testhost.example.com/iostat/iostat-stdout.txt'
[test-11.16]='mkdir ${_testdir}/tmp; (echo foo; echo bar) > ${_testdir}/tmp/good-remote-file'
[test-11.17]='mkdir ${_testdir}/tmp; touch ${_testdir}/tmp/empty-remote-file'
[test-19]='ln -s mock-pbench-tool-meister-client ${_testopt}/unittest-scripts/pbench-tool-meister-client'
Expand Down Expand Up @@ -623,7 +628,10 @@ function sort_tmlogs {
declare -A post_hooks=(
[test-05]='rm ${_testopt}/unittest-scripts/pbench-tool-meister-client'
[test-06]='rm ${_testopt}/unittest-scripts/pbench-tool-meister-client'
[test-07]='cat ${_testdir}/42-iter/sample42/tools-foobar/testhost.example.com/postprocess.log >> ${_testout} 2>&1'
# with labeled host
[test-07]='cat ${_testdir}/42-iter/sample42/tools-foobar/bar:testhost.example.com/postprocess.log >> ${_testout} 2>&1'
# with unlabeled host
[test-07.1]='cat ${_testdir}/42-iter/sample42/tools-foobar/testhost.example.com/postprocess.log >> ${_testout} 2>&1'
[test-19]='rm ${_testopt}/unittest-scripts/pbench-tool-meister-client'
[test-53]='sort_testlog; sort_tmlogs; filter_tmerrs'
[test-54]='sed -Ei "s/^optional arguments:/options:/" ${_testout}'
Expand Down
37 changes: 22 additions & 15 deletions lib/pbench/cli/agent/commands/tools/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ def print_results(toolinfo: dict, with_option: bool) -> bool:
"""
printed = False
for group, gval in sorted(toolinfo.items()):
for host, tools in sorted(gval.items()):
for host, hostitems in sorted(gval.items()):
label = toolinfo[group][host]["label"]
webbnh marked this conversation as resolved.
Show resolved Hide resolved
host_string = f"host: {host}" + (f", label: {label}" if label else "")
tools = hostitems["tools"]
if tools:
if not with_option:
s = ", ".join(sorted(tools.keys()))
tool_string = ", ".join(sorted(tools.keys()))
else:
tools_with_options = [
f"{t} {' '.join(v)}" for t, v in sorted(tools.items())
]
s = ", ".join(tools_with_options)
print(f"group: {group}; host: {host}; tools: {s}")
tool_string = ", ".join(tools_with_options)
webbnh marked this conversation as resolved.
Show resolved Hide resolved
print(f"group: {group}; {host_string}; tools: {tool_string}")
printed = True
return printed

Expand Down Expand Up @@ -68,12 +71,16 @@ def execute(self) -> int:
for path in tg_dir:
host = path.name
tool_info[group][host] = {}

label = path / "__label__"
v = label.read_text().rstrip("\n") if label.exists() else None
tool_info[group][host]["label"] = v

tool_info[group][host]["tools"] = {}

for tool in sorted(self.tools(path)):
tool_info[group][host][tool] = (
sorted((path / tool).read_text().rstrip("\n").split("\n"))
if opts
else ""
)
v = sorted((path / tool).read_text().rstrip("\n").split("\n"))
tool_info[group][host]["tools"][tool] = v if opts else ""

if tool_info:
found = self.print_results(tool_info, self.context.with_option)
Expand Down Expand Up @@ -106,13 +113,13 @@ def execute(self) -> int:

host = path.name
tool_info[group][host] = {}
# Check to see if the tool is in any of the hosts.
tool_info[group][host]["label"] = None
tool_info[group][host]["tools"] = {}

# Check if the tool is in any of the hosts.
webbnh marked this conversation as resolved.
Show resolved Hide resolved
if tool in self.tools(path):
tool_info[group][host][tool] = (
sorted((path / tool).read_text().rstrip("\n").split("\n"))
if opts
else ""
)
v = sorted((path / tool).read_text().rstrip("\n").split("\n"))
tool_info[group][host]["tools"][tool] = v if opts else ""
found = True

if found:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,39 @@ def tools_on_multiple_hosts(self, pbench_run):
tool = p / "perf"
tool.write_text("--record-opts='-a --freq=100'")

# Issue #3454
@pytest.fixture
def labels_on_multiple_hosts(self, pbench_run, tools_on_multiple_hosts):
# This fixture is meant to be called after the previous one
# (tools_on_multiple_hosts). The previous one establishes a
# tool-like directory structure; this one just embellishes it
# with labels on some host entries. Think of it as a
# double for-loop, like the one above, only unrolled.
webbnh marked this conversation as resolved.
Show resolved Hide resolved

# row 1
group = "default"

# column 1
host = "th1.example.com"
label = pbench_run / f"tools-v1-{group}" / host / "__label__"
label.write_text("foo")

# column 2
host = "th2.example.com"
label = pbench_run / f"tools-v1-{group}" / host / "__label__"
label.write_text("bar")

# row 2
group = "test"

# column 1
host = "th1.example.com"
label = pbench_run / f"tools-v1-{group}" / host / "__label__"
label.write_text("bar")

# column 2
# th2 has no label

# Issue #2346
def test_existing_group_options(self, single_group_tools, agent_config):
command = ["pbench-list-tools", "--with-option"]
Expand Down Expand Up @@ -309,3 +342,12 @@ def test_multiple_hosts_with_options(self, tools_on_multiple_hosts, agent_config
b"group: default; host: th1.example.com; tools: iostat --interval=30, mpstat --interval=300, sar --interval=10\ngroup: default; host: th2.example.com; tools: iostat --interval=30, mpstat --interval=300, perf --record-opts='-a --freq=100'\ngroup: test; host: th1.example.com; tools: iostat --interval=30, mpstat --interval=300, sar --interval=10\ngroup: test; host: th2.example.com; tools: iostat --interval=30, mpstat --interval=300, perf --record-opts='-a --freq=100'"
in out
)

def test_multiple_hosts_with_labels(self, labels_on_multiple_hosts, agent_config):
command = ["pbench-list-tools", "--with-option"]
out, err, exitcode = pytest.helpers.capture(command)
assert EMPTY == err and exitcode == 0
assert (
b"group: default; host: th1.example.com, label: foo; tools: iostat --interval=30, mpstat --interval=300, sar --interval=10\ngroup: default; host: th2.example.com, label: bar; tools: iostat --interval=30, mpstat --interval=300, perf --record-opts='-a --freq=100'\ngroup: test; host: th1.example.com, label: bar; tools: iostat --interval=30, mpstat --interval=300, sar --interval=10\ngroup: test; host: th2.example.com; tools: iostat --interval=30, mpstat --interval=300, perf --record-opts='-a --freq=100'"
in out
)