|
|
0034f4 |
From 70e254653edb21923d7565c80704e1ce6865d991 Mon Sep 17 00:00:00 2001
|
|
|
0034f4 |
From: Justin Stephenson <jstephen@redhat.com>
|
|
|
0034f4 |
Date: Wed, 12 Oct 2022 08:48:45 -0400
|
|
|
0034f4 |
Subject: [PATCH] Analyzer: Optimize list verbose output
|
|
|
0034f4 |
MIME-Version: 1.0
|
|
|
0034f4 |
Content-Type: text/plain; charset=UTF-8
|
|
|
0034f4 |
Content-Transfer-Encoding: 8bit
|
|
|
0034f4 |
|
|
|
0034f4 |
Modify the analyzer to parse the responder log file in one pass. This
|
|
|
0034f4 |
avoids repeated parsing of a single log file. This operation will now
|
|
|
0034f4 |
store log lines in a dictionary on a single pass then format and print
|
|
|
0034f4 |
the output accordingly. Does not affect 'list' or 'show' output.
|
|
|
0034f4 |
|
|
|
0034f4 |
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
|
|
|
0034f4 |
Reviewed-by: Tomáš Halman <thalman@redhat.com>
|
|
|
0034f4 |
|
|
|
0034f4 |
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
|
|
|
0034f4 |
Reviewed-by: Tomáš Halman <thalman@redhat.com>
|
|
|
0034f4 |
---
|
|
|
0034f4 |
src/tools/analyzer/modules/request.py | 71 ++++++++++++++++++---------
|
|
|
0034f4 |
1 file changed, 48 insertions(+), 23 deletions(-)
|
|
|
0034f4 |
|
|
|
0034f4 |
diff --git a/src/tools/analyzer/modules/request.py b/src/tools/analyzer/modules/request.py
|
|
|
0034f4 |
index b9fe3caf8..15c8e6bfb 100644
|
|
|
0034f4 |
--- a/src/tools/analyzer/modules/request.py
|
|
|
0034f4 |
+++ b/src/tools/analyzer/modules/request.py
|
|
|
0034f4 |
@@ -148,36 +148,57 @@ class RequestAnalyzer:
|
|
|
0034f4 |
print(line)
|
|
|
0034f4 |
return found_results
|
|
|
0034f4 |
|
|
|
0034f4 |
- def print_formatted_verbose(self, source, patterns):
|
|
|
0034f4 |
+ def print_formatted_verbose(self, source):
|
|
|
0034f4 |
"""
|
|
|
0034f4 |
- Parse line and print formatted verbose list_requests output
|
|
|
0034f4 |
+ Parse log file and print formatted verbose list_requests output
|
|
|
0034f4 |
|
|
|
0034f4 |
Args:
|
|
|
0034f4 |
source (Reader): source Reader object
|
|
|
0034f4 |
- patterns (list): List of regex patterns to use for
|
|
|
0034f4 |
- matching lines
|
|
|
0034f4 |
"""
|
|
|
0034f4 |
- # Get CID number, and print the basic line first
|
|
|
0034f4 |
- for line in self.matched_line(source, patterns):
|
|
|
0034f4 |
- cid = self.print_formatted(line)
|
|
|
0034f4 |
-
|
|
|
0034f4 |
- # Loop through each line with this CID number to extract and
|
|
|
0034f4 |
- # print the verbose data needed
|
|
|
0034f4 |
- verbose_patterns = ["(cache_req_send|cache_req_process_input|"
|
|
|
0034f4 |
- "cache_req_search_send)"]
|
|
|
0034f4 |
- for cidline in self.matched_line(source, verbose_patterns):
|
|
|
0034f4 |
+ data = {}
|
|
|
0034f4 |
+ # collect cid log lines from single run through of parsing the log
|
|
|
0034f4 |
+ # into dictionary # (cid, ts) -> logline_output
|
|
|
0034f4 |
+ for line in source:
|
|
|
0034f4 |
+ if "CID#" not in line:
|
|
|
0034f4 |
+ continue
|
|
|
0034f4 |
+
|
|
|
0034f4 |
+ # parse CID and ts from line, key is a tuple of (cid,ts)
|
|
|
0034f4 |
+ fields = line.split("[")
|
|
|
0034f4 |
+ # timestamp to the minute, cut off seconds, ms
|
|
|
0034f4 |
+ ts = fields[0][:17]
|
|
|
0034f4 |
+ result = re.search('CID#[0-9]*', fields[3])
|
|
|
0034f4 |
+ cid = result.group(0)
|
|
|
0034f4 |
+
|
|
|
0034f4 |
+ # if mapping exists, append line to output. Otherwise create new mapping
|
|
|
0034f4 |
+ if (cid, ts) in data.keys():
|
|
|
0034f4 |
+ data[(cid, ts)] += line
|
|
|
0034f4 |
+ else:
|
|
|
0034f4 |
+ data[(cid, ts)] = line
|
|
|
0034f4 |
+
|
|
|
0034f4 |
+ # pretty print the data
|
|
|
0034f4 |
+ for k, v in data.items():
|
|
|
0034f4 |
+ cr_done = []
|
|
|
0034f4 |
+ id_done = []
|
|
|
0034f4 |
+ for cidline in v.splitlines():
|
|
|
0034f4 |
plugin = ""
|
|
|
0034f4 |
name = ""
|
|
|
0034f4 |
id = ""
|
|
|
0034f4 |
|
|
|
0034f4 |
- # skip any lines not pertaining to this CID
|
|
|
0034f4 |
- if f"CID#{cid}]" not in cidline:
|
|
|
0034f4 |
- continue
|
|
|
0034f4 |
- if "refreshed" in cidline:
|
|
|
0034f4 |
- continue
|
|
|
0034f4 |
+ # CR number
|
|
|
0034f4 |
+ fields = cidline.split("[")
|
|
|
0034f4 |
+ cr_field = fields[3][7:]
|
|
|
0034f4 |
+ cr = cr_field.split(":")[0][4:]
|
|
|
0034f4 |
+ # Client connected, top-level info line
|
|
|
0034f4 |
+ if re.search(r'\[cmd', cidline):
|
|
|
0034f4 |
+ self.print_formatted(cidline)
|
|
|
0034f4 |
# CR Plugin name
|
|
|
0034f4 |
if re.search("cache_req_send", cidline):
|
|
|
0034f4 |
plugin = cidline.split('\'')[1]
|
|
|
0034f4 |
+ id_done.clear()
|
|
|
0034f4 |
+ # Extract CR number
|
|
|
0034f4 |
+ fields = cidline.split("[")
|
|
|
0034f4 |
+ cr_field = fields[3][7:]
|
|
|
0034f4 |
+ cr = cr_field.split(":")[0][4:]
|
|
|
0034f4 |
# CR Input name
|
|
|
0034f4 |
elif re.search("cache_req_process_input", cidline):
|
|
|
0034f4 |
name = cidline.rsplit('[')[-1]
|
|
|
0034f4 |
@@ -188,9 +209,14 @@ class RequestAnalyzer:
|
|
|
0034f4 |
if plugin:
|
|
|
0034f4 |
print(" - " + plugin)
|
|
|
0034f4 |
if name:
|
|
|
0034f4 |
- print(" - " + name[:-2])
|
|
|
0034f4 |
+ # Avoid duplicate output with the same CR #
|
|
|
0034f4 |
+ if cr not in cr_done:
|
|
|
0034f4 |
+ print(" - " + name[:-1])
|
|
|
0034f4 |
+ cr_done.append(cr)
|
|
|
0034f4 |
if (id and ("UID" in cidline or "GID" in cidline)):
|
|
|
0034f4 |
- print(" - " + id)
|
|
|
0034f4 |
+ if id not in id_done:
|
|
|
0034f4 |
+ print(" - " + id)
|
|
|
0034f4 |
+ id_done.append(id)
|
|
|
0034f4 |
|
|
|
0034f4 |
def print_formatted(self, line):
|
|
|
0034f4 |
"""
|
|
|
0034f4 |
@@ -237,7 +263,7 @@ class RequestAnalyzer:
|
|
|
0034f4 |
logger.info(f"******** Listing {resp} client requests ********")
|
|
|
0034f4 |
source.set_component(component, False)
|
|
|
0034f4 |
if args.verbose:
|
|
|
0034f4 |
- self.print_formatted_verbose(source, patterns)
|
|
|
0034f4 |
+ self.print_formatted_verbose(source)
|
|
|
0034f4 |
else:
|
|
|
0034f4 |
for line in self.matched_line(source, patterns):
|
|
|
0034f4 |
if isinstance(source, Journald):
|
|
|
0034f4 |
@@ -258,8 +284,7 @@ class RequestAnalyzer:
|
|
|
0034f4 |
be_results = False
|
|
|
0034f4 |
component = source.Component.NSS
|
|
|
0034f4 |
resp = "nss"
|
|
|
0034f4 |
- pattern = [rf'REQ_TRACE.*\[CID #{cid}\]']
|
|
|
0034f4 |
- pattern.append(rf"\[CID#{cid}\]")
|
|
|
0034f4 |
+ pattern = [rf"\[CID#{cid}\]"]
|
|
|
0034f4 |
|
|
|
0034f4 |
if args.pam:
|
|
|
0034f4 |
component = source.Component.PAM
|
|
|
0034f4 |
--
|
|
|
0034f4 |
2.37.3
|
|
|
0034f4 |
|