Skip to content

Commit

Permalink
Change separator in index prefix from : to - (#1284)
Browse files Browse the repository at this point in the history
* Change index prefix from : to -

The readers will still read from indices containing prefix "prefix:"
to keep backward compability.

Signed-off-by: Pavol Loffay <[email protected]>

* Change prefix in index cleaner

Signed-off-by: Pavol Loffay <[email protected]>
  • Loading branch information
pavolloffay authored Jan 18, 2019
1 parent 3a3a5e0 commit 4e3551c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion plugin/storage/es/esCleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def main():

prefix = os.getenv("INDEX_PREFIX", '')
if prefix != '':
prefix += ':'
prefix += '-'
prefix += 'jaeger'

ilo.filter_by_regex(kind='prefix', value=prefix)
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
flagSet.String(
nsConfig.namespace+suffixIndexPrefix,
nsConfig.IndexPrefix,
"Optional prefix of Jaeger indices. For example \"production\" creates \"production:jaeger-*\".")
"Optional prefix of Jaeger indices. For example \"production\" creates \"production-jaeger-*\".")
flagSet.Bool(
nsConfig.namespace+suffixTagsAsFieldsAll,
nsConfig.AllTagsAsFields,
Expand Down
45 changes: 27 additions & 18 deletions plugin/storage/es/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ import (
)

const (
spanIndex = "jaeger-span-"
serviceIndex = "jaeger-service-"
traceIDAggregation = "traceIDs"
spanIndex = "jaeger-span-"
serviceIndex = "jaeger-service-"
traceIDAggregation = "traceIDs"
indexPrefixSeparator = "-"
indexPrefixSeparatorDeprecated = ":"

traceIDField = "traceID"
durationField = "duration"
Expand Down Expand Up @@ -94,8 +96,8 @@ type SpanReader struct {
maxSpanAge time.Duration
maxNumSpans int
serviceOperationStorage *ServiceOperationStorage
spanIndexPrefix string
serviceIndexPrefix string
spanIndexPrefix []string
serviceIndexPrefix []string
spanConverter dbmodel.ToDomain
}

Expand All @@ -118,22 +120,26 @@ func NewSpanReader(p SpanReaderParams) spanstore.Reader {

func newSpanReader(p SpanReaderParams) *SpanReader {
ctx := context.Background()
if p.IndexPrefix != "" {
p.IndexPrefix += ":"
}
return &SpanReader{
ctx: ctx,
client: p.Client,
logger: p.Logger,
maxSpanAge: p.MaxSpanAge,
maxNumSpans: p.MaxNumSpans,
serviceOperationStorage: NewServiceOperationStorage(ctx, p.Client, p.Logger, 0), // the decorator takes care of metrics
spanIndexPrefix: p.IndexPrefix + spanIndex,
serviceIndexPrefix: p.IndexPrefix + serviceIndex,
spanIndexPrefix: indexNames(p.IndexPrefix, spanIndex),
serviceIndexPrefix: indexNames(p.IndexPrefix, serviceIndex),
spanConverter: dbmodel.NewToDomain(p.TagDotReplacement),
}
}

func indexNames(prefix, index string) []string {
if prefix != "" {
return []string{prefix + indexPrefixSeparator + index, prefix + indexPrefixSeparatorDeprecated + index}
}
return []string{index}
}

// GetTrace takes a traceID and returns a Trace associated with that traceID
func (s *SpanReader) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "GetTrace")
Expand Down Expand Up @@ -177,16 +183,19 @@ func (s *SpanReader) unmarshalJSONSpan(esSpanRaw *elastic.SearchHit) (*dbmodel.S
}

// Returns the array of indices that we need to query, based on query params
func (s *SpanReader) indicesForTimeRange(indexName string, startTime time.Time, endTime time.Time) []string {
func (s *SpanReader) indicesForTimeRange(indexNames []string, startTime time.Time, endTime time.Time) []string {
var indices []string
firstIndex := indexWithDate(indexName, startTime)
currentIndex := indexWithDate(indexName, endTime)
for currentIndex != firstIndex {
indices = append(indices, currentIndex)
endTime = endTime.Add(-24 * time.Hour)
currentIndex = indexWithDate(indexName, endTime)
for _, indexName := range indexNames {
firstIndex := indexWithDate(indexName, startTime)
currentIndex := indexWithDate(indexName, endTime)
for currentIndex != firstIndex {
indices = append(indices, currentIndex)
endTime = endTime.Add(-24 * time.Hour)
currentIndex = indexWithDate(indexName, endTime)
}
indices = append(indices, firstIndex)
}
return append(indices, firstIndex)
return indices
}

// GetServices returns all services traced by Jaeger, ordered by frequency
Expand Down
17 changes: 9 additions & 8 deletions plugin/storage/es/spanstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ func TestNewSpanReader(t *testing.T) {

func TestNewSpanReaderIndexPrefix(t *testing.T) {
testCases := []struct {
prefix string
expected string
prefix string
expectedSpanIndex []string
expectedServiceIndex []string
}{
{prefix: "", expected: ""},
{prefix: "foo", expected: "foo:"},
{prefix: ":", expected: "::"},
{prefix: "", expectedSpanIndex: []string{spanIndex}, expectedServiceIndex: []string{serviceIndex}},
{prefix: "foo", expectedSpanIndex: []string{"foo-"+spanIndex, "foo:"+spanIndex}, expectedServiceIndex: []string{"foo-"+serviceIndex, "foo:"+serviceIndex}},
{prefix: ":", expectedSpanIndex: []string{":-"+spanIndex, "::"+spanIndex}, expectedServiceIndex: []string{":-"+serviceIndex, "::"+serviceIndex}},
}
for _, testCase := range testCases {
client := &mocks.Client{}
Expand All @@ -131,8 +132,8 @@ func TestNewSpanReaderIndexPrefix(t *testing.T) {
Logger: zap.NewNop(),
MaxSpanAge: 0,
IndexPrefix: testCase.prefix})
assert.Equal(t, testCase.expected+spanIndex, r.spanIndexPrefix)
assert.Equal(t, testCase.expected+serviceIndex, r.serviceIndexPrefix)
assert.Equal(t, testCase.expectedSpanIndex, r.spanIndexPrefix)
assert.Equal(t, testCase.expectedServiceIndex, r.serviceIndexPrefix)
}
}

Expand Down Expand Up @@ -343,7 +344,7 @@ func TestSpanReaderFindIndices(t *testing.T) {
}
withSpanReader(func(r *spanReaderTest) {
for _, testCase := range testCases {
actual := r.reader.indicesForTimeRange(spanIndex, testCase.startTime, testCase.endTime)
actual := r.reader.indicesForTimeRange([]string{spanIndex}, testCase.startTime, testCase.endTime)
assert.EqualValues(t, testCase.expected, actual)
}
})
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/spanstore/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewSpanWriter(p SpanWriterParams) *SpanWriter {
// TODO: Configurable TTL
serviceOperationStorage := NewServiceOperationStorage(ctx, p.Client, p.Logger, time.Hour*12)
if p.IndexPrefix != "" {
p.IndexPrefix += ":"
p.IndexPrefix += indexPrefixSeparator
}
return &SpanWriter{
ctx: ctx,
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/es/spanstore/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func TestNewSpanWriterIndexPrefix(t *testing.T) {
expected string
}{
{prefix: "", expected: ""},
{prefix: "foo", expected: "foo:"},
{prefix: ":", expected: "::"},
{prefix: "foo", expected: "foo-"},
{prefix: ":", expected: ":-"},
}
client := &mocks.Client{}
logger, _ := testutils.NewLogger()
Expand Down

0 comments on commit 4e3551c

Please sign in to comment.