Skip to content

Commit

Permalink
🐛 Stricter equality for analyzer issues (#507)
Browse files Browse the repository at this point in the history
* 🐛 Take variables into account when determining if an issue is a duplicate
* Various logging/debugger changes for ease of use/comprehension

Signed-off-by: Fabian von Feilitzsch <fabian@fabianism.us>
  • Loading branch information
fabianvf authored Dec 3, 2024
1 parent 73e3b79 commit 69bd1f0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 43 deletions.
21 changes: 10 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,21 @@ get-analyzer-deps:
docker rm bundle

# This will get the rulesets and set them to be used by run_demo.py
get_rulesets:
get-rulesets:
(cd example/analysis && rm -rf rulesets && git clone https://github.com/konveyor/rulesets); rm -rf example/analysis/rulesets/preview

run_demo:
cd example && python run_demo.py

run_debug_driver:
PYTHONPATH=$(KAI_PYTHON_PATH) python kai/reactive_codeplanner/main.py \
example/config.toml \
example/coolstore \
example/analysis/rulesets/default/generated \
example/analysis/kai-analyzer-rpc \
example/analysis/jdtls/bin/jdtls \
example/analysis/bundle.jar \
"(konveyor.io/target=quarkus || konveyor.io/target=jakarta-ee || konveyor.io/target=jakarta-ee8 || konveyor.io/target=jakarta-ee9 || konveyor.io/target=cloud-readiness)" \
""
python kai/reactive_codeplanner/main.py \
--kai-config example/config.toml \
--source-directory example/coolstore \
--rules-directory example/analysis/rulesets/default/generated \
--analyzer-lsp-server-binary example/analysis/kai-analyzer-rpc \
--analyzer-lsp-path example/analysis/jdtls/bin/jdtls \
--analyzer-lsp-java-bundle example/analysis/bundle.jar \
--label-selector "(konveyor.io/target=quarkus || konveyor.io/target=jakarta-ee || konveyor.io/target=jakarta-ee8 || konveyor.io/target=jakarta-ee9 || konveyor.io/target=cloud-readiness)"

# This will run all the things that you need to do, to configure the demo.
config_demo: set-binaries-demo get_analyzer_deps get_rulesets
config_demo: set-binaries-demo get-analyzer-deps get-rulesets
2 changes: 1 addition & 1 deletion kai/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(
rules_directory: Path,
analyzer_lsp_path: Path,
analyzer_java_bundle_path: Path,
dep_open_source_labels_path: Path,
dep_open_source_labels_path: Optional[Path],
) -> None:
"""This will start and analyzer-lsp jsonrpc server"""
# trunk-ignore-begin(bandit/B603)
Expand Down
63 changes: 39 additions & 24 deletions kai/reactive_codeplanner/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,66 +35,81 @@


def main() -> None:

parser = argparse.ArgumentParser(
description="Run the CodePlan loop against a project"
)

parser.add_argument(
"kai_config",
"--kai-config",
"-k",
help="The path to the kai config file",
type=Path,
required=True,
)

parser.add_argument(
"source_directory",
"--source-directory",
"-s",
help="The root directory of the project to be fixed",
type=Path,
required=True,
)

parser.add_argument(
"rules_directory",
"--rules-directory",
"-r",
help="The root directory of the rules to use during analysis",
type=Path,
required=True,
)

parser.add_argument(
"analyzer_lsp_server_binary",
"--analyzer-lsp-server-binary",
"-b",
help="The binary for running analyzer-lsp RPC server",
type=Path,
required=True,
)

parser.add_argument(
"analyzer_lsp_path",
"--analyzer-lsp-path",
"-a",
help="The binary for analyzer-lsp",
type=Path,
required=True,
)

parser.add_argument(
"analyzer_lsp_java_bundle",
"--analyzer-lsp-java-bundle",
"-j",
help="The path to the analyzer java bundle",
type=Path,
required=True,
)

parser.add_argument(
"label_selector",
default="",
"--label-selector",
"-l",
help="The label selector for rules",
type=Path,
type=str,
default="",
)

parser.add_argument(
"incident_selector",
default="",
"--incident-selector",
"-i",
help="The incident selector for violations",
type=Path,
type=str,
default="",
)

parser.add_argument(
"dep_open_source_labels_path",
default="",
help="Path to the opensource labels for depenencies file",
"--dep-open-source-labels-path",
"-d",
help="Path to the open source labels for dependencies file",
type=Path,
default=None,
)

args = parser.parse_args()

config = RpcClientConfig(
Expand All @@ -121,7 +136,11 @@ def main() -> None:
rules_directory=Path(args.rules_directory),
analyzer_lsp_path=Path(args.analyzer_lsp_path),
analyzer_java_bundle_path=Path(args.analyzer_lsp_java_bundle),
dep_open_source_labels_path=Path(args.dep_open_source_labels_path),
dep_open_source_labels_path=(
Path(args.dep_open_source_labels_path)
if args.dep_open_source_labels_path
else None
),
)

task_manager = TaskManager(
Expand Down Expand Up @@ -175,15 +194,11 @@ def main() -> None:
logger.info("QUEUE_STATE: END")
logger.info("QUEUE_STATE: SUCCESSFUL_TASKS: START")
for task in task_manager.processed_tasks:
logger.info(
f"QUEUE_STATE: SUCCESSFUL_TASKS: {task}(priority={task.priority}, depth={task.depth}, retries={task.retry_count})"
)
logger.info(f"QUEUE_STATE: SUCCESSFUL_TASKS: {task}")
logger.info("QUEUE_STATE: SUCCESSFUL_TASKS: END")
logger.info("QUEUE_STATE: IGNORED_TASKS: START")
for task in task_manager.ignored_tasks:
logger.info(
f"QUEUE_STATE: IGNORED_TASKS: {task}(priority={task.priority}, depth={task.depth}, retries={task.retry_count})"
)
logger.info(f"QUEUE_STATE: IGNORED_TASKS: {task}")
logger.info("QUEUE_STATE: IGNORED_TASKS: END")
task_manager.stop()
logger.info("Codeplan execution completed.")
Expand Down
1 change: 1 addition & 0 deletions kai/reactive_codeplanner/task_runner/analyzer_lsp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def fuzzy_equals(self, error2: Task, offset: int = 1) -> bool:
self.ruleset.name == error2.ruleset.name
and self.incident.message == error2.incident.message
and self.file == error2.file
and self.incident.variables == error2.incident.variables
):
logger.info("should match on line numbers %s -- %s", self.line, error2.line)
return True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def run(self, scoped_paths: Optional[list[Path]] = None) -> ValidationResult:
)
# Build/dependency/other errors prevent the compilation errors from being reported
# But we still want to return them so they aren't mistakenly marked as solved.
logger.debug(
f"determining whether maven cache should be set: build_errors: {bool(build_errors)}, dependency_errors: {bool(dependency_errors)}, catchall_errors: {bool(catchall_errors)}, compilation_errors: {bool(compilation_errors)}, cond: {(build_errors or dependency_errors or catchall_errors) and not compilation_errors}"
)
if (
build_errors or dependency_errors or catchall_errors
) and not compilation_errors:
Expand All @@ -48,7 +51,9 @@ def run(self, scoped_paths: Optional[list[Path]] = None) -> ValidationResult:
)
else:
self.last_compilation_errors = compilation_errors
logger.debug("Setting the maven cache")
logger.debug(
f"Setting the maven cache with {len(self.last_compilation_errors)} compilation errors"
)
errors = build_errors + dependency_errors + compilation_errors + catchall_errors
return ValidationResult(passed=not errors, errors=errors)

