Skip to content

Commit

Permalink
otel helper instead of tls package
Browse files Browse the repository at this point in the history
Signed-off-by: chahatsagarmain <[email protected]>
  • Loading branch information
chahatsagarmain committed Nov 28, 2024
1 parent 4a14e87 commit 51d1607
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 38 deletions.
8 changes: 4 additions & 4 deletions cmd/ingester/app/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config/configtls"

"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
"github.com/jaegertracing/jaeger/pkg/kafka/auth"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/plugin/storage/kafka"
Expand Down Expand Up @@ -64,15 +64,15 @@ func TestTLSFlags(t *testing.T) {
},
{
flags: []string{"--kafka.consumer.authentication=kerberos", "--kafka.consumer.tls.enabled=true"},
expected: auth.AuthenticationConfig{Authentication: "kerberos", Kerberos: kerb, TLS: tlscfg.Options{Enabled: true}, PlainText: plain},
expected: auth.AuthenticationConfig{Authentication: "kerberos", Kerberos: kerb, TLS: configtls.ClientConfig{}, PlainText: plain},
},
{
flags: []string{"--kafka.consumer.authentication=tls"},
expected: auth.AuthenticationConfig{Authentication: "tls", Kerberos: kerb, TLS: tlscfg.Options{Enabled: true}, PlainText: plain},
expected: auth.AuthenticationConfig{Authentication: "tls", Kerberos: kerb, TLS: configtls.ClientConfig{}, PlainText: plain},
},
{
flags: []string{"--kafka.consumer.authentication=tls", "--kafka.consumer.tls.enabled=false"},
expected: auth.AuthenticationConfig{Authentication: "tls", Kerberos: kerb, TLS: tlscfg.Options{Enabled: true}, PlainText: plain},
expected: auth.AuthenticationConfig{Authentication: "tls", Kerberos: kerb, TLS: configtls.ClientConfig{}, PlainText: plain},
},
}

