Skip to content

Commit

Permalink
Remove deprecated index prefix from dependency store (#1637)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <ploffay@redhat.com>
  • Loading branch information
pavolloffay authored Jun 27, 2019
1 parent dec6114 commit 3181b98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
27 changes: 10 additions & 17 deletions plugin/storage/es/dependencystore/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,29 @@ const (

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

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

// WriteDependencies implements dependencystore.Writer#WriteDependencies.
func (s *DependencyStore) WriteDependencies(ts time.Time, dependencies []model.DependencyLink) error {
indexName := indexWithDate(s.dependencyIndexPrefix, ts)
indexName := indexWithDate(s.indexPrefix, ts)
if err := s.createIndex(indexName); err != nil {
return err
}
Expand All @@ -86,10 +82,7 @@ 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) {
indices := getIndices(s.dependencyIndexPrefix, endTs, lookback)
if s.dependencyIndexPrefix != s.dependencyIndexPrefixDeprecated {
indices = append(indices, getIndices(s.dependencyIndexPrefixDeprecated, endTs, lookback)...)
}
indices := getIndices(s.indexPrefix, endTs, lookback)
searchResult, err := s.client.Search(indices...).
Type(dependencyType).
Size(10000). // the default elasticsearch allowed limit
Expand Down
5 changes: 2 additions & 3 deletions plugin/storage/es/dependencystore/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestNewSpanReaderIndexPrefix(t *testing.T) {
for _, testCase := range testCases {
client := &mocks.Client{}
r := NewDependencyStore(client, zap.NewNop(), testCase.prefix)
assert.Equal(t, testCase.expected+dependencyIndex, r.dependencyIndexPrefix)
assert.Equal(t, testCase.expected+dependencyIndex, r.indexPrefix)
}
}

Expand Down Expand Up @@ -157,8 +157,7 @@ func TestGetDependencies(t *testing.T) {
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"},
indices: []interface{}{"foo-jaeger-dependencies-1995-04-21", "foo-jaeger-dependencies-1995-04-20"},
},
}
for _, testCase := range testCases {
Expand Down

0 comments on commit 3181b98

Please sign in to comment.