Skip to content
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

[processor/tailsampling] Improved "not sampled" decision cache usage #37189

Merged
merged 8 commits into from
Jan 17, 2025

Conversation

portertech
Copy link
Contributor

@portertech portertech commented Jan 14, 2025

Currently, a "not sampled" decision for a trace is only cached when late spans arrive for it. Whereas a "sampled" decision for a trace is immediately cached. This pull request immediately caches "not sampled" decisions, late spans (or reprocessed spans) for "not sampled" traces now take fewer resources to process.

Currently, traces are stored in memory until num_traces is reached, then the oldest is deleted to make room. This is a clever mechanism to limit the size* of the internal map, however, trace span counts and their contents likely vary considerably. This pull request doesn't touch this mechanism, but it does delete traces from the internal map after they are released and are added to a decision cache.

…l map if their trace id is in a decision cache

Signed-off-by: Sean Porter <portertech@gmail.com>
@portertech portertech requested review from jpkrohling and a team as code owners January 14, 2025 05:52
@github-actions github-actions bot added the processor/tailsampling Tail sampling processor label Jan 14, 2025
// IDs. If the trace ID is cached, it deletes the spans from the internal map.
func (tsp *tailSamplingSpanProcessor) releaseNotSampledTrace(id pcommon.TraceID) {
tsp.nonSampledIDCache.Put(id, true)
_, ok := tsp.nonSampledIDCache.Get(id)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This Get() would be unnecessary if the cache interface Put() returned bool, error. Saving for a potential future enhancement.

Copy link
Member

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

The change looks sane, but perhaps it could include a new test case?

@@ -386,8 +385,7 @@ func TestLateArrivingSpanUsesDecisionCache(t *testing.T) {
// The final decision SHOULD be Sampled.
require.EqualValues(t, 1, nextConsumer.SpanCount())

// Drop the trace to force cache to make decision
tsp.dropTrace(traceID, time.Now())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jpkrohling I was able to reuse the existing decision tests for the new functionality 👍 It was meant to be 😄

@portertech portertech requested a review from jpkrohling January 16, 2025 05:45
@jpkrohling jpkrohling merged commit cbcde1c into open-telemetry:main Jan 17, 2025
164 checks passed
@github-actions github-actions bot added this to the next release milestone Jan 17, 2025
chengchuanpeng pushed a commit to chengchuanpeng/opentelemetry-collector-contrib that referenced this pull request Jan 26, 2025
…pen-telemetry#37189)

Currently, a "not sampled" decision for a trace is only cached when late
spans arrive for it. Whereas a "sampled" decision for a trace is
immediately cached. This pull request immediately caches "not sampled"
decisions, late spans (or reprocessed spans) for "not sampled" traces
now take fewer resources to process.

Currently, traces are stored in memory until `num_traces` is reached,
then the oldest is deleted to make room. This is a clever mechanism to
limit the size* of the internal map, however, trace span counts and
their contents likely vary considerably. This pull request doesn't touch
this mechanism, but it does delete traces from the internal map after
they are released and are added to a decision cache.

---------

Signed-off-by: Sean Porter <portertech@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
processor/tailsampling Tail sampling processor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants