Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase codecov of pkg/kafka #5682

Merged
merged 37 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7bb8259
added more options auth for cassandra
hellspawn679 Jun 14, 2024
e8775e7
added AllowedAuthenticators
hellspawn679 Jun 14, 2024
89b2275
Merge branch 'jaegertracing:main' into auth
hellspawn679 Jun 16, 2024
9346d16
added aiven auth
hellspawn679 Jun 16, 2024
4e4450c
reverting back
hellspawn679 Jun 16, 2024
279ab59
added flags for auth
hellspawn679 Jun 16, 2024
e2cf82e
Merge branch 'main' into auth
hellspawn679 Jun 17, 2024
504ac07
updated integration test for cassandra
hellspawn679 Jun 17, 2024
1959b26
added flags
hellspawn679 Jun 17, 2024
31a8da3
Merge branch 'main' into auth
hellspawn679 Jun 17, 2024
0c892c7
update flag description
hellspawn679 Jun 17, 2024
82204d4
updated flag
hellspawn679 Jun 17, 2024
08ed6a6
Merge branch 'jaegertracing:main' into auth
hellspawn679 Jun 22, 2024
047c945
updated
Jun 25, 2024
7b0ad89
Merge branch 'main' of https://github.com/hellspawn679/jaeger
Jun 27, 2024
db5f04b
increase codecov
Jun 27, 2024
ee78dbe
updated
Jun 27, 2024
d6efe4f
testing_for_plain_test
Jun 27, 2024
a2b5373
updated
Jun 28, 2024
56b91c2
Merge branch 'main' into code_cov
hellspawn679 Jun 28, 2024
07ab8d4
fixed goleak
Jun 29, 2024
2b43f34
increase code_cov
Jun 29, 2024
56e1630
tls fail case
Jun 29, 2024
a498277
minor change
Jun 29, 2024
855892f
increase plaintest code_cov
Jun 30, 2024
db6d2ba
added test for kafka consumer
Jun 30, 2024
ffce2af
Merge branch 'main' into code_cov
hellspawn679 Jun 30, 2024
57ff7d0
fixed
Jun 30, 2024
ab430f0
increase consumer code cov
Jun 30, 2024
9ed2d3a
added test for kafka producer
Jun 30, 2024
e61a8d8
simplified the code
Jul 1, 2024
0bae39e
Merge branch 'main' into code_cov
hellspawn679 Jul 1, 2024
cdb5556
fixed
Jul 2, 2024
8d806bb
Merge branch 'main' into code_cov
hellspawn679 Jul 2, 2024
25bc2fa
Merge branch 'main' into code_cov
yurishkuro Jul 3, 2024
e067769
fixed
Jul 3, 2024
e7a0875
Merge branch 'code_cov' of https://github.com/hellspawn679/jaeger int…
Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/ingester/app/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestOptionsWithFlags(t *testing.T) {
"--kafka.consumer.protocol-version=1.0.0",
"--ingester.parallelism=5",
"--ingester.deadlockInterval=2m",
"--kafka.consumer.authentication=tls",
})
o.InitFromViper(v)

Expand All @@ -56,6 +57,7 @@ func TestOptionsWithFlags(t *testing.T) {
assert.Equal(t, 5, o.Parallelism)
assert.Equal(t, 2*time.Minute, o.DeadlockInterval)
assert.Equal(t, kafka.EncodingJSON, o.Encoding)
assert.Equal(t, "tls", o.AuthenticationConfig.Authentication)
}

