Skip to content

Commit

Permalink
Interactive fuzz logs subset of report to rollbar (#1239)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheng Lundquist authored Jan 10, 2024
1 parent 8d68e36 commit eb57306
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
21 changes: 17 additions & 4 deletions lib/agent0/agent0/hyperdrive/crash_report/crash_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def log_hyperdrive_crash_report(
crash_report_to_file: bool = True,
crash_report_file_prefix: str | None = None,
log_to_rollbar: bool = False,
rollbar_data: dict | None = None,
) -> None:
# pylint: disable=too-many-arguments
"""Log a crash report for a hyperdrive transaction.
Expand All @@ -206,6 +207,9 @@ def log_hyperdrive_crash_report(
log_to_rollbar: bool, optional
If enabled, logs errors to the rollbar service.
Defaults to False.
rollbar_data: dict | None, optional
Optional dictionary of data to use for the the rollbar report.
If not provided, will default to logging all of the crash report to rollbar.
"""
if log_level is None:
log_level = logging.CRITICAL
Expand Down Expand Up @@ -275,6 +279,7 @@ def log_hyperdrive_crash_report(
}

# We print out a machine readable crash report
crash_report_file = None
if crash_report_to_file:
dump_obj["env"] = env_details # type: ignore
# We add the machine readable version of the crash to the file
Expand All @@ -290,10 +295,18 @@ def log_hyperdrive_crash_report(
json.dump(dump_obj, file, indent=2, cls=ExtendedJSONEncoder)

if log_to_rollbar:
# Don't log anvil dump state to rollbar
dump_obj["anvil_dump_state"] = None # type: ignore
logging_crash_report = json.loads(json.dumps(dump_obj, indent=2, cls=ExtendedJSONEncoder))
log_rollbar_exception(trade_result.exception, log_level, logging_crash_report)
if rollbar_data is None:
# Don't log anvil dump state to rollbar
dump_obj["anvil_dump_state"] = None # type: ignore
rollbar_data = dump_obj
else:
# If we're supplying the subset of data, we want to link to the original crash report
if crash_report_file is not None:
rollbar_data["crash_report_file"] = os.path.abspath(crash_report_file)

# Format data
rollbar_data = json.loads(json.dumps(rollbar_data, indent=2, cls=ExtendedJSONEncoder))
log_rollbar_exception(trade_result.exception, log_level, rollbar_data)


def _hyperdrive_wallet_to_dict(wallet: HyperdriveWallet | None) -> dict[str, Any]:
Expand Down
14 changes: 13 additions & 1 deletion lib/agent0/agent0/interactive_fuzz/fuzz_hyperdrive_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,30 @@ def fuzz_hyperdrive_balance(num_trades: int, chain_config: LocalChain.Config, lo
invariant_check(initial_effective_share_reserves, interactive_hyperdrive)
except FuzzAssertionException as error:
dump_state_dir = chain.save_state(save_prefix="fuzz_long_short_maturity_values")
# The additional information going into the crash report
additional_info = {
"fuzz_random_seed": random_seed,
"dump_state_dir": dump_state_dir,
"trade_ticker": interactive_hyperdrive.get_ticker(),
}
additional_info.update(error.exception_data)
# The subset of information going into rollbar
rollbar_data = {
"fuzz_random_seed": random_seed,
"dump_state_dir": dump_state_dir,
}
rollbar_data.update(error.exception_data)

report = build_crash_trade_result(
error, interactive_hyperdrive.hyperdrive_interface, agent.agent, additional_info=additional_info
)
# Crash reporting already going to file in logging
log_hyperdrive_crash_report(
report, crash_report_to_file=True, crash_report_file_prefix="fuzz_hyperdrive_balance", log_to_rollbar=True
report,
crash_report_to_file=True,
crash_report_file_prefix="fuzz_hyperdrive_balance",
log_to_rollbar=True,
rollbar_data=rollbar_data,
)
chain.cleanup()
raise error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,21 @@ def fuzz_long_short_maturity_values(
invariant_check(trade, close_event, starting_checkpoint, maturity_checkpoint, interactive_hyperdrive)
except FuzzAssertionException as error:
dump_state_dir = chain.save_state(save_prefix="fuzz_long_short_maturity_values")
# The additional information going into the crash report
additional_info = {
"fuzz_random_seed": random_seed,
"dump_state_dir": dump_state_dir,
"trade_ticker": interactive_hyperdrive.get_ticker(),
}
additional_info.update(error.exception_data)

# The subset of information going into rollbar
rollbar_data = {
"fuzz_random_seed": random_seed,
"dump_state_dir": dump_state_dir,
}
rollbar_data.update(error.exception_data)

report = build_crash_trade_result(
error, interactive_hyperdrive.hyperdrive_interface, agent.agent, additional_info=additional_info
)
Expand All @@ -152,6 +161,7 @@ def fuzz_long_short_maturity_values(
crash_report_to_file=True,
crash_report_file_prefix="fuzz_long_short_maturity_values",
log_to_rollbar=True,
rollbar_data=rollbar_data,
)
chain.cleanup()
raise error
Expand Down
12 changes: 12 additions & 0 deletions lib/agent0/agent0/interactive_fuzz/fuzz_path_independence.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def fuzz_path_independence(
invariant_check(check_data, present_value_epsilon, interactive_hyperdrive)
except FuzzAssertionException as error:
dump_state_dir = chain.save_state(save_prefix="fuzz_path_independence")

# The additional information going into the crash report
additional_info = {
"fuzz_random_seed": random_seed,
"first_run_state_dump_dir": first_run_state_dump_dir,
Expand All @@ -161,6 +163,15 @@ def fuzz_path_independence(
"trade_ticker": interactive_hyperdrive.get_ticker(),
}
additional_info.update(error.exception_data)

# The subset of information going into rollbar
rollbar_data = {
"fuzz_random_seed": random_seed,
"first_run_state_dump_dir": first_run_state_dump_dir,
"dump_state_dir": dump_state_dir,
}
rollbar_data.update(error.exception_data)

report = build_crash_trade_result(
error, interactive_hyperdrive.hyperdrive_interface, agent.agent, additional_info=additional_info
)
Expand All @@ -170,6 +181,7 @@ def fuzz_path_independence(
crash_report_to_file=True,
crash_report_file_prefix="fuzz_path_independence",
log_to_rollbar=True,
rollbar_data=rollbar_data,
)
chain.cleanup()
raise error
Expand Down
16 changes: 15 additions & 1 deletion lib/agent0/agent0/interactive_fuzz/fuzz_profit_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,22 @@ def fuzz_profit_check(chain_config: LocalChain.Config | None = None, log_to_stdo
invariant_check(check_data)
except FuzzAssertionException as error:
dump_state_dir = chain.save_state(save_prefix="fuzz_profit_check")

# The additional information going into the crash report
additional_info = {
"fuzz_random_seed": random_seed,
"dump_state_dir": dump_state_dir,
"trade_ticker": interactive_hyperdrive.get_ticker(),
}
additional_info.update(error.exception_data)

# The subset of information going into rollbar
rollbar_data = {
"fuzz_random_seed": random_seed,
"dump_state_dir": dump_state_dir,
}
rollbar_data.update(error.exception_data)

# TODO do better checking here or make agent optional in build_crash_trade_result
if "LONG" in error.args[0]:
agent = long_agent.agent
Expand All @@ -136,7 +146,11 @@ def fuzz_profit_check(chain_config: LocalChain.Config | None = None, log_to_stdo
)
# Crash reporting already going to file in logging
log_hyperdrive_crash_report(
report, crash_report_to_file=True, crash_report_file_prefix="fuzz_profit_check", log_to_rollbar=True
report,
crash_report_to_file=True,
crash_report_file_prefix="fuzz_profit_check",
log_to_rollbar=True,
rollbar_data=rollbar_data,
)
chain.cleanup()
raise error
Expand Down

0 comments on commit eb57306

Please sign in to comment.