Blame SOURCES/0009-Analyzer-support-parallel-requests-parsing.patch

c29843
From d22ea2df62b6e245eef75d7201b678601bf63e98 Mon Sep 17 00:00:00 2001
c29843
From: Justin Stephenson <jstephen@redhat.com>
c29843
Date: Fri, 19 Aug 2022 14:44:11 -0400
c29843
Subject: [PATCH 9/9] Analyzer: support parallel requests parsing
c29843
MIME-Version: 1.0
c29843
Content-Type: text/plain; charset=UTF-8
c29843
Content-Transfer-Encoding: 8bit
c29843
c29843
Analyzer code(primarily the list verbose command) needs
c29843
changes to handle parsing the necessary lines from
c29843
NSS/PAM log files when multiple intermixed/parallel
c29843
client requests are sent to SSSD.
c29843
c29843
Resolves: https://github.com/SSSD/sssd/issues/6307
c29843
c29843
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
c29843
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
c29843
c29843
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
c29843
---
c29843
 src/tools/analyzer/modules/request.py | 119 +++++++++++++++-----------
c29843
 1 file changed, 67 insertions(+), 52 deletions(-)
c29843
c29843
diff --git a/src/tools/analyzer/modules/request.py b/src/tools/analyzer/modules/request.py
c29843
index 935e13adc..b9fe3caf8 100644
c29843
--- a/src/tools/analyzer/modules/request.py
c29843
+++ b/src/tools/analyzer/modules/request.py
c29843
@@ -16,7 +16,6 @@ class RequestAnalyzer:
c29843
     """
c29843
     module_parser = None
c29843
     consumed_logs = []
c29843
-    done = ""
c29843
     list_opts = [
c29843
         Option('--verbose', 'Verbose output', bool, '-v'),
c29843
         Option('--pam', 'Filter only PAM requests', bool),
c29843
@@ -149,58 +148,74 @@ class RequestAnalyzer:
c29843
                 print(line)
c29843
         return found_results
c29843
 
c29843
-    def print_formatted(self, line, verbose):
c29843
+    def print_formatted_verbose(self, source, patterns):
c29843
+        """
c29843
+        Parse line and print formatted verbose list_requests output
c29843
+
c29843
+        Args:
c29843
+            source (Reader): source Reader object
c29843
+            patterns (list): List of regex patterns to use for
c29843
+                matching lines
c29843
+        """
c29843
+        # Get CID number, and print the basic line first
c29843
+        for line in self.matched_line(source, patterns):
c29843
+            cid = self.print_formatted(line)
c29843
+
c29843
+            # Loop through each line with this CID number to extract and
c29843
+            # print the verbose data needed
c29843
+            verbose_patterns = ["(cache_req_send|cache_req_process_input|"
c29843
+                                "cache_req_search_send)"]
c29843
+            for cidline in self.matched_line(source, verbose_patterns):
c29843
+                plugin = ""
c29843
+                name = ""
c29843
+                id = ""
c29843
+
c29843
+                # skip any lines not pertaining to this CID
c29843
+                if f"CID#{cid}]" not in cidline:
c29843
+                    continue
c29843
+                if "refreshed" in cidline:
c29843
+                    continue
c29843
+                # CR Plugin name
c29843
+                if re.search("cache_req_send", cidline):
c29843
+                    plugin = cidline.split('\'')[1]
c29843
+                # CR Input name
c29843
+                elif re.search("cache_req_process_input", cidline):
c29843
+                    name = cidline.rsplit('[')[-1]
c29843
+                # CR Input id
c29843
+                elif re.search("cache_req_search_send", cidline):
c29843
+                    id = cidline.rsplit()[-1]
c29843
+
c29843
+                if plugin:
c29843
+                    print("   - " + plugin)
c29843
+                if name:
c29843
+                    print("       - " + name[:-2])
c29843
+                if (id and ("UID" in cidline or "GID" in cidline)):
c29843
+                    print("       - " + id)
c29843
+
c29843
+    def print_formatted(self, line):
c29843
         """
