-
Notifications
You must be signed in to change notification settings - Fork 355
Migrate TracerHealthMetrics onto the Accumulator primitive #12383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
dougqh
wants to merge
15
commits into
dougqh/accumulator-primitive
Choose a base branch
from
dougqh/accumulator-tracerhealthmetrics
base: dougqh/accumulator-primitive
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bcbcb2e
Migrate TracerHealthMetrics onto the Accumulator primitive
dougqh 859c547
Address review: rename metricAccumulator, seed storedTotal via Counts…
dougqh 86cca63
Use contextual Accumulator.update() to avoid capturing trace/count lo…
dougqh b07ec8e
Report a drained Counts directly instead of pairing values() with a m…
dougqh 15280e8
Follow Counts.values() -> Counts.keys() rename
dougqh 26e55b9
Use the boxing-free long-context update overload, and pass response a…
dougqh d9a6afc
Flip TracerHealthMetric ctor arg order, drop the shared NO_TAGS instance
dougqh b0e4b3a
Drop reportedInSummary; report org_guard counters in summary() too, f…
dougqh 3ce265c
Make TracerHealthMetric's tags varargs and inline the tag literals
dougqh 5bc8e98
Add a direct JMH benchmark for TracerHealthMetrics's Accumulator-back…
dougqh 157d441
Add legacy LongAdder comparison to TracerHealthMetricsBenchmark
dougqh 3ea8479
Replace Accumulator's synchronized stripes with lock-free AtomicLongA…
dougqh 97041a6
Simplify TracerHealthMetrics for the lock-free Accumulator; nest Trac…
dougqh e865df7
Correct AccumulatorBenchmark javadoc's high-contention drain numbers
dougqh fd086e5
Update TracerHealthMetricsBenchmark javadoc for the lock-free Accumul…
dougqh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
264 changes: 264 additions & 0 deletions
264
dd-trace-core/src/jmh/java/datadog/trace/core/monitor/LegacyTracerHealthMetrics.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,264 @@ | ||
| package datadog.trace.core.monitor; | ||
|
|
||
| import static datadog.trace.api.sampling.PrioritySampling.SAMPLER_DROP; | ||
| import static datadog.trace.api.sampling.PrioritySampling.SAMPLER_KEEP; | ||
| import static datadog.trace.api.sampling.PrioritySampling.USER_DROP; | ||
| import static datadog.trace.api.sampling.PrioritySampling.USER_KEEP; | ||
|
|
||
| import datadog.metrics.api.statsd.StatsDClient; | ||
| import datadog.trace.common.writer.RemoteApi; | ||
| import java.util.concurrent.atomic.LongAdder; | ||
|
|
||
| /** | ||
| * A faithful reconstruction of the pre-{@code Accumulator} {@code TracerHealthMetrics} -- one | ||
| * {@link LongAdder} field per counter, hand-rolled switch statements, a hand-concatenated {@code | ||
| * summary()} -- as it stood at {@code 77964b3996} (the last commit on {@code master} before the | ||
| * migration), restricted to the exact methods {@link TracerHealthMetricsBenchmark} exercises. Kept | ||
| * as a standalone class here (not resurrected via checkout) purely for a same-run, same-JVM | ||
| * before/after comparison; it is not wired into anything and should never be. | ||
| */ | ||
| class LegacyTracerHealthMetrics { | ||
|
|
||
| private final LongAdder apiRequests = new LongAdder(); | ||
| private final LongAdder apiErrors = new LongAdder(); | ||
| private final LongAdder apiResponsesOK = new LongAdder(); | ||
|
|
||
| private final LongAdder userDropEnqueuedTraces = new LongAdder(); | ||
| private final LongAdder userKeepEnqueuedTraces = new LongAdder(); | ||
| private final LongAdder samplerDropEnqueuedTraces = new LongAdder(); | ||
| private final LongAdder samplerKeepEnqueuedTraces = new LongAdder(); | ||
| private final LongAdder unsetPriorityEnqueuedTraces = new LongAdder(); | ||
|
|
||
| private final LongAdder userDropDroppedTraces = new LongAdder(); | ||
| private final LongAdder userKeepDroppedTraces = new LongAdder(); | ||
| private final LongAdder samplerDropDroppedTraces = new LongAdder(); | ||
| private final LongAdder samplerKeepDroppedTraces = new LongAdder(); | ||
| private final LongAdder serialFailedDroppedTraces = new LongAdder(); | ||
| private final LongAdder unsetPriorityDroppedTraces = new LongAdder(); | ||
|
|
||
| private final LongAdder userDropDroppedSpans = new LongAdder(); | ||
| private final LongAdder userKeepDroppedSpans = new LongAdder(); | ||
| private final LongAdder samplerDropDroppedSpans = new LongAdder(); | ||
| private final LongAdder samplerKeepDroppedSpans = new LongAdder(); | ||
| private final LongAdder serialFailedDroppedSpans = new LongAdder(); | ||
| private final LongAdder unsetPriorityDroppedSpans = new LongAdder(); | ||
|
|
||
| private final LongAdder enqueuedSpans = new LongAdder(); | ||
| private final LongAdder enqueuedBytes = new LongAdder(); | ||
| private final LongAdder createdTraces = new LongAdder(); | ||
| private final LongAdder createdSpans = new LongAdder(); | ||
| private final LongAdder finishedSpans = new LongAdder(); | ||
| private final LongAdder flushedTraces = new LongAdder(); | ||
| private final LongAdder flushedBytes = new LongAdder(); | ||
| private final LongAdder partialTraces = new LongAdder(); | ||
| private final LongAdder partialBytes = new LongAdder(); | ||
| private final LongAdder clientSpansWithoutContext = new LongAdder(); | ||
|
|
||
| private final LongAdder singleSpanSampled = new LongAdder(); | ||
| private final LongAdder singleSpanUnsampled = new LongAdder(); | ||
|
|
||
| private final LongAdder capturedContinuations = new LongAdder(); | ||
| private final LongAdder cancelledContinuations = new LongAdder(); | ||
| private final LongAdder finishedContinuations = new LongAdder(); | ||
|
|
||
| private final LongAdder activatedScopes = new LongAdder(); | ||
| private final LongAdder closedScopes = new LongAdder(); | ||
| private final LongAdder scopeStackOverflow = new LongAdder(); | ||
| private final LongAdder scopeCloseErrors = new LongAdder(); | ||
| private final LongAdder userScopeCloseErrors = new LongAdder(); | ||
|
|
||
| private final LongAdder longRunningTracesWrite = new LongAdder(); | ||
| private final LongAdder longRunningTracesDropped = new LongAdder(); | ||
| private final LongAdder longRunningTracesExpired = new LongAdder(); | ||
|
|
||
| private final LongAdder clientStatsProcessedSpans = new LongAdder(); | ||
| private final LongAdder clientStatsProcessedTraces = new LongAdder(); | ||
| private final LongAdder clientStatsP0DroppedSpans = new LongAdder(); | ||
| private final LongAdder clientStatsP0DroppedTraces = new LongAdder(); | ||
| private final LongAdder clientStatsRequests = new LongAdder(); | ||
| private final LongAdder clientStatsErrors = new LongAdder(); | ||
| private final LongAdder clientStatsDowngrades = new LongAdder(); | ||
|
|
||
| private final LongAdder statsAggregateDropped = new LongAdder(); | ||
| private final LongAdder statsInboxFull = new LongAdder(); | ||
|
|
||
| private final StatsDClient statsd; | ||
|
|
||
| LegacyTracerHealthMetrics(StatsDClient statsd) { | ||
| this.statsd = statsd; | ||
| } | ||
|
|
||
| void onCreateSpan() { | ||
| createdSpans.increment(); | ||
| } | ||
|
|
||
| void onFailedPublish(final int samplingPriority, final int spanCount) { | ||
| switch (samplingPriority) { | ||
| case USER_DROP: | ||
| userDropDroppedSpans.add(spanCount); | ||
| userDropDroppedTraces.increment(); | ||
| break; | ||
| case USER_KEEP: | ||
| userKeepDroppedSpans.add(spanCount); | ||
| userKeepDroppedTraces.increment(); | ||
| break; | ||
| case SAMPLER_DROP: | ||
| samplerDropDroppedSpans.add(spanCount); | ||
| samplerDropDroppedTraces.increment(); | ||
| break; | ||
| case SAMPLER_KEEP: | ||
| samplerKeepDroppedSpans.add(spanCount); | ||
| samplerKeepDroppedTraces.increment(); | ||
| break; | ||
| default: | ||
| unsetPriorityDroppedSpans.add(spanCount); | ||
| unsetPriorityDroppedTraces.increment(); | ||
| } | ||
| } | ||
|
|
||
| void onPartialPublish(final int numberOfDroppedSpans) { | ||
| partialTraces.increment(); | ||
| samplerDropDroppedSpans.add(numberOfDroppedSpans); | ||
| } | ||
|
|
||
| void onSend(final int traceCount, final int sizeInBytes, final RemoteApi.Response response) { | ||
| onSendAttempt(traceCount, sizeInBytes, response); | ||
| } | ||
|
|
||
| private void onSendAttempt( | ||
| final int traceCount, final int sizeInBytes, final RemoteApi.Response response) { | ||
| apiRequests.increment(); | ||
| flushedTraces.add(traceCount); | ||
| flushedBytes.add(sizeInBytes); | ||
|
|
||
| if (response.exception().isPresent()) { | ||
| apiErrors.increment(); | ||
| } | ||
|
|
||
| int status = response.status().orElse(0); | ||
| if (status != 0) { | ||
| if (200 == status) { | ||
| apiResponsesOK.increment(); | ||
| } else { | ||
| statsd.incrementCounter("api.responses.total", "status:" + status); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| String summary() { | ||
| return "apiRequests=" | ||
| + apiRequests.sum() | ||
| + "\napiErrors=" | ||
| + apiErrors.sum() | ||
| + "\napiResponsesOK=" | ||
| + apiResponsesOK.sum() | ||
| + "\n" | ||
| + "\nuserDropEnqueuedTraces=" | ||
| + userDropEnqueuedTraces.sum() | ||
| + "\nuserKeepEnqueuedTraces=" | ||
| + userKeepEnqueuedTraces.sum() | ||
| + "\nsamplerDropEnqueuedTraces=" | ||
| + samplerDropEnqueuedTraces.sum() | ||
| + "\nsamplerKeepEnqueuedTraces=" | ||
| + samplerKeepEnqueuedTraces.sum() | ||
| + "\nunsetPriorityEnqueuedTraces=" | ||
| + unsetPriorityEnqueuedTraces.sum() | ||
| + "\n" | ||
| + "\nuserDropDroppedTraces=" | ||
| + userDropDroppedTraces.sum() | ||
| + "\nuserKeepDroppedTraces=" | ||
| + userKeepDroppedTraces.sum() | ||
| + "\nsamplerDropDroppedTraces=" | ||
| + samplerDropDroppedTraces.sum() | ||
| + "\nsamplerKeepDroppedTraces=" | ||
| + samplerKeepDroppedTraces.sum() | ||
| + "\nserialFailedDroppedTraces=" | ||
| + serialFailedDroppedTraces.sum() | ||
| + "\nunsetPriorityDroppedTraces=" | ||
| + unsetPriorityDroppedTraces.sum() | ||
| + "\n" | ||
| + "\nuserDropDroppedSpans=" | ||
| + userDropDroppedSpans.sum() | ||
| + "\nuserKeepDroppedSpans=" | ||
| + userKeepDroppedSpans.sum() | ||
| + "\nsamplerDropDroppedSpans=" | ||
| + samplerDropDroppedSpans.sum() | ||
| + "\nsamplerKeepDroppedSpans=" | ||
| + samplerKeepDroppedSpans.sum() | ||
| + "\nserialFailedDroppedSpans=" | ||
| + serialFailedDroppedSpans.sum() | ||
| + "\nunsetPriorityDroppedSpans=" | ||
| + unsetPriorityDroppedSpans.sum() | ||
| + "\n" | ||
| + "\nenqueuedSpans=" | ||
| + enqueuedSpans.sum() | ||
| + "\nenqueuedBytes=" | ||
| + enqueuedBytes.sum() | ||
| + "\ncreatedTraces=" | ||
| + createdTraces.sum() | ||
| + "\ncreatedSpans=" | ||
| + createdSpans.sum() | ||
| + "\nfinishedSpans=" | ||
| + finishedSpans.sum() | ||
| + "\nflushedTraces=" | ||
| + flushedTraces.sum() | ||
| + "\nflushedBytes=" | ||
| + flushedBytes.sum() | ||
| + "\npartialTraces=" | ||
| + partialTraces.sum() | ||
| + "\npartialBytes=" | ||
| + partialBytes.sum() | ||
| + "\n" | ||
| + "\nclientSpansWithoutContext=" | ||
| + clientSpansWithoutContext.sum() | ||
| + "\n" | ||
| + "\nsingleSpanSampled=" | ||
| + singleSpanSampled.sum() | ||
| + "\nsingleSpanUnsampled=" | ||
| + singleSpanUnsampled.sum() | ||
| + "\n" | ||
| + "\ncapturedContinuations=" | ||
| + capturedContinuations.sum() | ||
| + "\ncancelledContinuations=" | ||
| + cancelledContinuations.sum() | ||
| + "\nfinishedContinuations=" | ||
| + finishedContinuations.sum() | ||
| + "\n" | ||
| + "\nactivatedScopes=" | ||
| + activatedScopes.sum() | ||
| + "\nclosedScopes=" | ||
| + closedScopes.sum() | ||
| + "\nscopeStackOverflow=" | ||
| + scopeStackOverflow.sum() | ||
| + "\nscopeCloseErrors=" | ||
| + scopeCloseErrors.sum() | ||
| + "\nuserScopeCloseErrors=" | ||
| + userScopeCloseErrors.sum() | ||
| + "\n" | ||
| + "\nlongRunningTracesWrite=" | ||
| + longRunningTracesWrite.sum() | ||
| + "\nlongRunningTracesDropped=" | ||
| + longRunningTracesDropped.sum() | ||
| + "\nlongRunningTracesExpired=" | ||
| + longRunningTracesExpired.sum() | ||
| + "\n" | ||
| + "\nclientStatsRequests=" | ||
| + clientStatsRequests.sum() | ||
| + "\nclientStatsErrors=" | ||
| + clientStatsErrors.sum() | ||
| + "\nclientStatsDowngrades=" | ||
| + clientStatsDowngrades.sum() | ||
| + "\nclientStatsP0DroppedSpans=" | ||
| + clientStatsP0DroppedSpans.sum() | ||
| + "\nclientStatsP0DroppedTraces=" | ||
| + clientStatsP0DroppedTraces.sum() | ||
| + "\nclientStatsProcessedSpans=" | ||
| + clientStatsProcessedSpans.sum() | ||
| + "\nclientStatsProcessedTraces=" | ||
| + clientStatsProcessedTraces.sum() | ||
| + "\nstatsAggregateDropped=" | ||
| + statsAggregateDropped.sum() | ||
| + "\nstatsInboxFull=" | ||
| + statsInboxFull.sum(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll probably remove this from the final PR, but for now, it shows the performance difference.