Skip to content

Remove dependency on tlscfg.Options #6468

@yurishkuro

Description

@yurishkuro

In a series of PRs for #4316 we removed the dependency on tlscfg.Options producing tls.Config by replacing it with the corresponding OTEL functions (PR #6345).

We can clean this up even further and make Options struct to be private in tlscfg, by changing the signature of ServerFlagsConfig.InitFromViper and ClientFlagsConfig.InitFromViper to return the corresponding OTEL structs directly, rather than returning Options, because every time we call those functions we immediately call ToOtelServerConfig() on the returned value, for example

tlsOpts, err := cfg.tls.InitFromViper(v)
if err != nil {
return fmt.Errorf("failed to parse GRPC TLS options: %w", err)
}
opts.TLSSetting = tlsOpts.ToOtelServerConfig()

Sample change:

-func (c ServerFlagsConfig) InitFromViper(v *viper.Viper) (Options, error) {
+func (c ServerFlagsConfig) InitFromViper(v *viper.Viper) (*configtls.ServerConfig, error) {
        var p Options
        p.Enabled = v.GetBool(c.Prefix + tlsEnabled)
        p.CertPath = v.GetString(c.Prefix + tlsCert)
@@ -99,11 +100,11 @@ func (c ServerFlagsConfig) InitFromViper(v *viper.Viper) (Options, error) {
        if !p.Enabled {
                var empty Options
                if !reflect.DeepEqual(&p, &empty) {
-                       return p, fmt.Errorf("%s.tls.* options cannot be used when %s is false", c.Prefix, c.Prefix+tlsEnabled)
+                       return nil, fmt.Errorf("%s.tls.* options cannot be used when %s is false", c.Prefix, c.Prefix+tlsEnabled)
                }
        }

-       return p, nil
+       return p.ToOtelServerConfig(), nil
 }

We should also remove mapstructure tags from the Options struct, since we're not using it in the config files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/otelenhancementgood first issueGood for beginnershelp wantedFeatures that maintainers are willing to accept but do not have cycles to implement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions