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

feat: Add arg to capture skips in the broker #3663

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 8 additions & 3 deletions insights/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ def _load_context(path):
return dr.get_component(path)


def run(component=None, root=None, print_summary=False,
context=None, inventory=None, print_component=None):

def run(component=None, root=None, print_summary=False, context=None, inventory=None, print_component=None,
store_skips=False):
args = None
formatters = None

Expand All @@ -293,6 +292,8 @@ def run(component=None, root=None, print_summary=False,
p.add_argument("--context", help="Execution Context. Defaults to HostContext if an archive isn't passed.")
p.add_argument("--no-load-default", help="Don't load the default plugins.", action="store_true")
p.add_argument("--parallel", help="Execute rules in parallel.", action="store_true")
p.add_argument("--show-skips", help="Capture skips in the broker for troubleshooting.", action="store_true",
default=False)
p.add_argument("--tags", help="Expression to select rules by tag.")

class Args(object):
Expand Down Expand Up @@ -385,6 +386,10 @@ class Args(object):
graph = dr.COMPONENTS[dr.GROUPS.single]

broker = dr.Broker()
if args:
broker.store_skips = args.show_skips
else:
broker.store_skips = store_skips

if args and args.bare:
ctx = ExecutionContext() # dummy context that no spec depend on. needed for filters to work
Expand Down
10 changes: 8 additions & 2 deletions insights/core/dr.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,13 +809,15 @@ class Broker(object):
:func:`time.time`. For components that produce multiple instances,
the execution time here is the sum of their individual execution
times.
store_skips (bool): Weather to store skips in the broker or not.
"""
def __init__(self, seed_broker=None):
self.instances = dict(seed_broker.instances) if seed_broker else {}
self.missing_requirements = {}
self.exceptions = defaultdict(list)
self.tracebacks = {}
self.exec_times = {}
self.store_skips = False

self.observers = defaultdict(set)
if seed_broker is not None:
Expand Down Expand Up @@ -1045,8 +1047,12 @@ def run_components(ordered_components, components, broker):
except ParseException as pe:
log.warning(pe)
broker.add_exception(component, pe, traceback.format_exc())
except SkipComponent:
pass
except SkipComponent as sc:
if broker.store_skips:
log.warning(sc)
broker.add_exception(component, sc, traceback.format_exc())
else:
pass
except Exception as ex:
tb = traceback.format_exc()
log.warning(tb)
Expand Down
10 changes: 7 additions & 3 deletions insights/core/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,18 @@ def invoke(self, broker):
r = self.component(d)
if r is not None:
results.append(r)
except SkipComponent:
pass
except ContentException as ce:
log.debug(ce)
broker.add_exception(self.component, ce, traceback.format_exc())
if not self.continue_on_error:
exception = True
break
except SkipComponent as sc:
if broker.store_skips:
log.warning(sc)
broker.add_exception(component, sc, traceback.format_exc())
else:
pass
except CalledProcessError as cpe:
log.debug(cpe)
broker.add_exception(self.component, cpe, traceback.format_exc())
Expand All @@ -183,7 +187,7 @@ def invoke(self, broker):
break
except Exception as ex:
tb = traceback.format_exc()
log.warn(tb)
log.warning(tb)
broker.add_exception(self.component, ex, tb)
if not self.continue_on_error:
exception = True
Expand Down