func TestTLSFlags(t *testing.T) {
Expand Down
85 changes: 59 additions & 26 deletions internal/tracegen/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,63 @@ import (
)

func Test_SimulateTraces(t *testing.T) {
logger, buf := testutils.NewLogger()
tp := sdktrace.NewTracerProvider()
tracers := []trace.Tracer{tp.Tracer("stdout")}
wg := sync.WaitGroup{}
wg.Add(1)
var running uint32 = 1

worker := &worker{
logger: logger,
tracers: tracers,
wg: &wg,
id: 7,
running: &running,
Config: Config{
Traces: 7,
Duration: time.Second,
Pause: time.Second,
Service: "stdout",
Debug: true,
Firehose: true,
},
}
expectedOutput := `{"level":"info","msg":"Worker 7 generated 7 traces"}` + "\n"

worker.simulateTraces()
assert.Equal(t, expectedOutput, buf.String())
// First test case with Pause = time.Second
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
t.Run("Pause time.Second", func(t *testing.T) {
logger, buf := testutils.NewLogger()
tp := sdktrace.NewTracerProvider()
tracers := []trace.Tracer{tp.Tracer("stdout")}
wg := sync.WaitGroup{}
wg.Add(1)
var running uint32 = 1

worker := &worker{
logger: logger,
tracers: tracers,
wg: &wg,
id: 7,
running: &running,
Config: Config{
Traces: 7,
Duration: time.Second,
Pause: time.Second,
Service: "stdout",
Debug: true,
Firehose: true,
},
}
expectedOutput := `{"level":"info","msg":"Worker 7 generated 7 traces"}` + "\n"

worker.simulateTraces()
assert.Equal(t, expectedOutput, buf.String())
})

// Second test case with Pause = 3 * time.Second
t.Run("Pause 3 * time.Second", func(t *testing.T) {
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
logger, buf := testutils.NewLogger()
tp := sdktrace.NewTracerProvider()
tracers := []trace.Tracer{tp.Tracer("stdout")}
wg := sync.WaitGroup{}
wg.Add(1)
var running uint32 = 1

worker := &worker{
logger: logger,
tracers: tracers,
wg: &wg,
id: 7,
running: &running,
Config: Config{
Traces: 7,
Duration: time.Second,
Pause: 3 * time.Second,
Service: "stdout",
Debug: true,
Firehose: true,
},
}
expectedOutput := `{"level":"info","msg":"Worker 7 generated 7 traces"}` + "\n"

worker.simulateTraces()
assert.Equal(t, expectedOutput, buf.String())
})
}
87 changes: 87 additions & 0 deletions pkg/kafka/auth/config_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package auth

import (
"testing"

"github.com/Shopify/sarama"
"github.com/spf13/viper"
//"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

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



func TestSetConfiguration(t *testing.T) {
logger, _ := zap.NewDevelopment()
saramaConfig := sarama.NewConfig()
v := viper.New()
configPrefix := "kafka.auth."
v.Set(configPrefix+suffixAuthentication, "kerberos")
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
v.Set(configPrefix+kerberosPrefix+suffixKerberosServiceName, "kafka")
v.Set(configPrefix+kerberosPrefix+suffixKerberosRealm, "EXAMPLE.COM")
v.Set(configPrefix+kerberosPrefix+suffixKerberosUseKeyTab, true)
v.Set(configPrefix+kerberosPrefix+suffixKerberosUsername, "user")
v.Set(configPrefix+kerberosPrefix+suffixKerberosPassword, "password")
v.Set(configPrefix+kerberosPrefix+suffixKerberosConfig, "/path/to/krb5.conf")
v.Set(configPrefix+kerberosPrefix+suffixKerberosKeyTab, "/path/to/keytab")
v.Set(configPrefix+kerberosPrefix+suffixKerberosDisablePAFXFAST, true)
v.Set(configPrefix+plainTextPrefix+suffixPlainTextUsername, "user")
v.Set(configPrefix+plainTextPrefix+suffixPlainTextPassword, "password")
v.Set(configPrefix+plainTextPrefix+suffixPlainTextMechanism, "SCRAM-SHA-256")

authConfig := &AuthenticationConfig{}
err := authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)
require.NoError(t, authConfig.SetConfiguration(saramaConfig, logger))
// plaintest test(SCRAM-SHA-256)
v.Set(configPrefix+suffixAuthentication, "plaintext")
authConfig = &AuthenticationConfig{}
err = authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)
require.NoError(t, authConfig.SetConfiguration(saramaConfig, logger))
// plaintest test(SCRAM-SHA-512)
v.Set(configPrefix+plainTextPrefix+suffixPlainTextMechanism, "SCRAM-SHA-512")
authConfig = &AuthenticationConfig{}
err = authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)
require.NoError(t, authConfig.SetConfiguration(saramaConfig, logger))
// plaintest test(PLAIN)
v.Set(configPrefix+plainTextPrefix+suffixPlainTextMechanism, "PLAIN")
authConfig = &AuthenticationConfig{}
err = authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)
require.NoError(t, authConfig.SetConfiguration(saramaConfig, logger))
// default value
v.Set(configPrefix+suffixAuthentication, "none")
authConfig = &AuthenticationConfig{}
err = authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)
require.Error(t, authConfig.SetConfiguration(saramaConfig, logger), nil)
// none value
v.Set(configPrefix+suffixAuthentication, " ")
authConfig = &AuthenticationConfig{}
err = authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)
require.NoError(t, authConfig.SetConfiguration(saramaConfig, logger))
// tls value
// v.Set(configPrefix + suffixAuthentication, "tls")
// authConfig = &AuthenticationConfig{}
// err = authConfig.InitFromViper(configPrefix, v)
// require.NoError(t, err)
// _,err=authConfig.TLS.Config(zap.NewNop())
// // require.NoError(t, err)
// // require.NoError(t,authConfig.SetConfiguration(saramaConfig, logger))
// default value
v.Set(configPrefix+suffixAuthentication, "error")
authConfig = &AuthenticationConfig{}
err = authConfig.InitFromViper(configPrefix, v)
require.NoError(t, err)
expected_error := "Unknown/Unsupported authentication method error to kafka cluster"
require.Error(t, authConfig.SetConfiguration(saramaConfig, logger), expected_error)
}
1 change: 1 addition & 0 deletions plugin/storage/integration/kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (s *KafkaIntegrationTestSuite) initialize(t *testing.T) {
clientID,
"--ingester.parallelism",
"1000",
"--kafka.consumer.authentication=plaintext",
})
require.NoError(t, err)
options := app.Options{
Expand Down
Loading