From 7336c3f0ab46398091f580c0d89e5a853f1f5687 Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Sun, 1 Sep 2024 15:36:57 -0400 Subject: [PATCH] cleanup2 Signed-off-by: Yuri Shkuro --- pkg/es/config/config.go | 10 ++++----- plugin/storage/es/mappings/mapping.go | 4 ++-- plugin/storage/es/mappings/mapping_test.go | 22 +++++++++--------- plugin/storage/es/spanstore/reader.go | 26 +++++++++++----------- plugin/storage/es/spanstore/reader_test.go | 8 +++---- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pkg/es/config/config.go b/pkg/es/config/config.go index c13e7c616f2..5a2b9a2d18a 100644 --- a/pkg/es/config/config.go +++ b/pkg/es/config/config.go @@ -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 @@ -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 } } diff --git a/plugin/storage/es/mappings/mapping.go b/plugin/storage/es/mappings/mapping.go index 29b6f886d20..93c8682224f 100644 --- a/plugin/storage/es/mappings/mapping.go +++ b/plugin/storage/es/mappings/mapping.go @@ -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 diff --git a/plugin/storage/es/mappings/mapping_test.go b/plugin/storage/es/mappings/mapping_test.go index a1f448d95d3..6ad66dc2c95 100644 --- a/plugin/storage/es/mappings/mapping_test.go +++ b/plugin/storage/es/mappings/mapping_test.go @@ -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 @@ -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(), @@ -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{ diff --git a/plugin/storage/es/spanstore/reader.go b/plugin/storage/es/spanstore/reader.go index 5c864d8f4d7..37f6563190e 100644 --- a/plugin/storage/es/spanstore/reader.go +++ b/plugin/storage/es/spanstore/reader.go @@ -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, @@ -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") @@ -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, @@ -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, @@ -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), @@ -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, diff --git a/plugin/storage/es/spanstore/reader_test.go b/plugin/storage/es/spanstore/reader_test.go index 4b62cfb2285..17f90144fcc 100644 --- a/plugin/storage/es/spanstore/reader_test.go +++ b/plugin/storage/es/spanstore/reader_test.go @@ -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 @@ -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...)) } }