Skip to content

feat: run commands during javaagent startup - #3255

Draft
hengyunabc wants to merge 2 commits into
alibaba:masterfrom
hengyunabc:codex/javaagent-startup-commands
Draft

feat: run commands during javaagent startup#3255
hengyunabc wants to merge 2 commits into
alibaba:masterfrom
hengyunabc:codex/javaagent-startup-commands

Conversation

@hengyunabc

Copy link
Copy Markdown
Collaborator

Summary

  • add arthas.startupScript for executing UTF-8 command scripts when Arthas starts through -javaagent
  • run every startup command in an independent session/job so multiple long-running watch, line, and other enhancer commands can coexist
  • automatically enable lazy enhancement for startup sessions and wait on an executor barrier before premain returns
  • persist a manifest and per-command JSONL event streams under ${arthas.outputPath}/startup/<pid>/<run-id>/
  • use bounded asynchronous result queues, explicit dropped-result events, fail-open startup behavior, and lifecycle cleanup
  • fix blank core JAR handling so the agent reliably falls back to arthas-core.jar beside arthas-agent.jar
  • document the configuration and add focused parser, orchestration, lazy-mode, configuration, and output tests

Motivation

Starting Arthas with -javaagent currently initializes the server but cannot preinstall diagnostic commands. Commands submitted after application startup can miss early class loads or method calls, and one session cannot host multiple foreground long-running commands. This change adds a thin startup orchestration layer on top of the existing command, job, and transformer infrastructure.

User impact

The feature is disabled unless arthas.startupScript is configured, so existing startup and interactive-session behavior is unchanged. When enabled, a script can contain one Arthas command per line; enhancer commands wait for unloaded target classes automatically, and structured results are persisted without blocking application threads on disk I/O.

Example:

arthas.startupScript=/opt/arthas/startup.as
line --class demo.MathGame --line 51 -n 2
line --class demo.MathGame --line 57 -n 2
watch demo.MathGame primeFactors '{params, returnObj}' -n 2

Validation

  • ./mvnw -pl core -am test — 291 tests, 0 failures, 7 existing skips
  • ./mvnw -f agent/pom.xml -DskipTests package
  • ./mvnw -pl packaging -am -DskipTests package — core, site, and distribution build succeeded
  • manual -javaagent smoke test with MathGame: two line jobs and one watch job entered lazy mode before demo.MathGame loaded, then all produced results in separate JSONL files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant