Skip to content

Commit

Permalink
[adaptive processor] Remove redundant function (#5953)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- The function was a duplicate of another public method

## Description of the changes
- Remove the function and redirect callsites to invoke HandleRootSpan
instead

## How was this change tested?
- CI

Signed-off-by: Yuri Shkuro <github@ysh.us>
  • Loading branch information
yurishkuro authored Sep 7, 2024
1 parent 364832f commit 88a0319
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (tp *traceProcessor) processTraces(_ context.Context, td ptrace.Traces) (pt
if span.Process == nil {
span.Process = batch.Process
}
adaptive.RecordThroughput(tp.aggregator, span, tp.telset.Logger)
tp.aggregator.HandleRootSpan(span, tp.telset.Logger)
}
}
return td, nil
Expand Down
17 changes: 0 additions & 17 deletions plugin/sampling/strategyprovider/adaptive/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,6 @@ func (a *aggregator) RecordThroughput(service, operation string, samplerType spa
}
}

func RecordThroughput(agg samplingstrategy.Aggregator, span *span_model.Span, logger *zap.Logger) {
// TODO simply checking parentId to determine if a span is a root span is not sufficient. However,
// we can be sure that only a root span will have sampler tags.
if span.ParentSpanID() != span_model.NewSpanID(0) {
return
}
service := span.Process.ServiceName
if service == "" || span.OperationName == "" {
return
}
samplerType, samplerParam := span.GetSamplerParams(logger)
if samplerType == span_model.SamplerTypeUnrecognized {
return
}
agg.RecordThroughput(service, span.OperationName, samplerType, samplerParam)
}

func (a *aggregator) Start() {
a.postAggregator.Start()

Expand Down
8 changes: 4 additions & 4 deletions plugin/sampling/strategyprovider/adaptive/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,27 @@ func TestRecordThroughputFunc(t *testing.T) {

// Testing non-root span
span := &model.Span{References: []model.SpanRef{{SpanID: model.NewSpanID(1), RefType: model.ChildOf}}}
RecordThroughput(a, span, logger)
a.HandleRootSpan(span, logger)
require.Empty(t, a.(*aggregator).currentThroughput)

// Testing span with service name but no operation
span.References = []model.SpanRef{}
span.Process = &model.Process{
ServiceName: "A",
}
RecordThroughput(a, span, logger)
a.HandleRootSpan(span, logger)
require.Empty(t, a.(*aggregator).currentThroughput)

// Testing span with service name and operation but no probabilistic sampling tags
span.OperationName = "GET"
RecordThroughput(a, span, logger)
a.HandleRootSpan(span, logger)
require.Empty(t, a.(*aggregator).currentThroughput)

// Testing span with service name, operation, and probabilistic sampling tags
span.Tags = model.KeyValues{
model.String("sampler.type", "probabilistic"),
model.String("sampler.param", "0.001"),
}
RecordThroughput(a, span, logger)
a.HandleRootSpan(span, logger)
assert.EqualValues(t, 1, a.(*aggregator).currentThroughput["A"]["GET"].Count)
}

0 comments on commit 88a0319

Please sign in to comment.