Skip to content

chore: camel-jbang - local times without the time zone rules of java.time (get health, log, get sql-trace) - #30213

Merged
davsclaus merged 1 commit into
mainfrom
chore-cli-local-time-without-zone-rules
Nov 16, 2026
Merged

davsclaus merged 1 commit into
mainfrom
chore-cli-local-time-without-zone-rules

Conversation

@davsclaus

@davsclaus davsclaus commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

ZoneId.systemDefault(), and parsing a time with a region such as [Europe/Paris], load the time zone rules of java.time. The JDK then looks for their providers (ZoneRulesProvider) with a ServiceLoader in every JAR of the class path: about 50 ms with the 340 JARs of the CLI distribution, on a short command that otherwise needs a dozen JARs. Found while working on the startup of the short commands (CAMEL-26935).

Change

CliTimes (camel-jbang-run) gives local times without those rules: the offset of the default TimeZone at that time (both read the tzdb data of the JDK, so the local time is the same, also around daylight saving changes), and the epoch millis of an ISO date-time from its offset (the region in brackets is left out; a text without an offset still goes to ZonedDateTime.parse).

It is used where a short command printed a local time or parsed one:

  • camel get health: the SINCE column parsed the times of the health checks with ZonedDateTime.parse (with region) and ZonedDateTime.now().
  • camel log: the tip about the previous run (PreviousRun), whose formatter called ZoneId.systemDefault() when the class was loaded.
  • camel get sql-trace: the TIME column.

The other uses of java.time zones in the CLI are in commands that do much more anyway (run, export, the AI tools, chaos explore).

Measured on a small program with the class path of the distribution: formatting a local time with ZoneId.systemDefault() 60 ms, with CliTimes 7 ms (SimpleDateFormat 21 ms, it loads locale data).

Measured

JDK 25, macOS (Apple M4 Pro), through camel.sh (with its CDS archive), median of 15 runs; CPU time (user + system), with the wall time in brackets, as the machine was busy:

command main this PR
camel get health (one integration) 445 ms (244 ms) 373 ms (223 ms)
camel log (tip about a previous run) 316 ms (165 ms) 306 ms (163 ms)

camel log gains little on main today, as aesh's class path scan (aeshell/aesh#779) and its JUL loggers (aeshell/aesh#782) open every JAR first; with those fixed, and #30199, the zone rules were 30 ms of it.

Tests

  • CliTimesTest (new): the same local time as ZoneId.of(zone) for Copenhagen, New York, Kolkata, Lord Howe (half hour daylight saving) and UTC, at the second before and after the 2026 daylight saving changes of Europe and the US and the April one of Lord Howe; parsing the text of a ZonedDateTime with and without region, with an offset and Z; a text that is not a date-time.
  • camel-jbang-run: CliTimesTest, PreviousRunTest, PreviousRunLogTest; camel-jbang-core: ListHealthTest, ListSqlTraceTest, CamelLogActionTest and the process tests: all pass.
  • Distribution: -Xlog:class+load shows no ZoneRulesProvider for get health and the log tip (main: loaded); their output is the same as on main.

Claude Code on behalf of davsclaus

🤖 Generated with Claude Code

https://claude.ai/code/session_012nJsFsjqqFiwroeHRWaKbS

…time (get health, log, get sql-trace)

ZoneId.systemDefault(), and parsing a time with a region such as
[Europe/Paris], load the time zone rules of java.time, and the JDK looks
for their providers with a ServiceLoader in every JAR of the class path
(about 50 ms with the 340 JARs of the CLI distribution). CliTimes takes
the offset of the default TimeZone at that time instead, which gives the
same local time, and parses an ISO date-time from its offset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
@davsclaus davsclaus added this to the 4.24.0 milestone Nov 16, 2026
@davsclaus davsclaus added the dsl label Nov 16, 2026

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. No issues found.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@davsclaus davsclaus self-assigned this Nov 16, 2026
@davsclaus davsclaus added the enhancement New feature or request label Nov 16, 2026
@davsclaus
davsclaus merged commit ce3e46c into main Nov 16, 2026
6 checks passed
@davsclaus
davsclaus deleted the chore-cli-local-time-without-zone-rules branch November 16, 2026 16:05
@github-actions

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • dsl/camel-jbang/camel-jbang-core
  • dsl/camel-jbang/camel-jbang-run

🔁 1 test passed only after a retry on JDK 21 (1 retried attempt)

Recovered flaky tests on JDK 21 (1)
Module Test Failed attempts First failure
dsl/camel-jbang/camel-jbang-plugin-tui AiPanelAcpTest.usageUpdateFeedsTheTokenCounter 1 array contents differ at index [0], expected: <900> but was: <0>

