Skip to content

Commit

Permalink
cleanup2
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <github@ysh.us>
  • Loading branch information
yurishkuro committed Sep 1, 2024
1 parent 1dc436e commit 7336c3f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import (

// IndexOptions describes the index format and rollover frequency
type IndexOptions struct {
IndexPrefix string `mapstructure:"index_prefix"`
DateLayout string `mapstructure:"date_layout"`
RolloverFrequency string `mapstructure:"rollover_frequency"` // "hour" or "day"
Prefix string `mapstructure:"prefix"`
Priority int `mapstructure:"priority"`
DateLayout string `mapstructure:"date_layout"`
Shards int `mapstructure:"shards"`
Replicas int `mapstructure:"replicas"`
RolloverFrequency string `mapstructure:"rollover_frequency"` // "hour" or "day"
}

// Indices describes different configuration options for each index type
Expand Down Expand Up @@ -235,8 +235,8 @@ func setDefaultIndexOptions(cfg, source *IndexOptions) {
cfg.RolloverFrequency = source.RolloverFrequency
}

if cfg.IndexPrefix == "" {
cfg.IndexPrefix = source.IndexPrefix
if cfg.Prefix == "" {
cfg.Prefix = source.Prefix
}
}

Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/es/mappings/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func (mb *MappingBuilder) fixMapping(mapping string, options *IndexTemplateOptio
}
writer := new(bytes.Buffer)

if options.IndexPrefix != "" && !strings.HasSuffix(options.IndexPrefix, "-") {
options.IndexPrefix += "-"
if options.Prefix != "" && !strings.HasSuffix(options.Prefix, "-") {
options.Prefix += "-"
}
if err := tmpl.Execute(writer, options); err != nil {
return "", err
Expand Down
22 changes: 11 additions & 11 deletions plugin/storage/es/mappings/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func TestMappingBuilderGetMapping(t *testing.T) {
for _, tt := range tests {
t.Run(tt.mapping, func(t *testing.T) {
indexTemOps := config.IndexOptions{
Shards: 3,
Replicas: 3,
Priority: 500,
IndexPrefix: "test-",
Shards: 3,
Replicas: 3,
Priority: 500,
Prefix: "test-",
}
serviceOps := indexTemOps
serviceOps.Priority = 501
Expand Down Expand Up @@ -152,10 +152,10 @@ func TestMappingBuilderFixMapping(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
indexTemOps := config.IndexOptions{
Shards: 3,
Replicas: 5,
Priority: 500,
IndexPrefix: "test",
Shards: 3,
Replicas: 5,
Priority: 500,
Prefix: "test",
}
mappingBuilder := MappingBuilder{
TemplateBuilder: test.templateBuilderMockFunc(),
Expand Down Expand Up @@ -301,9 +301,9 @@ func TestMappingBuilderGetSpanServiceMappings(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
indexTemOps := config.IndexOptions{
Shards: 3,
Replicas: 3,
IndexPrefix: test.args.indexPrefix,
Shards: 3,
Replicas: 3,
Prefix: test.args.indexPrefix,
}

mappingBuilder := MappingBuilder{
Expand Down
26 changes: 13 additions & 13 deletions plugin/storage/es/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,15 @@ func NewSpanReader(p SpanReaderParams) *SpanReader {
maxSpanAge = rolloverMaxSpanAge
}

p.SpanIndex.IndexPrefix = indexNames(p.SpanIndex.IndexPrefix, spanIndexBaseName)
p.ServiceIndex.IndexPrefix = indexNames(p.ServiceIndex.IndexPrefix, serviceIndexBaseName)
makeName := func(prefix, index string) string {
if prefix != "" {
return prefix + indexPrefixSeparator + index
}
return index
}

p.SpanIndex.Prefix = makeName(p.SpanIndex.Prefix, spanIndexBaseName)
p.ServiceIndex.Prefix = makeName(p.ServiceIndex.Prefix, serviceIndexBaseName)

return &SpanReader{
client: p.Client,
Expand Down Expand Up @@ -215,13 +222,6 @@ func timeRangeIndices(indexName, indexDateLayout string, startTime time.Time, en
return indices
}

func indexNames(prefix, index string) string {
if prefix != "" {
return prefix + indexPrefixSeparator + index
}
return 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) {
ctx, span := s.tracer.Start(ctx, "GetTrace")
Expand Down Expand Up @@ -273,7 +273,7 @@ func (s *SpanReader) GetServices(ctx context.Context) ([]string, error) {
defer span.End()
currentTime := time.Now()
jaegerIndices := s.timeRangeIndices(
s.serviceIndex.IndexPrefix,
s.serviceIndex.Prefix,
s.serviceIndex.DateLayout,
currentTime.Add(-s.maxSpanAge),
currentTime,
Expand All @@ -291,7 +291,7 @@ func (s *SpanReader) GetOperations(
defer span.End()
currentTime := time.Now()
jaegerIndices := s.timeRangeIndices(
s.serviceIndex.IndexPrefix,
s.serviceIndex.Prefix,
s.serviceIndex.DateLayout,
currentTime.Add(-s.maxSpanAge),
currentTime,
Expand Down Expand Up @@ -376,7 +376,7 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []model.TraceID, st
// Add an hour in both directions so that traces that straddle two indexes are retrieved.
// i.e starts in one and ends in another.
indices := s.timeRangeIndices(
s.spanIndex.IndexPrefix,
s.spanIndex.Prefix,
s.spanIndex.DateLayout,
startTime.Add(-time.Hour),
endTime.Add(time.Hour),
Expand Down Expand Up @@ -574,7 +574,7 @@ func (s *SpanReader) findTraceIDs(ctx context.Context, traceQuery *spanstore.Tra
aggregation := s.buildTraceIDAggregation(traceQuery.NumTraces)
boolQuery := s.buildFindTraceIDsQuery(traceQuery)
jaegerIndices := s.timeRangeIndices(
s.spanIndex.IndexPrefix,
s.spanIndex.Prefix,
s.spanIndex.DateLayout,
traceQuery.StartTimeMin,
traceQuery.StartTimeMax,
Expand Down
8 changes: 4 additions & 4 deletions plugin/storage/es/spanstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ func TestSpanReaderIndices(t *testing.T) {
serviceIndexOpts := config.IndexOptions{DateLayout: serviceDataLayout}

serviceIndexOptsWithFoo := serviceIndexOpts
serviceIndexOptsWithFoo.IndexPrefix = "foo:"
serviceIndexOptsWithFoo.Prefix = "foo:"

spanIndexOptsWithFoo := spanIndexOpts
spanIndexOptsWithFoo.IndexPrefix = "foo:"
spanIndexOptsWithFoo.Prefix = "foo:"

testCases := []struct {
indices []string
Expand Down Expand Up @@ -304,8 +304,8 @@ func TestSpanReaderIndices(t *testing.T) {
testCase.params.Tracer = tracer.Tracer("test")
r := NewSpanReader(testCase.params)

actualSpan := r.timeRangeIndices(r.spanIndex.IndexPrefix, r.spanIndex.DateLayout, date, date, -1*time.Hour)
actualService := r.timeRangeIndices(r.serviceIndex.IndexPrefix, r.serviceIndex.DateLayout, date, date, -24*time.Hour)
actualSpan := r.timeRangeIndices(r.spanIndex.Prefix, r.spanIndex.DateLayout, date, date, -1*time.Hour)
actualService := r.timeRangeIndices(r.serviceIndex.Prefix, r.serviceIndex.DateLayout, date, date, -24*time.Hour)
assert.Equal(t, testCase.indices, append(actualSpan, actualService...))
}
}
Expand Down

0 comments on commit 7336c3f

Please sign in to comment.