Skip to content

Commit fa31b89

Browse files
authored
[jaeger-v2] Consolidate v1 and v2 Configurations for GRPC Storage (#6042)
## Which problem is this PR solving? - Resolves #6041 ## Description of the changes - We were currently maintaining two entirely separate configurations for v1 and v2 for the GRPC Storage Component and were initializing v1 configurations and then translating them to the v2 configurations which were the ones actually being used. This caused an issue where one configuration field was left out of the translation method (see #6030 for more details). - In this PR, we consolidate the v1 and v2 configurations into a single config type that is directly initialized to avoid having configurations that diverge or running into issues like the one described above. ## How was this change tested? - Unit tests were updated - Integration tests were not touched but should still pass since this was just an internal change and the interface was not touched ## 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 edc45e0 commit fa31b89

File tree

8 files changed

+51
-85
lines changed

8 files changed

+51
-85
lines changed

cmd/jaeger/internal/extension/jaegerstorage/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Config struct {
4141
type Backend struct {
4242
Memory *memory.Configuration `mapstructure:"memory"`
4343
Badger *badger.Config `mapstructure:"badger"`
44-
GRPC *grpc.ConfigV2 `mapstructure:"grpc"`
44+
GRPC *grpc.Config `mapstructure:"grpc"`
4545
Cassandra *cassandra.Options `mapstructure:"cassandra"`
4646
Elasticsearch *esCfg.Configuration `mapstructure:"elasticsearch"`
4747
Opensearch *esCfg.Configuration `mapstructure:"opensearch"`
@@ -66,7 +66,7 @@ func (cfg *Backend) Unmarshal(conf *confmap.Conf) error {
6666
cfg.Badger = v
6767
}
6868
if conf.IsSet("grpc") {
69-
v := grpc.DefaultConfigV2()
69+
v := grpc.DefaultConfig()
7070
cfg.GRPC = &v
7171
}
7272
if conf.IsSet("cassandra") {

cmd/jaeger/internal/extension/jaegerstorage/extension_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestGRPC(t *testing.T) {
143143
ext := makeStorageExtenion(t, &Config{
144144
Backends: map[string]Backend{
145145
"foo": {
146-
GRPC: &grpc.ConfigV2{
146+
GRPC: &grpc.Config{
147147
ClientConfig: configgrpc.ClientConfig{
148148
Endpoint: "localhost:12345",
149149
},

plugin/storage/grpc/config.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,28 @@
44
package grpc
55

66
import (
7-
"time"
8-
97
"go.opentelemetry.io/collector/config/configgrpc"
108
"go.opentelemetry.io/collector/exporter/exporterhelper"
119

12-
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
1310
"github.com/jaegertracing/jaeger/pkg/tenancy"
1411
"github.com/jaegertracing/jaeger/plugin/storage/grpc/shared"
1512
)
1613

17-
// Configuration describes the options to customize the storage behavior.
18-
type Configuration struct {
19-
RemoteServerAddr string `yaml:"server" mapstructure:"server"`
20-
RemoteTLS tlscfg.Options
21-
RemoteConnectTimeout time.Duration `yaml:"connection-timeout" mapstructure:"connection-timeout"`
22-
TenancyOpts tenancy.Options
23-
}
24-
25-
type ConfigV2 struct {
14+
// Config describes the options to customize the storage behavior
15+
type Config struct {
2616
Tenancy tenancy.Options `mapstructure:"multi_tenancy"`
2717
configgrpc.ClientConfig `mapstructure:",squash"`
2818
exporterhelper.TimeoutSettings `mapstructure:",squash"`
2919
}
3020

31-
func DefaultConfigV2() ConfigV2 {
32-
return ConfigV2{
21+
func DefaultConfig() Config {
22+
return Config{
3323
TimeoutSettings: exporterhelper.TimeoutConfig{
3424
Timeout: defaultConnectionTimeout,
3525
},
3626
}
3727
}
3828

39-
func (c *Configuration) TranslateToConfigV2() *ConfigV2 {
40-
return &ConfigV2{
41-
Tenancy: c.TenancyOpts,
42-
ClientConfig: configgrpc.ClientConfig{
43-
Endpoint: c.RemoteServerAddr,
44-
TLSSetting: c.RemoteTLS.ToOtelClientConfig(),
45-
},
46-
TimeoutSettings: exporterhelper.TimeoutConfig{
47-
Timeout: c.RemoteConnectTimeout,
48-
},
49-
}
50-
}
51-
5229
// ClientPluginServices defines services plugin can expose and its capabilities
5330
type ClientPluginServices struct {
5431
shared.PluginServices

plugin/storage/grpc/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/stretchr/testify/assert"
1010
)
1111

12-
func TestDefaultConfigV2(t *testing.T) {
13-
cfg := DefaultConfigV2()
12+
func TestDefaultConfig(t *testing.T) {
13+
cfg := DefaultConfig()
1414
assert.NotEmpty(t, cfg.Timeout)
1515
}

plugin/storage/grpc/factory.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,9 @@ type Factory struct {
4444
metricsFactory metrics.Factory
4545
logger *zap.Logger
4646
tracerProvider trace.TracerProvider
47-
48-
// configV1 is used for backward compatibility. it will be removed in v2.
49-
// In the main initialization logic, only configV2 is used.
50-
configV1 Configuration
51-
configV2 *ConfigV2
52-
53-
services *ClientPluginServices
54-
remoteConn *grpc.ClientConn
47+
config Config
48+
services *ClientPluginServices
49+
remoteConn *grpc.ClientConn
5550
}
5651

5752
// NewFactory creates a new Factory.
@@ -61,12 +56,12 @@ func NewFactory() *Factory {
6156

6257
// NewFactoryWithConfig is used from jaeger(v2).
6358
func NewFactoryWithConfig(
64-
cfg ConfigV2,
59+
cfg Config,
6560
metricsFactory metrics.Factory,
6661
logger *zap.Logger,
6762
) (*Factory, error) {
6863
f := NewFactory()
69-
f.configV2 = &cfg
64+
f.config = cfg
7065
if err := f.Initialize(metricsFactory, logger); err != nil {
7166
return nil, err
7267
}
@@ -75,12 +70,12 @@ func NewFactoryWithConfig(
7570

7671
// AddFlags implements plugin.Configurable
7772
func (*Factory) AddFlags(flagSet *flag.FlagSet) {
78-
v1AddFlags(flagSet)
73+
addFlags(flagSet)
7974
}
8075

8176
// InitFromViper implements plugin.Configurable
8277
func (f *Factory) InitFromViper(v *viper.Viper, logger *zap.Logger) {
83-
if err := v1InitFromViper(&f.configV1, v); err != nil {
78+
if err := initFromViper(&f.config, v); err != nil {
8479
logger.Fatal("unable to initialize gRPC storage factory", zap.Error(err))
8580
}
8681
}
@@ -90,10 +85,6 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
9085
f.metricsFactory, f.logger = metricsFactory, logger
9186
f.tracerProvider = otel.GetTracerProvider()
9287

93-
if f.configV2 == nil {
94-
f.configV2 = f.configV1.TranslateToConfigV2()
95-
}
96-
9788
telset := component.TelemetrySettings{
9889
Logger: logger,
9990
TracerProvider: f.tracerProvider,
@@ -107,22 +98,22 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
10798
for _, opt := range opts {
10899
clientOpts = append(clientOpts, configgrpc.WithGrpcDialOption(opt))
109100
}
110-
return f.configV2.ToClientConnWithOptions(context.Background(), componenttest.NewNopHost(), telset, clientOpts...)
101+
return f.config.ToClientConnWithOptions(context.Background(), componenttest.NewNopHost(), telset, clientOpts...)
111102
}
112103

113104
var err error
114105
f.services, err = f.newRemoteStorage(telset, newClientFn)
115106
if err != nil {
116107
return fmt.Errorf("grpc storage builder failed to create a store: %w", err)
117108
}
118-
logger.Info("Remote storage configuration", zap.Any("configuration", f.configV2))
109+
logger.Info("Remote storage configuration", zap.Any("configuration", f.config))
119110
return nil
120111
}
121112

122113
type newClientFn func(opts ...grpc.DialOption) (*grpc.ClientConn, error)
123114

124115
func (f *Factory) newRemoteStorage(telset component.TelemetrySettings, newClient newClientFn) (*ClientPluginServices, error) {
125-
c := f.configV2
116+
c := f.config
126117
opts := []grpc.DialOption{
127118
grpc.WithStatsHandler(otelgrpc.NewClientHandler(otelgrpc.WithTracerProvider(telset.TracerProvider))),
128119
}
@@ -208,6 +199,5 @@ func (f *Factory) Close() error {
208199
if f.remoteConn != nil {
209200
errs = append(errs, f.remoteConn.Close())
210201
}
211-
errs = append(errs, f.configV1.RemoteTLS.Close())
212202
return errors.Join(errs...)
213203
}

plugin/storage/grpc/factory_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func makeFactory(t *testing.T) *Factory {
9898
}
9999

100100
func TestNewFactoryError(t *testing.T) {
101-
cfg := &ConfigV2{
101+
cfg := &Config{
102102
ClientConfig: configgrpc.ClientConfig{
103103
// non-empty Auth is currently not supported
104104
Auth: &configauth.Authentication{},
@@ -113,15 +113,15 @@ func TestNewFactoryError(t *testing.T) {
113113
t.Run("viper", func(t *testing.T) {
114114
f := NewFactory()
115115
f.InitFromViper(viper.New(), zap.NewNop())
116-
f.configV2 = cfg
116+
f.config = *cfg
117117
err := f.Initialize(metrics.NullFactory, zap.NewNop())
118118
require.Error(t, err)
119119
assert.Contains(t, err.Error(), "authenticator")
120120
})
121121

122122
t.Run("client", func(t *testing.T) {
123123
// this is a silly test to verify handling of error from grpc.NewClient, which cannot be induced via params.
124-
f, err := NewFactoryWithConfig(ConfigV2{}, metrics.NullFactory, zap.NewNop())
124+
f, err := NewFactoryWithConfig(Config{}, metrics.NullFactory, zap.NewNop())
125125
require.NoError(t, err)
126126
t.Cleanup(func() { require.NoError(t, f.Close()) })
127127
newClientFn := func(_ ...grpc.DialOption) (conn *grpc.ClientConn, err error) {
@@ -162,7 +162,7 @@ func TestGRPCStorageFactoryWithConfig(t *testing.T) {
162162
}()
163163
defer s.Stop()
164164

165-
cfg := ConfigV2{
165+
cfg := Config{
166166
ClientConfig: configgrpc.ClientConfig{
167167
Endpoint: lis.Addr().String(),
168168
},
@@ -265,7 +265,7 @@ func TestWithCLIFlags(t *testing.T) {
265265
})
266266
require.NoError(t, err)
267267
f.InitFromViper(v, zap.NewNop())
268-
assert.Equal(t, "foo:1234", f.configV1.RemoteServerAddr)
268+
assert.Equal(t, "foo:1234", f.config.ClientConfig.Endpoint)
269269
require.NoError(t, f.Close())
270270
}
271271

plugin/storage/grpc/options.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ func tlsFlagsConfig() tlscfg.ClientFlagsConfig {
2727
}
2828
}
2929

30-
// AddFlags adds flags for Options
31-
func v1AddFlags(flagSet *flag.FlagSet) {
30+
// addFlags adds flags for Options
31+
func addFlags(flagSet *flag.FlagSet) {
3232
tlsFlagsConfig().AddFlags(flagSet)
3333

3434
flagSet.String(remoteServer, "", "The remote storage gRPC server address as host:port")
3535
flagSet.Duration(remoteConnectionTimeout, defaultConnectionTimeout, "The remote storage gRPC server connection timeout")
3636
}
3737

38-
func v1InitFromViper(cfg *Configuration, v *viper.Viper) error {
39-
cfg.RemoteServerAddr = v.GetString(remoteServer)
40-
var err error
41-
cfg.RemoteTLS, err = tlsFlagsConfig().InitFromViper(v)
38+
func initFromViper(cfg *Config, v *viper.Viper) error {
39+
cfg.ClientConfig.Endpoint = v.GetString(remoteServer)
40+
remoteTLS, err := tlsFlagsConfig().InitFromViper(v)
4241
if err != nil {
4342
return fmt.Errorf("failed to parse gRPC storage TLS options: %w", err)
4443
}
45-
cfg.RemoteConnectTimeout = v.GetDuration(remoteConnectionTimeout)
46-
cfg.TenancyOpts = tenancy.InitFromViper(v)
44+
cfg.ClientConfig.TLSSetting = remoteTLS.ToOtelClientConfig()
45+
cfg.TimeoutSettings.Timeout = v.GetDuration(remoteConnectionTimeout)
46+
cfg.Tenancy = tenancy.InitFromViper(v)
4747
return nil
4848
}

plugin/storage/grpc/options_test.go

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,61 +18,60 @@ import (
1818
)
1919

2020
func TestOptionsWithFlags(t *testing.T) {
21-
v, command := config.Viperize(v1AddFlags, tenancy.AddFlags)
21+
v, command := config.Viperize(addFlags, tenancy.AddFlags)
2222
err := command.ParseFlags([]string{
2323
"--grpc-storage.server=foo:12345",
2424
"--multi-tenancy.header=x-scope-orgid",
2525
})
2626
require.NoError(t, err)
27-
var cfg Configuration
28-
require.NoError(t, v1InitFromViper(&cfg, v))
27+
var cfg Config
28+
require.NoError(t, initFromViper(&cfg, v))
2929

30-
assert.Equal(t, "foo:12345", cfg.RemoteServerAddr)
31-
assert.False(t, cfg.TenancyOpts.Enabled)
32-
assert.Equal(t, "x-scope-orgid", cfg.TenancyOpts.Header)
30+
assert.Equal(t, "foo:12345", cfg.ClientConfig.Endpoint)
31+
assert.False(t, cfg.Tenancy.Enabled)
32+
assert.Equal(t, "x-scope-orgid", cfg.Tenancy.Header)
3333
}
3434

3535
func TestRemoteOptionsWithFlags(t *testing.T) {
36-
v, command := config.Viperize(v1AddFlags)
36+
v, command := config.Viperize(addFlags)
3737
err := command.ParseFlags([]string{
3838
"--grpc-storage.server=localhost:2001",
3939
"--grpc-storage.tls.enabled=true",
4040
"--grpc-storage.connection-timeout=60s",
4141
})
4242
require.NoError(t, err)
43-
var cfg Configuration
44-
require.NoError(t, v1InitFromViper(&cfg, v))
43+
var cfg Config
44+
require.NoError(t, initFromViper(&cfg, v))
4545

46-
assert.Equal(t, "localhost:2001", cfg.RemoteServerAddr)
47-
assert.True(t, cfg.RemoteTLS.Enabled)
48-
assert.Equal(t, 60*time.Second, cfg.RemoteConnectTimeout)
46+
assert.Equal(t, "localhost:2001", cfg.ClientConfig.Endpoint)
47+
assert.False(t, cfg.ClientConfig.TLSSetting.Insecure)
48+
assert.Equal(t, 60*time.Second, cfg.TimeoutSettings.Timeout)
4949
}
5050

5151
func TestRemoteOptionsNoTLSWithFlags(t *testing.T) {
52-
v, command := config.Viperize(v1AddFlags)
52+
v, command := config.Viperize(addFlags)
5353
err := command.ParseFlags([]string{
5454
"--grpc-storage.server=localhost:2001",
5555
"--grpc-storage.tls.enabled=false",
5656
"--grpc-storage.connection-timeout=60s",
5757
})
5858
require.NoError(t, err)
59-
var cfg Configuration
60-
require.NoError(t, v1InitFromViper(&cfg, v))
59+
var cfg Config
60+
require.NoError(t, initFromViper(&cfg, v))
6161

62-
assert.Equal(t, "localhost:2001", cfg.RemoteServerAddr)
63-
assert.False(t, cfg.RemoteTLS.Enabled)
64-
assert.Equal(t, 60*time.Second, cfg.RemoteConnectTimeout)
62+
assert.Equal(t, "localhost:2001", cfg.ClientConfig.Endpoint)
63+
assert.True(t, cfg.ClientConfig.TLSSetting.Insecure)
64+
assert.Equal(t, 60*time.Second, cfg.TimeoutSettings.Timeout)
6565
}
6666

6767
func TestFailedTLSFlags(t *testing.T) {
68-
v, command := config.Viperize(v1AddFlags)
68+
v, command := config.Viperize(addFlags)
6969
err := command.ParseFlags([]string{
7070
"--grpc-storage.tls.enabled=false",
7171
"--grpc-storage.tls.cert=blah", // invalid unless tls.enabled=true
7272
})
7373
require.NoError(t, err)
7474
f := NewFactory()
75-
f.configV2 = nil
7675
core, logs := observer.New(zap.NewAtomicLevelAt(zapcore.ErrorLevel))
7776
logger := zap.New(core, zap.WithFatalHook(zapcore.WriteThenPanic))
7877
require.Panics(t, func() { f.InitFromViper(v, logger) })

0 commit comments

Comments
 (0)