-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new ES reader implementation in OTEL (#2441)
* Use new ES reader implementation in OTEL Signed-off-by: Pavol Loffay <[email protected]> * fmt Signed-off-by: Pavol Loffay <[email protected]> * Fix ITest Signed-off-by: Pavol Loffay <[email protected]> * fixes after rebase Signed-off-by: Pavol Loffay <[email protected]>
- Loading branch information
1 parent
21de269
commit 043d00c
Showing
11 changed files
with
469 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
cmd/opentelemetry/app/exporter/elasticsearchexporter/index_name.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2020 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package elasticsearchexporter | ||
|
||
import "time" | ||
|
||
func newIndexNameProvider(index, prefix string, useAliases bool, useArchive bool) indexNameProvider { | ||
if prefix != "" { | ||
prefix = prefix + "-" | ||
index = prefix + index | ||
} | ||
index = index + "-" | ||
if useArchive { | ||
index = index + "archive" | ||
} | ||
if useAliases { | ||
if index[len(index)-1] != '-' { | ||
index += "-" | ||
} | ||
index = index + "write" | ||
} | ||
return indexNameProvider{ | ||
index: index, | ||
useSingleIndex: useAliases || useArchive, | ||
} | ||
} | ||
|
||
type indexNameProvider struct { | ||
index string | ||
useSingleIndex bool | ||
} | ||
|
||
func (n indexNameProvider) get(date time.Time) string { | ||
if n.useSingleIndex { | ||
return n.index | ||
} | ||
spanDate := date.UTC().Format(indexDateFormat) | ||
return n.index + spanDate | ||
} |
68 changes: 68 additions & 0 deletions
68
cmd/opentelemetry/app/exporter/elasticsearchexporter/index_name_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2020 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package elasticsearchexporter | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIndexName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
index string | ||
nameProvider indexNameProvider | ||
date time.Time | ||
end time.Time | ||
}{ | ||
{ | ||
name: "index prefix", | ||
nameProvider: newIndexNameProvider("myindex", "production", false, false), | ||
index: "production-myindex-0001-01-01", | ||
}, | ||
{ | ||
name: "no prefix", | ||
nameProvider: newIndexNameProvider("myindex", "", false, false), | ||
index: "myindex-2020-08-28", | ||
date: time.Date(2020, 8, 28, 0, 0, 0, 0, time.UTC), | ||
}, | ||
{ | ||
name: "use aliases", | ||
nameProvider: newIndexNameProvider("myindex", "", true, false), | ||
index: "myindex-write", | ||
date: time.Date(2020, 8, 28, 0, 0, 0, 0, time.UTC), | ||
}, | ||
{ | ||
name: "use archive", | ||
nameProvider: newIndexNameProvider("myindex", "", false, true), | ||
index: "myindex-archive", | ||
date: time.Date(2020, 8, 28, 0, 0, 0, 0, time.UTC), | ||
}, | ||
{ | ||
name: "use archive alias", | ||
nameProvider: newIndexNameProvider("myindex", "", true, true), | ||
index: "myindex-archive-write", | ||
date: time.Date(2020, 8, 28, 0, 0, 0, 0, time.UTC), | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
indices := test.nameProvider.get(test.date) | ||
assert.Equal(t, test.index, indices) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
cmd/opentelemetry/app/exporter/elasticsearchexporter/storagefactory.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
// Copyright (c) 2020 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package elasticsearchexporter | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/uber/jaeger-lib/metrics" | ||
"go.uber.org/zap" | ||
|
||
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/internal/esclient" | ||
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/internal/reader/es/esdependencyreader" | ||
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/internal/reader/es/esspanreader" | ||
"github.com/jaegertracing/jaeger/model" | ||
"github.com/jaegertracing/jaeger/plugin/storage/es" | ||
"github.com/jaegertracing/jaeger/plugin/storage/es/spanstore/dbmodel" | ||
"github.com/jaegertracing/jaeger/storage" | ||
"github.com/jaegertracing/jaeger/storage/dependencystore" | ||
"github.com/jaegertracing/jaeger/storage/spanstore" | ||
) | ||
|
||
const archiveNamespace = "es-archive" | ||
|
||
// StorageFactory implements storage.Factory and storage.ArchiveFactory | ||
type StorageFactory struct { | ||
Options *es.Options | ||
logger *zap.Logger | ||
} | ||
|
||
var _ storage.Factory = (*StorageFactory)(nil) | ||
var _ storage.ArchiveFactory = (*StorageFactory)(nil) | ||
|
||
// NewStorageFactory creates StorageFactory | ||
func NewStorageFactory(opts *es.Options, logger *zap.Logger) *StorageFactory { | ||
return &StorageFactory{ | ||
Options: opts, | ||
logger: logger, | ||
} | ||
} | ||
|
||
// Initialize initializes StorageFactory | ||
func (s *StorageFactory) Initialize(_ metrics.Factory, logger *zap.Logger) error { | ||
s.logger = logger | ||
return nil | ||
} | ||
|
||
// CreateSpanWriter creates spanstore.Writer | ||
func (s *StorageFactory) CreateSpanWriter() (spanstore.Writer, error) { | ||
cfg := s.Options.GetPrimary() | ||
writer, err := newEsSpanWriter(*cfg, s.logger, false) | ||
if err != nil { | ||
return nil, err | ||
} | ||
fields, err := cfg.TagKeysAsFields() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &singleSpanWriter{ | ||
converter: dbmodel.NewFromDomain(cfg.GetAllTagsAsFields(), fields, cfg.GetTagDotReplacement()), | ||
writer: writer, | ||
}, nil | ||
} | ||
|
||
// CreateSpanReader creates spanstore.Reader | ||
func (s *StorageFactory) CreateSpanReader() (spanstore.Reader, error) { | ||
cfg := s.Options.GetPrimary() | ||
client, err := esclient.NewElasticsearchClient(*cfg, s.logger) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return esspanreader.NewEsSpanReader(client, s.logger, esspanreader.Config{ | ||
Archive: false, | ||
UseReadWriteAliases: cfg.GetUseReadWriteAliases(), | ||
IndexPrefix: cfg.GetIndexPrefix(), | ||
MaxSpanAge: cfg.GetMaxSpanAge(), | ||
MaxNumSpans: cfg.GetMaxNumSpans(), | ||
TagDotReplacement: cfg.GetTagDotReplacement(), | ||
}), nil | ||
} | ||
|
||
// CreateDependencyReader creates dependencystore.Reader | ||
func (s *StorageFactory) CreateDependencyReader() (dependencystore.Reader, error) { | ||
cfg := s.Options.GetPrimary() | ||
client, err := esclient.NewElasticsearchClient(*cfg, s.logger) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return esdependencyreader.NewDependencyStore(client, s.logger, cfg.GetIndexPrefix()), nil | ||
} | ||
|
||
// CreateArchiveSpanReader creates archive spanstore.Reader | ||
func (s *StorageFactory) CreateArchiveSpanReader() (spanstore.Reader, error) { | ||
cfg := s.Options.Get(archiveNamespace) | ||
client, err := esclient.NewElasticsearchClient(*cfg, s.logger) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return esspanreader.NewEsSpanReader(client, s.logger, esspanreader.Config{ | ||
Archive: true, | ||
UseReadWriteAliases: cfg.GetUseReadWriteAliases(), | ||
IndexPrefix: cfg.GetIndexPrefix(), | ||
MaxSpanAge: cfg.GetMaxSpanAge(), | ||
MaxNumSpans: cfg.GetMaxNumSpans(), | ||
TagDotReplacement: cfg.GetTagDotReplacement(), | ||
}), nil | ||
} | ||
|
||
// CreateArchiveSpanWriter creates archive spanstore.Writer | ||
func (s *StorageFactory) CreateArchiveSpanWriter() (spanstore.Writer, error) { | ||
cfg := s.Options.Get(archiveNamespace) | ||
writer, err := newEsSpanWriter(*cfg, s.logger, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
fields, err := cfg.TagKeysAsFields() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &singleSpanWriter{ | ||
converter: dbmodel.NewFromDomain(cfg.GetAllTagsAsFields(), fields, cfg.GetTagDotReplacement()), | ||
writer: writer, | ||
}, nil | ||
} | ||
|
||
type singleSpanWriter struct { | ||
writer batchSpanWriter | ||
converter dbmodel.FromDomain | ||
} | ||
|
||
type batchSpanWriter interface { | ||
writeSpans(context.Context, []*dbmodel.Span) (int, error) | ||
} | ||
|
||
var _ spanstore.Writer = (*singleSpanWriter)(nil) | ||
|
||
func (s singleSpanWriter) WriteSpan(ctx context.Context, span *model.Span) error { | ||
dbSpan := s.converter.FromDomainEmbedProcess(span) | ||
_, err := s.writer.writeSpans(ctx, []*dbmodel.Span{dbSpan}) | ||
return err | ||
} |
Oops, something went wrong.