docstr: Extract stack trace pattern from the logs. Stack trace pattern often matches
  the following:
  ERROR ...
  Traceback (most recent call last):
      File "...", line ..., in ...
      ...
  Exception: exception error
docstr_tok: ["Extract","stack","trace","pattern","from","the","logs",".","Stack","trace","pattern","often","matches","the","following",":","ERROR","...","Traceback","(","most","recent","call","last",")",":","File","``","...","''",",","line","...",",","in","...","...","Exception",":","exception","error"]
code: def _compute_stack_trace(logs: List[str]) -> List[str]:
      """
      Extract stack trace pattern from the logs. Stack trace pattern often matches
      the following:
      ERROR ...
      Traceback (most recent call last):
          File "...", line ..., in ...
          ...
      Exception: exception error
      """
      error_stacktrace = []
      stacktrace = []
      i = 0
      while i < len(logs):
          stack = []
          trace = error_stacktrace
          # Search for lines that are either
          # ... ERROR ...
          # or
          # ... ERROR ...
          # Traceback (most recent call last):
          if "ERROR" in logs[i]:
              stack.append(logs[i])
              next = i + 1
              if i + 1 < len(logs) and TRACEBACK_PATTERN in logs[i + 1]:
                  stack.append(logs[i + 1])
                  next = i + 2
          # Or if the line with ERROR does not exist, just search for the line with
          # Traceback (most recent call last):
          elif TRACEBACK_PATTERN in logs[i]:
              stack.append(logs[i])
              trace = stacktrace
              next = i + 1
          # Or else, skip this line and continue
          else:
              i = i + 1
              continue
          # If the line that contains ERROR, Traceback, etc. is found, scan the logs
          # until the line no longer has indentation. This is because stack trace
          # is always indented, and stops when the line is no longer indented
          while next < len(logs):
              if logs[next].startswith((" ", "\t")):
                  stack.append(logs[next])
                  next = next + 1
              else:
                  break
          # Finished capturing the entire stack trace
          if next < len(logs):
              stack.append(logs[next])
          if stack:
              trace.append(stack)
          i = next + 1
  
      # Favor stack trace that contains the ERROR keyword
      if error_stacktrace:
          return error_stacktrace[-1]
  
      # Otherwise any stack trace is fine
      if stacktrace:
          return stacktrace[-1]
  
      return []
  
imports: import re
  from typing import List
label_desc: Use image node_id 4 for calling the LogAggregator obj's underlying member method code with example usage: obj._compute_stack_trace(logs) and returns: list, error_stacktrace, stacktrace