Skip to content

fix(metrics): count a command under the label actually typed - #72

Merged
milanmalhotra merged 1 commit into
devfrom
fix-metrics-label-double-count
Aug 22, 2026
Merged

fix(metrics): count a command under the label actually typed#72
milanmalhotra merged 1 commit into
devfrom
fix-metrics-label-double-count

Conversation

@milanmalhotra

Copy link
Copy Markdown
Collaborator

The bug

CommandUsageListener incremented two counters on every invocation, the COMMAND family under the canonical name and the ALIAS family under the typed label. One /sethome therefore reported as a use of create-home as well as a use of sethome.

That defeats the reason the alias charts exist. The point of counting commands is to decide which commands and aliases can be retired, and command_create_home could not be told apart from alias traffic folded into it.

The change

An invocation now increments exactly one family, chosen by the label actually typed. The canonical name goes to COMMAND, anything else to ALIAS. The namespaced form has its prefix stripped first, so /sethomestwo:sethome still lands with the plain alias.

WindowShare.total takes varargs, and commands_total is now total(COMMAND, ALIAS) so it keeps meaning every invocation whatever label was typed. Putting the sum there rather than in the chart lambda keeps it testable, since BStatsHandle cannot be constructed under MockBukkit.

Chart ids are unchanged, so nothing needs re-registering on bstats.org.

Tests

Three existing tests encoded the old behavior and were inverted before the fix, so all four failures were observed red first. The new aCommandAndItsAliasAreCountedSeparately types /create-home once and /sethome twice; against the old code it failed with expected: <1> but was: <3>, and now reports command_create_home = 1, alias_sethome = 2. A new WindowShareTest case covers the multi-family total and asserts each family is still drained only once per submission.

mvn verify: 389 tests, 0 failures, 0 skipped.

Note for the dashboard

Expect a step down in the command_* lines where alias traffic used to be folded in. The metrics shipped in 2.0.0, so there is existing history under the old semantics.

Every invocation incremented both the command family under the canonical
name and the alias family under the typed label, so one /sethome reported
as a use of create-home as well. That made the alias charts useless for
the thing they exist for, deciding which labels to retire, because a
canonical chart could not be told apart from alias traffic.

An invocation now increments exactly one family: the canonical name goes
to command, anything else to alias. commands_total sums both families so
it keeps meaning every invocation whatever label was typed.

Expect a step down in the command_* lines on the dashboard where alias
traffic used to be folded in. Chart ids are unchanged.
@milanmalhotra
milanmalhotra merged commit ef126ea into dev Aug 22, 2026
5 checks passed
@milanmalhotra
milanmalhotra deleted the fix-metrics-label-double-count branch August 22, 2026 01:57
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