Expand Down
8 changes: 2 additions & 6 deletions kai/rpc_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,11 @@ class OverallResult(TypedDict):
app.log.debug("QUEUE_STATE: END")
app.log.debug("QUEUE_STATE: SUCCESSFUL_TASKS: START")
for task in app.task_manager.processed_tasks:
app.log.debug(
f"QUEUE_STATE: SUCCESSFUL_TASKS: {task}(priority={task.priority}, depth={task.depth}, retries={task.retry_count})"
)
app.log.debug(f"QUEUE_STATE: SUCCESSFUL_TASKS: {task}")
app.log.debug("QUEUE_STATE: SUCCESSFUL_TASKS: END")
app.log.debug("QUEUE_STATE: IGNORED_TASKS: START")
for task in app.task_manager.ignored_tasks:
app.log.debug(
f"QUEUE_STATE: IGNORED_TASKS: {task}(priority={task.priority}, depth={task.depth}, retries={task.retry_count})"
)
app.log.debug(f"QUEUE_STATE: IGNORED_TASKS: {task}")
app.log.debug("QUEUE_STATE: IGNORED_TASKS: END")

diff = app.rcm.snapshot.diff(app.rcm.first_snapshot)
Expand Down

0 comments on commit 69bd1f0

Please sign in to comment.