c29843
         Parse line and print formatted list_requests output
c29843
 
c29843
         Args:
c29843
             line (str): line to parse
c29843
-            verbose (bool): If true, enable verbose output
c29843
+        Returns:
c29843
+            Client ID from printed line, 0 otherwise
c29843
         """
c29843
-        plugin = ""
c29843
-        name = ""
c29843
-        id = ""
c29843
-
c29843
         # exclude backtrace logs
c29843
         if line.startswith('   *  '):
c29843
-            return
c29843
-        fields = line.split("[")
c29843
-        cr_field = fields[3][7:]
c29843
-        cr = cr_field.split(":")[0][4:]
c29843
+            return 0
c29843
         if "refreshed" in line:
c29843
-            return
c29843
-        # CR Plugin name
c29843
-        if re.search("cache_req_send", line):
c29843
-            plugin = line.split('\'')[1]
c29843
-        # CR Input name
c29843
-        elif re.search("cache_req_process_input", line):
c29843
-            name = line.rsplit('[')[-1]
c29843
-        # CR Input id
c29843
-        elif re.search("cache_req_search_send", line):
c29843
-            id = line.rsplit()[-1]
c29843
-        # CID and client process name
c29843
-        else:
c29843
-            ts = line.split(")")[0]
c29843
-            ts = ts[1:]
c29843
-            fields = line.split("[")
c29843
-            cid = fields[3][4:-9]
c29843
-            cmd = fields[4][4:-1]
c29843
-            uid = fields[5][4:-1]
c29843
-            if not uid.isnumeric():
c29843
-                uid = fields[6][4:-1]
c29843
-            print(f'{ts}: [uid {uid}] CID #{cid}: {cmd}')
c29843
-
c29843
-        if verbose:
c29843
-            if plugin:
c29843
-                print("   - " + plugin)
c29843
-            if name:
c29843
-                if cr not in self.done:
c29843
-                    print("       - " + name[:-2])
c29843
-                    self.done = cr
c29843
-            if id:
c29843
-                if cr not in self.done:
c29843
-                    print("       - " + id)
c29843
-                    self.done = cr
c29843
+            return 0
c29843
+        ts = line.split(")")[0]
c29843
+        ts = ts[1:]
c29843
+        fields = line.split("[")
c29843
+        cid = fields[3][4:-9]
c29843
+        cmd = fields[4][4:-1]
c29843
+        uid = fields[5][4:-1]
c29843
+        if not uid.isnumeric():
c29843
+            uid = fields[6][4:-1]
c29843
+        print(f'{ts}: [uid {uid}] CID #{cid}: {cmd}')
c29843
+        return cid
c29843
 
c29843
     def list_requests(self, args):
c29843
         """
c29843
@@ -215,20 +230,20 @@ class RequestAnalyzer:
c29843
         # Log messages matching the following regex patterns contain
c29843
         # the useful info we need to produce list output
c29843
         patterns = [r'\[cmd']
c29843
-        patterns.append("(cache_req_send|cache_req_process_input|"
c29843
-                        "cache_req_search_send)")
c29843
         if args.pam:
c29843
             component = source.Component.PAM
c29843
             resp = "pam"
c29843
 
c29843
         logger.info(f"******** Listing {resp} client requests ********")
c29843
         source.set_component(component, False)
c29843
-        self.done = ""
c29843
-        for line in self.matched_line(source, patterns):
c29843
-            if isinstance(source, Journald):
c29843
-                print(line)
c29843
-            else:
c29843
-                self.print_formatted(line, args.verbose)
c29843
+        if args.verbose:
c29843
+            self.print_formatted_verbose(source, patterns)
c29843
+        else:
c29843
+            for line in self.matched_line(source, patterns):
c29843
+                if isinstance(source, Journald):
c29843
+                    print(line)
c29843
+                else:
c29843
+                    self.print_formatted(line)
c29843
 
c29843
     def track_request(self, args):
c29843
         """
c29843
-- 
c29843
2.37.1
c29843