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

FEAT: Add Span Kind support for ES/OS #6399

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions cmd/jaeger/internal/integration/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ func TestElasticsearchStorage(t *testing.T) {
s := &E2EStorageIntegration{
ConfigFile: "../../config-elasticsearch.yaml",
StorageIntegration: integration.StorageIntegration{
CleanUp: purge,
Fixtures: integration.LoadAndParseQueryTestCases(t, "fixtures/queries_es.json"),
GetOperationsMissingSpanKind: true,
CleanUp: purge,
Fixtures: integration.LoadAndParseQueryTestCases(t, "fixtures/queries_es.json"),
},
}
s.e2eInitialize(t, "elasticsearch")
Expand Down
5 changes: 2 additions & 3 deletions cmd/jaeger/internal/integration/opensearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ func TestOpenSearchStorage(t *testing.T) {
s := &E2EStorageIntegration{
ConfigFile: "../../config-opensearch.yaml",
StorageIntegration: integration.StorageIntegration{
CleanUp: purge,
Fixtures: integration.LoadAndParseQueryTestCases(t, "fixtures/queries_es.json"),
GetOperationsMissingSpanKind: true,
CleanUp: purge,
Fixtures: integration.LoadAndParseQueryTestCases(t, "fixtures/queries_es.json"),
},
}
s.e2eInitialize(t, "opensearch")
Expand Down
6 changes: 6 additions & 0 deletions plugin/storage/es/spanstore/dbmodel/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ type Service struct {
ServiceName string `json:"serviceName"`
OperationName string `json:"operationName"`
}

// ServiceWithKind is the JSON struct service:kind:operation documents in ElasticSearch
type ServiceWithKind struct {
Service
Kind string `json:"spanKind"`
Copy link
Member

Choose a reason for hiding this comment

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

not sure I follow. Why wouldn't we just add Kind field to the Service struct above?

}
12 changes: 2 additions & 10 deletions plugin/storage/es/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,20 +306,12 @@ func (s *SpanReader) GetOperations(
currentTime,
cfg.RolloverFrequencyAsNegativeDuration(s.serviceIndex.RolloverFrequency),
)
operations, err := s.serviceOperationStorage.getOperations(ctx, jaegerIndices, query.ServiceName, s.maxDocCount)
operations, err := s.serviceOperationStorage.getOperations(ctx, jaegerIndices, query.ServiceName, query.SpanKind, s.maxDocCount)
if err != nil {
return nil, err
}

// TODO: https://github.com/jaegertracing/jaeger/issues/1923
// - return the operations with actual span kind that meet requirement
var result []spanstore.Operation
for _, operation := range operations {
result = append(result, spanstore.Operation{
Name: operation,
})
}
return result, err
return operations, err
}

func bucketToStringArray(buckets []*elastic.AggregationBucketKeyItem) ([]string, error) {
Expand Down
112 changes: 89 additions & 23 deletions plugin/storage/es/spanstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,33 +627,56 @@ func TestSpanReader_indexWithDate(t *testing.T) {
})
}

type testGetStruct struct {
caption string
searchResult *elastic.SearchResult
searchError error
expectedError func() string
expectedOutput map[string]any
}

func testGet(typ string, t *testing.T) {
testGetWithKind(typ, t, false)
}

