Skip to content

Add StatsDCounterKey/StatsDCountReporter glue for Accumulator - #12360

Closed
dougqh wants to merge 2 commits into
dougqh/accumulator-primitivefrom
dougqh/accumulator-metric-binding
Closed

dougqh wants to merge 2 commits into
dougqh/accumulator-primitivefrom
dougqh/accumulator-metric-binding

Conversation

@dougqh

@dougqh dougqh commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Adds StatsDCounterKey and StatsDCountReporter in products/metrics/metrics-api: reusable glue that lets an enum used as an Accumulator key declare its own dogstatsd metric name at the declaration site, and drains an Accumulator.accumulateAndReset(...) result to a StatsDClient in one call, skipping zero-delta counters.

This is groundwork only -- no caller is wired in yet. The natural first caller is TracerHealthMetrics (currently ~49 individual LongAdder fields, each diffed by hand against a fixed-size previousCounts array), but that migration is scoped to a separate follow-up PR.

Motivation

Accumulator (#12351) has no consumer yet. Before wiring one in, this PR builds the small reusable piece that makes adoption mechanical: one interface for an enum to name its own metric, one static helper to report a drained counter array. Keeping this separate from the TracerHealthMetrics migration keeps that follow-up PR focused on the migration itself rather than also inventing this glue inline.

This is explicitly a consolidation move: the codebase already has several ad hoc ways to get a counter's value to a metrics sink (CoreCounter/StatsMetrics.TaggedCounter, the MetricCollector SPI, CiVisibilityCountMetric's tag-combination encoding). None of them fit Accumulator's enum-ordinal, tag-less shape, so this adds the smallest new piece rather than reusing a mismatched one -- see the design note in StatsDCounterKey's Javadoc for the intended usage shape.

Additional Notes

  • products/metrics/metrics-api had no test dependencies before this PR; added testImplementation(libs.bundles.junit5) (matches the pattern in sibling modules metrics-lib, feature-flagging-api).
  • Test plan:
    • ./gradlew :products:metrics:metrics-api:test --tests "datadog.metrics.api.statsd.StatsDCountReporterTest" -- all pass
    • ./gradlew :products:metrics:metrics-api:spotlessCheck -- clean
    • /techdebt and /perf-review run over branch changes -- no findings on either pass

Contributor Checklist

  • Format the title according to the contribution guidelines
  • Assign the type: and (comp: or inst:) labels in addition to any other useful labels
  • Avoid using close, fix, or any linking keywords when referencing an issue
  • Update the CODEOWNERS file on source file addition, migration, or deletion
  • Update public documentation with any new configuration flags or behaviors
  • Once approved, use merge queue to merge the PR

Jira ticket: APMLP-1779

dougqh and others added 2 commits September 1, 2026 08:42
Lets an enum used as an Accumulator key declare its own dogstatsd
metric name, and drains an Accumulator.accumulateAndReset() result to
StatsDClient in one call. No caller wired in yet -- TracerHealthMetrics
migration is a follow-up PR.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds JUnit5 test dependency to metrics-api (previously had none),
a RecordingStatsDClient test fake, and coverage for non-zero/zero/
negative deltas and tag pass-through.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dougqh dougqh added type: feature Enhancements and improvements comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes labels Sep 1, 2026
@datadog-official

datadog-official Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 58.80% (-0.06%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 264a2ef | Docs | View more details | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.90 s 13.95 s [-0.9%; +0.2%] (no difference)
startup:insecure-bank:tracing:Agent 12.91 s 13.06 s [-2.0%; -0.3%] (maybe better)
startup:petclinic:appsec:Agent 16.90 s 16.76 s [-0.3%; +1.9%] (no difference)
startup:petclinic:iast:Agent 16.91 s 16.90 s [-0.8%; +0.9%] (no difference)
startup:petclinic:profiling:Agent 16.70 s 16.72 s [-1.3%; +1.0%] (no difference)
startup:petclinic:sca:Agent 16.62 s 16.38 s [+0.6%; +2.4%] (maybe worse)
startup:petclinic:tracing:Agent 16.05 s 15.96 s [-0.2%; +1.3%] (no difference)

Commit: 264a2ef4 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@dougqh

dougqh commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #12351 — the StatsDCounterKey/StatsDCountReporter glue landed there in a more complete form (pending-delta retry, RunningTotal, etc.), so this branch would now revert that work rather than add to it.

@dougqh dougqh closed this Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant