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

Change index prefix from : to - #1284

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
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 @@ -175,7 +175,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 @@ -93,8 +95,8 @@ type SpanReader struct {
// this will be rounded down to UTC 00:00 of that day.
maxSpanAge time.Duration
serviceOperationStorage *ServiceOperationStorage
spanIndexPrefix string
serviceIndexPrefix string
spanIndexPrefix []string
serviceIndexPrefix []string
spanConverter dbmodel.ToDomain
}

Expand All @@ -116,21 +118,25 @@ 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,
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 @@ -174,16 +180,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