func testGetWithKind(typ string, t *testing.T, testKind bool) {
goodAggregations := make(map[string]*json.RawMessage)
rawMessage := []byte(`{"buckets": [{"key": "123","doc_count": 16}]}`)
goodAggregations[typ] = (*json.RawMessage)(&rawMessage)

var filterRawMessage json.RawMessage
if typ == operationsAggregation {
if !testKind {
filterRawMessage = json.RawMessage(`
{
"buckets": {
"distinct_operations_without_kind": {
"doc_count": 1,
"operationName": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "123",
"doc_count": 16
}
]
}
}
}
}
`)
} else {
filterRawMessage = rawMessage
}
goodAggregations[typ] = &filterRawMessage
} else {
goodAggregations[typ] = (*json.RawMessage)(&rawMessage)
}
badAggregations := make(map[string]*json.RawMessage)
badRawMessage := []byte(`{"buckets": [{bad json]}asdf`)
badAggregations[typ] = (*json.RawMessage)(&badRawMessage)

testCases := []struct {
caption string
searchResult *elastic.SearchResult
searchError error
expectedError func() string
expectedOutput map[string]any
}{
{
caption: typ + " full behavior",
searchResult: &elastic.SearchResult{Aggregations: elastic.Aggregations(goodAggregations)},
expectedOutput: map[string]any{
operationsAggregation: []spanstore.Operation{{Name: "123"}},
"default": []string{"123"},
},
expectedError: func() string {
return ""
},
},
testCases := []testGetStruct{
{
caption: typ + " search error",
searchError: errors.New("Search failure"),
Expand All @@ -672,13 +695,42 @@ func testGet(typ string, t *testing.T) {
},
},
}
if testKind {
testCases = append(testCases, testGetStruct{
caption: typ + " full behavior with kind",
searchResult: &elastic.SearchResult{Aggregations: goodAggregations},
expectedOutput: map[string]any{
operationsAggregation: []spanstore.Operation{{Name: "123", SpanKind: "server"}},
"default": []string{"123"},
},
expectedError: func() string {
return ""
},
})
} else {
testCases = append(testCases, testGetStruct{
caption: typ + " full behavior",
searchResult: &elastic.SearchResult{Aggregations: goodAggregations},
expectedOutput: map[string]any{
operationsAggregation: []spanstore.Operation{{Name: "123"}},
"default": []string{"123"},
},
expectedError: func() string {
return ""
},
})
}

for _, tc := range testCases {
testCase := tc
t.Run(testCase.caption, func(t *testing.T) {
withSpanReader(t, func(r *spanReaderTest) {
mockSearchService(r).Return(testCase.searchResult, testCase.searchError)
actual, err := returnSearchFunc(typ, r)
if testKind {
mockSearchServiceWithSpanKind(r, true).Return(testCase.searchResult, testCase.searchError)
} else {
mockSearchService(r).Return(testCase.searchResult, testCase.searchError)
}
actual, err := returnSearchFunc(typ, r, testKind)
if testCase.expectedError() != "" {
require.EqualError(t, err, testCase.expectedError())
assert.Nil(t, actual)
Expand All @@ -692,11 +744,17 @@ func testGet(typ string, t *testing.T) {
}
}

func returnSearchFunc(typ string, r *spanReaderTest) (any, error) {
func returnSearchFunc(typ string, r *spanReaderTest, testKind bool) (any, error) {
switch typ {
case servicesAggregation:
return r.reader.GetServices(context.Background())
case operationsAggregation:
if testKind {
return r.reader.GetOperations(
context.Background(),
spanstore.OperationQueryParameters{ServiceName: "someservice", SpanKind: "server"},
)
}
return r.reader.GetOperations(
context.Background(),
spanstore.OperationQueryParameters{ServiceName: "someService"},
Expand Down Expand Up @@ -1012,14 +1070,22 @@ func matchTermsAggregation(termsAgg *elastic.TermsAggregation) bool {
}

func mockSearchService(r *spanReaderTest) *mock.Call {
return mockSearchServiceWithSpanKind(r, false)
}

func mockSearchServiceWithSpanKind(r *spanReaderTest, inputHasSpanKind bool) *mock.Call {
searchService := &mocks.SearchService{}
searchService.On("Query", mock.Anything).Return(searchService)
searchService.On("IgnoreUnavailable", mock.AnythingOfType("bool")).Return(searchService)
searchService.On("Size", mock.MatchedBy(func(size int) bool {
return size == 0 // Aggregations apply size (bucket) limits in their own query objects, and do not apply at the parent query level.
})).Return(searchService)
searchService.On("Aggregation", stringMatcher(servicesAggregation), mock.MatchedBy(matchTermsAggregation)).Return(searchService)
searchService.On("Aggregation", stringMatcher(operationsAggregation), mock.MatchedBy(matchTermsAggregation)).Return(searchService)
if inputHasSpanKind {
searchService.On("Aggregation", stringMatcher(operationsAggregation), mock.MatchedBy(matchTermsAggregation)).Return(searchService)
} else {
searchService.On("Aggregation", stringMatcher(operationsAggregation), mock.AnythingOfType("*elastic.FiltersAggregation")).Return(searchService)
}
searchService.On("Aggregation", stringMatcher(traceIDAggregation), mock.AnythingOfType("*elastic.TermsAggregation")).Return(searchService)
r.client.On("Search", mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(searchService)
return searchService.On("Do", mock.Anything)
Expand Down
Loading
Loading