Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[refactor] move root span handler into aggregator #5478

Merged
merged 6 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions plugin/sampling/strategystore/adaptive/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,20 @@ func (a *aggregator) Close() error {
a.bgFinished.Wait()
return nil
}

func RecordThroughput(agg strategystore.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)
}
40 changes: 40 additions & 0 deletions plugin/sampling/strategystore/adaptive/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,43 @@ func TestLowerboundThroughput(t *testing.T) {
assert.EqualValues(t, 0, a.(*aggregator).currentThroughput["A"]["GET"].Count)
assert.Empty(t, a.(*aggregator).currentThroughput["A"]["GET"].Probabilities["0.001000"])
}

func TestRecordThroughput(t *testing.T) {
metricsFactory := metricstest.NewFactory(0)
mockStorage := &mocks.Store{}
mockEP := &epmocks.ElectionParticipant{}
testOpts := Options{
CalculationInterval: 1 * time.Second,
AggregationBuckets: 1,
BucketsForCalculation: 1,
}
logger := zap.NewNop()
a, err := NewAggregator(testOpts, logger, metricsFactory, mockEP, mockStorage)
require.NoError(t, err)

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

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

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

// 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)
assert.EqualValues(t, 1, a.(*aggregator).currentThroughput["A"]["GET"].Count)
}
Loading