ℹ️ These tests did not fail the build. Surefire retried them and they passed.
Retries are enabled project-wide by surefire.rerunFailingTestsCount in parent/pom.xml.


🔬 Scalpel shadow comparison — Scalpel: 6 of 726 tested, 8 compile-only — current: 6 all tested

Maveniverse Scalpel detected 6 affected modules (current approach: 6).

Skip-tests mode would test 6 modules (2 direct + 5 downstream), skip tests for 8 (generated code, meta-modules)

Modules Scalpel would test (6)
  • camel-jbang-mcp ← downstream of org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-mcp ← downstream of org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-tui ← downstream of org.apache.camel:camel-jbang-core
  • camel-jbang-plugin-validate ← downstream of org.apache.camel:camel-jbang-core
  • camel-jbang-run ← dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/CliTimes.java, dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/common/PreviousRun.java, dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/common/CliTimesTest.java
  • camel-launcher-container ← downstream of org.apache.camel:camel-launcher
Modules with tests skipped (8)
  • camel-jbang-it
  • camel-jbang-main
  • camel-jbang-plugin-edit
  • camel-jbang-plugin-generate
  • camel-jbang-plugin-kubernetes
  • camel-jbang-plugin-test
  • camel-launcher
  • coverage

ℹ️ Shadow mode — Scalpel observes but does not affect test execution. Learn more

⚠️ Some tests are disabled on GitHub Actions (@DisabledIfSystemProperty(named = "ci.env.name")) and require manual verification:

  • dsl/camel-jbang/camel-jbang-core: 2 test(s) disabled on GitHub Actions

💡 Manual integration tests recommended:

You modified dsl/camel-jbang/camel-jbang-core. The related integration tests in dsl/camel-jbang/camel-jbang-it are excluded from CI. Consider running them manually:

mvn verify -f dsl/camel-jbang/camel-jbang-it -Djbang-it-test
All tested modules (15 modules, 3m 32s total)

Total reactor time: 3m 32s

Module Duration Status
Camel :: JBang :: Plugin :: TUI 54.1s SUCCESS
Camel :: JBang :: MCP 52.2s SUCCESS
Camel :: JBang :: Run 25.7s SUCCESS
Camel :: JBang :: Plugin :: Validate 25.1s SUCCESS
Camel :: JBang :: Plugin :: Kubernetes 15.2s SUCCESS
Camel :: JBang :: Plugin :: Testing 13.7s SUCCESS
Camel :: JBang :: Plugin :: Generate 8.4s SUCCESS
Camel :: Coverage 6.0s SUCCESS
Camel :: JBang :: Plugin :: MCP 4.3s SUCCESS
Camel :: JBang :: Plugin :: Edit 3.6s SUCCESS
Camel :: JBang :: Main 1.6s SUCCESS
Camel :: JBang :: Integration tests 1.1s SUCCESS
Camel :: Launcher :: Container 0.7s SUCCESS
Camel :: JBang :: Core n/a
Camel :: Launcher n/a

Top 20 slowest modules:

  • Camel :: JBang :: Plugin :: TUI (54.1s)
  • Camel :: JBang :: MCP (52.2s)
  • Camel :: JBang :: Run (25.7s)
  • Camel :: JBang :: Plugin :: Validate (25.1s)
  • Camel :: JBang :: Plugin :: Kubernetes (15.2s)
  • Camel :: JBang :: Plugin :: Testing (13.7s)
  • Camel :: JBang :: Plugin :: Generate (8.4s)
  • Camel :: Coverage (6.0s)
  • Camel :: JBang :: Plugin :: MCP (4.3s)
  • Camel :: JBang :: Plugin :: Edit (3.6s)
  • Camel :: JBang :: Main (1.6s)
  • Camel :: JBang :: Integration tests (1.1s)
  • Camel :: Launcher :: Container (0.7s)

⚙️ View full build and test results

@oscerd oscerd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat micro-optimization, and it keeps the times correct.

ZoneId.systemDefault() and parsing a region id like [Europe/Paris] pull in java.time's zone rules, which makes the JDK run a ServiceLoader over every JAR on the class path looking for ZoneRulesProvider, about 50 ms with the 340 JARs of the distribution on a command that otherwise needs a dozen. Avoiding that on a short command is worth doing.

The substitution is sound: TimeZone.getDefault().getOffset(epochMillis) reads the same JDK tzdb data and returns the offset in effect at that instant, so it is DST-aware (the offset is computed for the actual date, not a fixed raw offset), and wrapping it as a ZoneOffset gives the same local time java.time would have produced, without triggering the provider scan. So this is a faster path to the same answer, not an approximation. Consistent with the other short-command startup work. Good.

Claude Code on behalf of oscerd

@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

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

Labels

dsl enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants