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

Deprecate colon in index prefix in ES dependency store #1386

Merged
Merged
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
29 changes: 19 additions & 10 deletions plugin/storage/es/dependencystore/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,27 @@ const (

// DependencyStore handles all queries and insertions to ElasticSearch dependencies
type DependencyStore struct {
ctx context.Context
client es.Client
logger *zap.Logger
dependencyIndexPrefix string
ctx context.Context
client es.Client
logger *zap.Logger
dependencyIndexPrefix string
dependencyIndexPrefixDeprecated string
}

// NewDependencyStore returns a DependencyStore
func NewDependencyStore(client es.Client, logger *zap.Logger, indexPrefix string) *DependencyStore {
var prefix string
var prefixDeprecated string
if indexPrefix != "" {
indexPrefix += ":"
prefix = indexPrefix + "-"
prefixDeprecated = indexPrefix + ":"
}
return &DependencyStore{
ctx: context.Background(),
client: client,
logger: logger,
dependencyIndexPrefix: indexPrefix + dependencyIndex,
ctx: context.Background(),
client: client,
logger: logger,
dependencyIndexPrefix: prefix + dependencyIndex,
dependencyIndexPrefixDeprecated: prefixDeprecated + dependencyIndex,
}
}

Expand Down Expand Up @@ -81,7 +86,11 @@ func (s *DependencyStore) writeDependencies(indexName string, ts time.Time, depe

// GetDependencies returns all interservice dependencies
func (s *DependencyStore) GetDependencies(endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error) {
searchResult, err := s.client.Search(getIndices(s.dependencyIndexPrefix, endTs, lookback)...).
indices := getIndices(s.dependencyIndexPrefix, endTs, lookback)
if s.dependencyIndexPrefix != s.dependencyIndexPrefixDeprecated {
indices = append(indices, getIndices(s.dependencyIndexPrefixDeprecated, endTs, lookback)...)
}
searchResult, err := s.client.Search(indices...).
Type(dependencyType).
Size(10000). // the default elasticsearch allowed limit
Query(buildTSQuery(endTs, lookback)).
Expand Down
27 changes: 19 additions & 8 deletions plugin/storage/es/dependencystore/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ type depStorageTest struct {
storage *DependencyStore
}

func withDepStorage(fn func(r *depStorageTest)) {
func withDepStorage(indexPrefix string, fn func(r *depStorageTest)) {
client := &mocks.Client{}
logger, logBuffer := testutils.NewLogger()
r := &depStorageTest{
client: client,
logger: logger,
logBuffer: logBuffer,
storage: NewDependencyStore(client, logger, ""),
storage: NewDependencyStore(client, logger, indexPrefix),
}
fn(r)
}
Expand All @@ -60,8 +60,8 @@ func TestNewSpanReaderIndexPrefix(t *testing.T) {
expected string
}{
{prefix: "", expected: ""},
{prefix: "foo", expected: "foo:"},
{prefix: ":", expected: "::"},
{prefix: "foo", expected: "foo-"},
{prefix: ":", expected: ":-"},
}
for _, testCase := range testCases {
client := &mocks.Client{}
Expand All @@ -83,7 +83,7 @@ func TestWriteDependencies(t *testing.T) {
{},
}
for _, testCase := range testCases {
withDepStorage(func(r *depStorageTest) {
withDepStorage("", func(r *depStorageTest) {
fixedTime := time.Date(1995, time.April, 21, 4, 21, 19, 95, time.UTC)
indexName := indexWithDate("", fixedTime)

Expand Down Expand Up @@ -129,6 +129,8 @@ func TestGetDependencies(t *testing.T) {
searchError error
expectedError string
expectedOutput []model.DependencyLink
indexPrefix string
indices []interface{}
}{
{
searchResult: createSearchResult(goodDependencies),
Expand All @@ -139,23 +141,32 @@ func TestGetDependencies(t *testing.T) {
CallCount: 12,
},
},
indices: []interface{}{"jaeger-dependencies-1995-04-21", "jaeger-dependencies-1995-04-20"},
},
{
searchResult: createSearchResult(badDependencies),
expectedError: "Unmarshalling ElasticSearch documents failed",
indices: []interface{}{"jaeger-dependencies-1995-04-21", "jaeger-dependencies-1995-04-20"},
},
{
searchError: errors.New("search failure"),
expectedError: "Failed to search for dependencies: search failure",
indices: []interface{}{"jaeger-dependencies-1995-04-21", "jaeger-dependencies-1995-04-20"},
},
{
searchError: errors.New("search failure"),
expectedError: "Failed to search for dependencies: search failure",
indexPrefix: "foo",
indices: []interface{}{"foo-jaeger-dependencies-1995-04-21", "foo-jaeger-dependencies-1995-04-20",
"foo:jaeger-dependencies-1995-04-21", "foo:jaeger-dependencies-1995-04-20"},
},
}
for _, testCase := range testCases {
withDepStorage(func(r *depStorageTest) {
withDepStorage(testCase.indexPrefix, func(r *depStorageTest) {
fixedTime := time.Date(1995, time.April, 21, 4, 21, 19, 95, time.UTC)
indices := []string{"jaeger-dependencies-1995-04-21", "jaeger-dependencies-1995-04-20"}

searchService := &mocks.SearchService{}
r.client.On("Search", indices[0], indices[1]).Return(searchService)
r.client.On("Search", testCase.indices...).Return(searchService)

searchService.On("Type", stringMatcher(dependencyType)).Return(searchService)
searchService.On("Size", mock.Anything).Return(searchService)
Expand Down