Skip to content

Commit c9a8c6b

Browse files
mahadzaryab1chahatsagarmain
authored andcommitted
[jaeger-v2] Migrate ElasticSearch/OpenSearch to use OTEL's TLS configuration (jaegertracing#6079)
## Which problem is this PR solving? - Towards jaegertracing#6059 ## Description of the changes - Migrated the ElasticSearch/OpenSearch configurations to use OTEL's TLS configurations - In a follow up PR, I'll re-evaluate the groupings of the configurations and add the missing mapstructure tags ## How was this change tested? - CI ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` Signed-off-by: Mahad Zaryab <[email protected]>
1 parent 10efd28 commit c9a8c6b

File tree

5 files changed

+47
-49
lines changed

5 files changed

+47
-49
lines changed

pkg/es/config/config.go

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import (
2121
"github.com/asaskevich/govalidator"
2222
esV8 "github.com/elastic/go-elasticsearch/v8"
2323
"github.com/olivere/elastic"
24+
"go.opentelemetry.io/collector/config/configtls"
2425
"go.uber.org/zap"
2526
"go.uber.org/zap/zapcore"
2627
"go.uber.org/zap/zapgrpc"
2728

2829
"github.com/jaegertracing/jaeger/pkg/bearertoken"
29-
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
3030
"github.com/jaegertracing/jaeger/pkg/es"
3131
eswrapper "github.com/jaegertracing/jaeger/pkg/es/wrapper"
3232
"github.com/jaegertracing/jaeger/pkg/metrics"
@@ -70,35 +70,34 @@ func (p IndexPrefix) Apply(indexName string) string {
7070

7171
// Configuration describes the configuration properties needed to connect to an ElasticSearch cluster
7272
type Configuration struct {
73-
Servers []string `mapstructure:"server_urls" valid:"required,url"`
74-
RemoteReadClusters []string `mapstructure:"remote_read_clusters"`
75-
Username string `mapstructure:"username"`
76-
Password string `mapstructure:"password" json:"-"`
77-
TokenFilePath string `mapstructure:"token_file"`
78-
PasswordFilePath string `mapstructure:"password_file"`
79-
AllowTokenFromContext bool `mapstructure:"-"`
80-
Sniffer bool `mapstructure:"sniffer"` // https://github.com/olivere/elastic/wiki/Sniffing
81-
SnifferTLSEnabled bool `mapstructure:"sniffer_tls_enabled"`
82-
MaxDocCount int `mapstructure:"-"` // Defines maximum number of results to fetch from storage per query
83-
MaxSpanAge time.Duration `mapstructure:"-"` // configures the maximum lookback on span reads
84-
Timeout time.Duration `mapstructure:"-"`
85-
BulkSize int `mapstructure:"-"`
86-
BulkWorkers int `mapstructure:"-"`
87-
BulkActions int `mapstructure:"-"`
88-
BulkFlushInterval time.Duration `mapstructure:"-"`
89-
Indices Indices `mapstructure:"indices"`
90-
ServiceCacheTTL time.Duration `mapstructure:"service_cache_ttl"`
91-
AdaptiveSamplingLookback time.Duration `mapstructure:"-"`
92-
Tags TagsAsFields `mapstructure:"tags_as_fields"`
93-
Enabled bool `mapstructure:"-"`
94-
// TODO: migration to OTEL's TLS configuration
95-
TLS tlscfg.Options `mapstructure:"tls"`
96-
UseReadWriteAliases bool `mapstructure:"use_aliases"`
97-
CreateIndexTemplates bool `mapstructure:"create_mappings"`
98-
UseILM bool `mapstructure:"use_ilm"`
99-
Version uint `mapstructure:"version"`
100-
LogLevel string `mapstructure:"log_level"`
101-
SendGetBodyAs string `mapstructure:"send_get_body_as"`
73+
Servers []string `mapstructure:"server_urls" valid:"required,url"`
74+
RemoteReadClusters []string `mapstructure:"remote_read_clusters"`
75+
Username string `mapstructure:"username"`
76+
Password string `mapstructure:"password" json:"-"`
77+
TokenFilePath string `mapstructure:"token_file"`
78+
PasswordFilePath string `mapstructure:"password_file"`
79+
AllowTokenFromContext bool `mapstructure:"-"`
80+
Sniffer bool `mapstructure:"sniffer"` // https://github.com/olivere/elastic/wiki/Sniffing
81+
SnifferTLSEnabled bool `mapstructure:"sniffer_tls_enabled"`
82+
MaxDocCount int `mapstructure:"-"` // Defines maximum number of results to fetch from storage per query
83+
MaxSpanAge time.Duration `mapstructure:"-"` // configures the maximum lookback on span reads
84+
Timeout time.Duration `mapstructure:"-"`
85+
BulkSize int `mapstructure:"-"`
86+
BulkWorkers int `mapstructure:"-"`
87+
BulkActions int `mapstructure:"-"`
88+
BulkFlushInterval time.Duration `mapstructure:"-"`
89+
Indices Indices `mapstructure:"indices"`
90+
ServiceCacheTTL time.Duration `mapstructure:"service_cache_ttl"`
91+
AdaptiveSamplingLookback time.Duration `mapstructure:"-"`
92+
Tags TagsAsFields `mapstructure:"tags_as_fields"`
93+
Enabled bool `mapstructure:"-"`
94+
TLS configtls.ClientConfig `mapstructure:"tls"`
95+
UseReadWriteAliases bool `mapstructure:"use_aliases"`
96+
CreateIndexTemplates bool `mapstructure:"create_mappings"`
97+
UseILM bool `mapstructure:"use_ilm"`
98+
Version uint `mapstructure:"version"`
99+
LogLevel string `mapstructure:"log_level"`
100+
SendGetBodyAs string `mapstructure:"send_get_body_as"`
102101
}
103102

104103
// TagsAsFields holds configuration for tag schema.
@@ -440,8 +439,8 @@ func addLoggerOptions(options []elastic.ClientOptionFunc, logLevel string, logge
440439

441440
// GetHTTPRoundTripper returns configured http.RoundTripper
442441
func GetHTTPRoundTripper(c *Configuration, logger *zap.Logger) (http.RoundTripper, error) {
443-
if c.TLS.Enabled {
444-
ctlsConfig, err := c.TLS.Config(logger)
442+
if !c.TLS.Insecure {
443+
ctlsConfig, err := c.TLS.LoadTLSConfig(context.Background())
445444
if err != nil {
446445
return nil, err
447446
}
@@ -454,10 +453,10 @@ func GetHTTPRoundTripper(c *Configuration, logger *zap.Logger) (http.RoundTrippe
454453
httpTransport := &http.Transport{
455454
Proxy: http.ProxyFromEnvironment,
456455
// #nosec G402
457-
TLSClientConfig: &tls.Config{InsecureSkipVerify: c.TLS.SkipHostVerify},
456+
TLSClientConfig: &tls.Config{InsecureSkipVerify: c.TLS.InsecureSkipVerify},
458457
}
459-
if c.TLS.CAPath != "" {
460-
ctlsConfig, err := c.TLS.Config(logger)
458+
if c.TLS.CAFile != "" {
459+
ctlsConfig, err := c.TLS.LoadTLSConfig(context.Background())
461460
if err != nil {
462461
return nil, err
463462
}

pkg/es/config/config_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313

1414
"github.com/stretchr/testify/assert"
1515
"github.com/stretchr/testify/require"
16+
"go.opentelemetry.io/collector/config/configtls"
1617
"go.uber.org/zap"
1718

18-
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
1919
"github.com/jaegertracing/jaeger/pkg/metrics"
2020
"github.com/jaegertracing/jaeger/pkg/testutils"
2121
)
@@ -139,7 +139,7 @@ func TestNewClient(t *testing.T) {
139139
PasswordFilePath: "",
140140
BulkSize: -1, // disable bulk; we want immediate flush
141141
Version: 0,
142-
TLS: tlscfg.Options{Enabled: true},
142+
TLS: configtls.ClientConfig{Insecure: false},
143143
},
144144
expectedError: false,
145145
},
@@ -154,8 +154,13 @@ func TestNewClient(t *testing.T) {
154154
PasswordFilePath: "",
155155
BulkSize: -1, // disable bulk; we want immediate flush
156156
Version: 0,
157-
TLS: tlscfg.Options{Enabled: false, CAPath: certFilePath.Name()},
158-
TokenFilePath: pwdtokenFile,
157+
TLS: configtls.ClientConfig{
158+
Insecure: true,
159+
Config: configtls.Config{
160+
CAFile: certFilePath.Name(),
161+
},
162+
},
163+
TokenFilePath: pwdtokenFile,
159164
},
160165
expectedError: false,
161166
},
@@ -308,8 +313,6 @@ func TestNewClient(t *testing.T) {
308313
err = client.Close()
309314
require.NoError(t, err)
310315
}
311-
err = config.TLS.Close()
312-
require.NoError(t, err)
313316
})
314317
}
315318
}

plugin/storage/es/factory.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,6 @@ func (f *Factory) Close() error {
343343
for _, w := range f.watchers {
344344
errs = append(errs, w.Close())
345345
}
346-
if cfg := f.Options.Get(archiveNamespace); cfg != nil {
347-
errs = append(errs, cfg.TLS.Close())
348-
}
349-
errs = append(errs, f.Options.GetPrimary().TLS.Close())
350346
errs = append(errs, f.getPrimaryClient().Close())
351347
if client := f.getArchiveClient(); client != nil {
352348
errs = append(errs, client.Close())

plugin/storage/es/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,12 @@ func initFromViper(cfg *namespaceConfig, v *viper.Viper) {
379379

380380
// Daily is recommended for dependencies calculation, and this index size is very small
381381
cfg.Indices.Dependencies.DateLayout = initDateLayout(cfg.Indices.Dependencies.DateLayout, separator)
382-
var err error
383-
cfg.TLS, err = cfg.getTLSFlagsConfig().InitFromViper(v)
382+
tlsconfig, err := cfg.getTLSFlagsConfig().InitFromViper(v)
384383
if err != nil {
385384
// TODO refactor to be able to return error
386385
log.Fatal(err)
387386
}
387+
cfg.TLS = tlsconfig.ToOtelClientConfig()
388388
}
389389

390390
// GetPrimary returns primary configuration.

plugin/storage/es/options_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func TestOptionsWithFlags(t *testing.T) {
8888
assert.Equal(t, 48*time.Hour, primary.MaxSpanAge)
8989
assert.True(t, primary.Sniffer)
9090
assert.True(t, primary.SnifferTLSEnabled)
91-
assert.True(t, primary.TLS.Enabled)
92-
assert.True(t, primary.TLS.SkipHostVerify)
91+
assert.False(t, primary.TLS.Insecure)
92+
assert.True(t, primary.TLS.InsecureSkipVerify)
9393
assert.True(t, primary.Tags.AllAsFields)
9494
assert.Equal(t, "!", primary.Tags.DotReplacement)
9595
assert.Equal(t, "./file.txt", primary.Tags.File)

0 commit comments

Comments
 (0)