Expand Down
3 changes: 0 additions & 3 deletions cmd/ingester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ func main() {
consumer.Start()

svc.RunAndThen(func() {
if err := options.TLS.Close(); err != nil {
logger.Error("Failed to close TLS certificates watcher", zap.Error(err))
}
if err = consumer.Close(); err != nil {
logger.Error("Failed to close consumer", zap.Error(err))
}
Expand Down
19 changes: 10 additions & 9 deletions pkg/kafka/auth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/Shopify/sarama"
"github.com/spf13/viper"
"go.opentelemetry.io/collector/config/configtls"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
Expand All @@ -30,10 +31,10 @@ var authTypes = []string{

// AuthenticationConfig describes the configuration properties needed authenticate with kafka cluster
type AuthenticationConfig struct {
Authentication string `mapstructure:"type"`
Kerberos KerberosConfig `mapstructure:"kerberos"`
TLS tlscfg.Options `mapstructure:"tls"`
PlainText PlainTextConfig `mapstructure:"plaintext"`
Authentication string `mapstructure:"type"`
Kerberos KerberosConfig `mapstructure:"kerberos"`
TLS configtls.ClientConfig `mapstructure:"tls"`
PlainText PlainTextConfig `mapstructure:"plaintext"`
}

// SetConfiguration set configure authentication into sarama config structure
Expand All @@ -42,7 +43,7 @@ func (config *AuthenticationConfig) SetConfiguration(saramaConfig *sarama.Config
if strings.Trim(authentication, " ") == "" {
authentication = none
}
if config.Authentication == tls || config.TLS.Enabled {
if config.Authentication == tls {
err := setTLSConfiguration(&config.TLS, saramaConfig, logger)
if err != nil {
return err
Expand Down Expand Up @@ -79,15 +80,15 @@ func (config *AuthenticationConfig) InitFromViper(configPrefix string, v *viper.
Prefix: configPrefix,
}

var err error
config.TLS, err = tlsClientConfig.InitFromViper(v)
opts, err := tlsClientConfig.InitFromViper(v)
if err != nil {
return fmt.Errorf("failed to process Kafka TLS options: %w", err)
}
if config.Authentication == tls {
config.TLS.Enabled = true
opts.Enabled = true
config.TLS = opts.ToOtelClientConfig()
}

fmt.Printf("%v \n", opts.Enabled)
config.PlainText.Username = v.GetString(configPrefix + plainTextPrefix + suffixPlainTextUsername)
config.PlainText.Password = v.GetString(configPrefix + plainTextPrefix + suffixPlainTextPassword)
config.PlainText.Mechanism = v.GetString(configPrefix + plainTextPrefix + suffixPlainTextMechanism)
Expand Down
9 changes: 3 additions & 6 deletions pkg/kafka/auth/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config/configtls"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"

"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
)

func addFlags(flags *flag.FlagSet) {
Expand Down Expand Up @@ -64,9 +64,7 @@ func Test_InitFromViper(t *testing.T) {
KeyTabPath: "/path/to/keytab",
DisablePAFXFast: true,
},
TLS: tlscfg.Options{
Enabled: true,
},
TLS: configtls.ClientConfig{},
PlainText: PlainTextConfig{
Username: "user",
Password: "password",
Expand Down Expand Up @@ -139,7 +137,7 @@ func TestSetConfiguration(t *testing.T) {
{
name: "TLS authentication with invalid cipher suite",
authType: "tls",
expectedError: "error loading tls config: failed to get cipher suite ids from cipher suite names: cipher suite fail not supported or doesn't exist",
expectedError: "error loading tls config: failed to load TLS config: invalid TLS cipher suite: \"fail\"",
},
}

Expand All @@ -149,7 +147,6 @@ func TestSetConfiguration(t *testing.T) {
"--kafka.auth.authentication=" + tt.authType,
})
authConfig := &AuthenticationConfig{}
defer authConfig.TLS.Close()
err := authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)

Expand Down
10 changes: 5 additions & 5 deletions pkg/kafka/auth/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
package auth

import (
"context"
"fmt"

"github.com/Shopify/sarama"
"go.opentelemetry.io/collector/config/configtls"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
)

func setTLSConfiguration(config *tlscfg.Options, saramaConfig *sarama.Config, logger *zap.Logger) error {
if config.Enabled {
tlsConfig, err := config.Config(logger)
func setTLSConfiguration(config *configtls.ClientConfig, saramaConfig *sarama.Config, _ *zap.Logger) error {
if !config.Insecure {
tlsConfig, err := config.LoadTLSConfig(context.Background())
if err != nil {
return fmt.Errorf("error loading tls config: %w", err)
}
Expand Down
8 changes: 2 additions & 6 deletions pkg/kafka/auth/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@ import (
"github.com/Shopify/sarama"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config/configtls"
"go.uber.org/zap/zaptest"

"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
)

func TestSetTLSConfiguration(t *testing.T) {
logger := zaptest.NewLogger(t)
saramaConfig := sarama.NewConfig()
tlsConfig := &tlscfg.Options{
Enabled: true,
}
tlsConfig := &configtls.ClientConfig{}
err := setTLSConfiguration(tlsConfig, saramaConfig, logger)
require.NoError(t, err)
assert.True(t, saramaConfig.Net.TLS.Enable)
assert.NotNil(t, saramaConfig.Net.TLS.Config)
defer tlsConfig.Close()
}
1 change: 0 additions & 1 deletion plugin/storage/kafka/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,5 @@ func (f *Factory) Close() error {
if f.producer != nil {
errs = append(errs, f.producer.Close())
}
errs = append(errs, f.options.Config.TLS.Close())
return errors.Join(errs...)
}
8 changes: 4 additions & 4 deletions plugin/storage/kafka/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/Shopify/sarama"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config/configtls"

"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
"github.com/jaegertracing/jaeger/pkg/kafka/auth"
)

Expand Down Expand Up @@ -181,15 +181,15 @@ func TestTLSFlags(t *testing.T) {
},
{
flags: []string{"--kafka.producer.authentication=kerberos", "--kafka.producer.tls.enabled=true"},
expected: auth.AuthenticationConfig{Authentication: "kerberos", Kerberos: kerb, TLS: tlscfg.Options{Enabled: true}, PlainText: plain},
expected: auth.AuthenticationConfig{Authentication: "kerberos", Kerberos: kerb, TLS: configtls.ClientConfig{}, PlainText: plain},
},
{
flags: []string{"--kafka.producer.authentication=tls"},
expected: auth.AuthenticationConfig{Authentication: "tls", Kerberos: kerb, TLS: tlscfg.Options{Enabled: true}, PlainText: plain},
expected: auth.AuthenticationConfig{Authentication: "tls", Kerberos: kerb, TLS: configtls.ClientConfig{}, PlainText: plain},
},
{
flags: []string{"--kafka.producer.authentication=tls", "--kafka.producer.tls.enabled=false"},
expected: auth.AuthenticationConfig{Authentication: "tls", Kerberos: kerb, TLS: tlscfg.Options{Enabled: true}, PlainText: plain},
expected: auth.AuthenticationConfig{Authentication: "tls", Kerberos: kerb, TLS: configtls.ClientConfig{}, PlainText: plain},
},
}

Expand Down

0 comments on commit 51d1607

Please sign in to comment.