Skip to content

Commit 617b0bb

Browse files
authored
[processor/tailsampling] Fixed sampling policy evaluation debug logging batch metrics (#37040)
#### Description Currently, the processor always logs (at debug) `sampled=0` and `notSampled=0` for every batch processed. This pull-request fixes those metrics. --------- Signed-off-by: Sean Porter <[email protected]>
1 parent d3f65e7 commit 617b0bb

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: tailsamplingprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fixed sampling policy evaluation debug logging batch metrics (e.g. sampled).
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [37040]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

processor/tailsamplingprocessor/processor.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,13 @@ func (tsp *tailSamplingSpanProcessor) makeDecision(id pcommon.TraceID, trace *sa
404404
finalDecision = sampling.Sampled
405405
}
406406

407+
switch finalDecision {
408+
case sampling.Sampled:
409+
metrics.decisionSampled++
410+
case sampling.NotSampled:
411+
metrics.decisionNotSampled++
412+
}
413+
407414
return finalDecision
408415
}
409416

processor/tailsamplingprocessor/processor_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,46 @@ func TestDuplicatePolicyName(t *testing.T) {
609609
assert.Equal(t, err, errors.New(`duplicate policy name "always_sample"`))
610610
}
611611

612+
func TestDecisionPolicyMetrics(t *testing.T) {
613+
traceIDs, batches := generateIDsAndBatches(10)
614+
policy := []PolicyCfg{
615+
{
616+
sharedPolicyCfg: sharedPolicyCfg{
617+
Name: "test-policy",
618+
Type: Probabilistic,
619+
ProbabilisticCfg: ProbabilisticCfg{SamplingPercentage: 50},
620+
},
621+
},
622+
}
623+
cfg := Config{
624+
DecisionWait: defaultTestDecisionWait,
625+
NumTraces: uint64(2 * len(traceIDs)),
626+
ExpectedNewTracesPerSec: 64,
627+
PolicyCfgs: policy,
628+
}
629+
sp, _ := newTracesProcessor(context.Background(), processortest.NewNopSettings(), consumertest.NewNop(), cfg)
630+
tsp := sp.(*tailSamplingSpanProcessor)
631+
require.NoError(t, tsp.Start(context.Background(), componenttest.NewNopHost()))
632+
defer func() {
633+
require.NoError(t, tsp.Shutdown(context.Background()))
634+
}()
635+
metrics := &policyMetrics{}
636+
637+
for i, id := range traceIDs {
638+
sb := &sampling.TraceData{
639+
ArrivalTime: time.Now(),
640+
ReceivedBatches: batches[i],
641+
}
642+
643+
_ = tsp.makeDecision(id, sb, metrics)
644+
}
645+
646+
assert.EqualValues(t, 5, metrics.decisionSampled)
647+
assert.EqualValues(t, 5, metrics.decisionNotSampled)
648+
assert.EqualValues(t, 0, metrics.idNotFoundOnMapCount)
649+
assert.EqualValues(t, 0, metrics.evaluateErrorCount)
650+
}
651+
612652
func collectSpanIDs(trace ptrace.Traces) []pcommon.SpanID {
613653
var spanIDs []pcommon.SpanID
614654

0 commit comments

Comments
 (0)