Add tpstatsjson nodetool subcommand for deterministic JSON thread-pool stats#4600
Open
hemanth-19 wants to merge 1 commit intoapache:trunkfrom
Open
Add tpstatsjson nodetool subcommand for deterministic JSON thread-pool stats#4600hemanth-19 wants to merge 1 commit intoapache:trunkfrom
hemanth-19 wants to merge 1 commit intoapache:trunkfrom
Conversation
…l stats Provides a machine-parseable alternative to "tpstats -F json" with alphabetically sorted keys at every nesting level, making the output safe to diff in CI without post-processing. Two-tier error handling (section-level + per-metric) ensures a single bad MBean never silences the rest of the output; the "N/A" sentinel from unregistered MBeans is normalised to JSON null rather than treated as an error. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
I do not understand the reasoning here. If tpstats -F prints non-deterministically, what harm is done when it starts to be ordered? If it is ordered, that is the same case as if it was not intentionally ordered and it was printed out ordered by pure accident. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
nodetool tpstatsjson— a new read-only subcommand that printsthread-pool and dropped-message statistics as a single, deterministic
JSON object to stdout.
This is deliberate: when a single counter ticks from
5to6thediff is one line. Compact single-line JSON would collapse the entire
document into one line, turning every change into a full-document
replacement and making diffs uninformative. Users who need compact
output for transport can pipe through
jq -c.ORDER_MAP_ENTRIES_BY_KEYS), making the output safe todiffin CIwithout post-processing.
each caught independently and recorded in a top-level
errorsobject(present only when a failure actually occurs). The
"N/A"sentinelfrom unregistered MBeans is normalised to JSON
null— datanormalisation, not an error.
Why a new command instead of fixing
tpstats -F jsontpstats -F jsonalready emits JSON, but its key ordering isnon-deterministic: the data flows through
TpStatsHolder.convert2Map()and
StatsPrinter.JsonPrinter, both of which use plainHashMap.Switching those to sorted maps would silently change the output that
existing scripts and CI pipelines already consume and may parse or diff
in an order-dependent way. A dedicated command with its own
ObjectWriterisolates the sorted-keys contract entirely — no existingcode path is touched, no operator is surprised.
Files changed
src/java/.../TpStatsJson.javasrc/java/.../NodetoolCommand.javatest/resources/nodetool/help/tpstatsjsonNodetoolHelpCommandsOutputTesttest/unit/.../TpStatsJsonTest.javaStatic verification notes
All API call sites and data contracts were cross-checked against the
existing codebase before submission:
getThreadPools()returnsMultimap<String,String>(NodeProbe:2062);getThreadPoolMetric(path, pool, metric)returnsObject(
NodeProbe:1955);getDroppedMessages()returnsMap<String,Integer>(NodeProbe:1672). Every call site inTpStatsJson.execute()matches these signatures exactly.names used —
ActiveTasks,PendingTasks,CompletedTasks,CurrentlyBlockedTasks,TotalBlockedTasks— are the identical setfetched by
TpStatsHolder:46–50. No new MBean attributes areintroduced.
for (Map.Entry<String,String> tp : probe.getThreadPools().entries())loop is the established pattern at
TpStatsHolder:43.probe.output().out.println(…)is the canonicalwrite mechanism, used by 70+ existing commands.
Output.outispublic final PrintStream(Output:27).verified by computing PicoCLI's 80-column word-wrap and
cross-checking against the
failuredetectorreference file (acommand with no custom options, structurally identical). SYNOPSIS
and OPTIONS sections are the shared global-JMX-option boilerplate.
If the file is off by even one character
NodetoolHelpCommandsOutputTestwill surface the exact diff; regenerate via
NodetoolHelpGenerator.Test plan
Tests could not be executed locally (no
ant/ JDK runtime in thedevelopment environment). The following three CI targets must pass:
ant testsome -Dtest.name=org.apache.cassandra.tools.nodetool.TpStatsJsonTest— all six new tests
ant testsome -Dtest.name=org.apache.cassandra.tools.nodetool.TpStatsTest— regression: existing tpstats behaviour unchanged
ant testsome -Dtest.name=org.apache.cassandra.tools.nodetool.NodetoolHelpCommandsOutputTest— golden help file validation (parameterised; auto-discovers tpstatsjson)
🤖 Generated with Claude Code