-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add Kafka OTEL receiver/ingester #2221
Merged
pavolloffay
merged 3 commits into
jaegertracing:master
from
pavolloffay:otel-kafka-ingester
May 6, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2020 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package kafka | ||
|
||
import ( | ||
"github.com/open-telemetry/opentelemetry-collector/config/configmodels" | ||
|
||
ingesterApp "github.com/jaegertracing/jaeger/cmd/ingester/app" | ||
) | ||
|
||
// Config hold configuration for Jaeger kafka receiver/ingester. | ||
type Config struct { | ||
configmodels.ReceiverSettings `mapstructure:",squash"` | ||
ingesterApp.Options `mapstructure:",squash"` | ||
} |
91 changes: 91 additions & 0 deletions
91
cmd/opentelemetry-collector/app/receiver/kafka/config_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) 2020 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package kafka | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector/config" | ||
"github.com/open-telemetry/opentelemetry-collector/config/configcheck" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/jaegertracing/jaeger/cmd/flags" | ||
"github.com/jaegertracing/jaeger/cmd/ingester/app" | ||
jConfig "github.com/jaegertracing/jaeger/pkg/config" | ||
) | ||
|
||
func TestDefaultConfig(t *testing.T) { | ||
v, c := jConfig.Viperize(app.AddFlags) | ||
err := c.ParseFlags([]string{""}) | ||
require.NoError(t, err) | ||
factory := &Factory{OptionsFactory: func() *app.Options { | ||
opts := DefaultOptions() | ||
opts.InitFromViper(v) | ||
return opts | ||
}} | ||
defaultCfg := factory.CreateDefaultConfig().(*Config) | ||
assert.NoError(t, configcheck.ValidateConfig(defaultCfg)) | ||
assert.Equal(t, "jaeger-spans", defaultCfg.Topic) | ||
assert.Equal(t, "protobuf", defaultCfg.Encoding) | ||
assert.Equal(t, []string{"127.0.0.1:9092"}, defaultCfg.Brokers) | ||
assert.Equal(t, "none", defaultCfg.Authentication) | ||
assert.Equal(t, "/etc/krb5.conf", defaultCfg.Kerberos.ConfigPath) | ||
assert.Equal(t, "kafka", defaultCfg.Kerberos.ServiceName) | ||
assert.Equal(t, false, defaultCfg.TLS.Enabled) | ||
} | ||
|
||
func TestLoadConfigAndFlags(t *testing.T) { | ||
factories, err := config.ExampleComponents() | ||
require.NoError(t, err) | ||
|
||
v, c := jConfig.Viperize(app.AddFlags, flags.AddConfigFileFlag) | ||
err = c.ParseFlags([]string{"--config-file=./testdata/jaeger-config.yaml", "--kafka.consumer.topic=jaeger-test", "--kafka.consumer.brokers=host1,host2", "--kafka.consumer.tls.cert=from-flag"}) | ||
require.NoError(t, err) | ||
|
||
err = flags.TryLoadConfigFile(v) | ||
require.NoError(t, err) | ||
|
||
factory := &Factory{OptionsFactory: func() *app.Options { | ||
opts := DefaultOptions() | ||
opts.InitFromViper(v) | ||
assert.Equal(t, "jaeger-test", opts.Topic) | ||
assert.Equal(t, []string{"host1", "host2"}, opts.Brokers) | ||
return opts | ||
}} | ||
|
||
factories.Receivers[TypeStr] = factory | ||
cfg, err := config.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) | ||
require.NoError(t, err) | ||
require.NotNil(t, cfg) | ||
|
||
kafkaCfg := cfg.Receivers[TypeStr].(*Config) | ||
assert.Equal(t, TypeStr, kafkaCfg.Name()) | ||
assert.Equal(t, "jaeger-prod", kafkaCfg.Topic) | ||
assert.Equal(t, "emojis", kafkaCfg.Encoding) | ||
assert.Equal(t, []string{"foo", "bar"}, kafkaCfg.Options.Brokers) | ||
assert.Equal(t, "tls", kafkaCfg.Options.Authentication) | ||
assert.Equal(t, "user", kafkaCfg.Options.PlainText.UserName) | ||
assert.Equal(t, "123", kafkaCfg.Options.PlainText.Password) | ||
assert.Equal(t, true, kafkaCfg.Options.TLS.Enabled) | ||
assert.Equal(t, "ca.crt", kafkaCfg.Options.TLS.CAPath) | ||
assert.Equal(t, "key.crt", kafkaCfg.Options.TLS.KeyPath) | ||
pavolloffay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert.Equal(t, "from-flag", kafkaCfg.Options.TLS.CertPath) | ||
assert.Equal(t, true, kafkaCfg.Options.TLS.SkipHostVerify) | ||
assert.Equal(t, "jaeger", kafkaCfg.Options.Kerberos.Realm) | ||
assert.Equal(t, "/etc/foo", kafkaCfg.Options.Kerberos.ConfigPath) | ||
assert.Equal(t, "from-jaeger-config", kafkaCfg.Options.Kerberos.Username) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) 2020 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package kafka | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector/component" | ||
"github.com/open-telemetry/opentelemetry-collector/config/configerror" | ||
"github.com/open-telemetry/opentelemetry-collector/config/configmodels" | ||
"github.com/open-telemetry/opentelemetry-collector/consumer" | ||
|
||
ingesterApp "github.com/jaegertracing/jaeger/cmd/ingester/app" | ||
) | ||
|
||
const ( | ||
TypeStr = "jaeger_kafka" | ||
) | ||
|
||
// OptionsFactory returns initialized ingester app.Options structure. | ||
type OptionsFactory func() *ingesterApp.Options | ||
|
||
// DefaultOptions creates Kafka options supported by this receiver. | ||
func DefaultOptions() *ingesterApp.Options { | ||
return &ingesterApp.Options{} | ||
} | ||
|
||
type Factory struct { | ||
OptionsFactory OptionsFactory | ||
} | ||
|
||
var _ component.ReceiverFactory = (*Factory)(nil) | ||
|
||
// Type returns the receiver type. | ||
func (f Factory) Type() configmodels.Type { | ||
return TypeStr | ||
} | ||
|
||
// CreateDefaultConfig creates default config. | ||
// This function implements OTEL component.ReceiverFactoryBase interface. | ||
func (f Factory) CreateDefaultConfig() configmodels.Receiver { | ||
opts := f.OptionsFactory() | ||
return &Config{ | ||
Options: *opts, | ||
} | ||
} | ||
|
||
// CustomUnmarshaler returns custom marshaller. | ||
// This function implements OTEL component.ReceiverFactoryBase interface. | ||
func (f Factory) CustomUnmarshaler() component.CustomUnmarshaler { | ||
return nil | ||
} | ||
|
||
// CreateTraceReceiver returns Kafka receiver. | ||
// This function implements OTEL component.ReceiverFactory. | ||
func (f Factory) CreateTraceReceiver( | ||
_ context.Context, | ||
params component.ReceiverCreateParams, | ||
cfg configmodels.Receiver, | ||
nextConsumer consumer.TraceConsumer, | ||
) (component.TraceReceiver, error) { | ||
kafkaCfg, ok := cfg.(*Config) | ||
if !ok { | ||
return nil, fmt.Errorf("could not cast configuration to %s", TypeStr) | ||
} | ||
return new(kafkaCfg, nextConsumer, params) | ||
} | ||
|
||
// CreateMetricsReceiver returns metrics receiver. | ||
// This function implements OTEL component.ReceiverFactory. | ||
func (f Factory) CreateMetricsReceiver( | ||
_ context.Context, | ||
_ component.ReceiverCreateParams, | ||
_ configmodels.Receiver, | ||
_ consumer.MetricsConsumer, | ||
) (component.MetricsReceiver, error) { | ||
return nil, configerror.ErrDataTypeIsNotSupported | ||
} |
70 changes: 70 additions & 0 deletions
70
cmd/opentelemetry-collector/app/receiver/kafka/factory_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) 2020 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package kafka | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector/component" | ||
"github.com/open-telemetry/opentelemetry-collector/config/configcheck" | ||
"github.com/open-telemetry/opentelemetry-collector/config/configerror" | ||
"github.com/open-telemetry/opentelemetry-collector/config/configmodels" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap" | ||
|
||
ingesterApp "github.com/jaegertracing/jaeger/cmd/ingester/app" | ||
jConfig "github.com/jaegertracing/jaeger/pkg/config" | ||
) | ||
|
||
// TODO failing | ||
func TestCreateTraceReceiver(t *testing.T) { | ||
v, _ := jConfig.Viperize(ingesterApp.AddFlags) | ||
opts := DefaultOptions() | ||
opts.InitFromViper(v) | ||
factory := &Factory{OptionsFactory: func() *ingesterApp.Options { | ||
return opts | ||
}} | ||
exporter, err := factory.CreateTraceReceiver(context.Background(), component.ReceiverCreateParams{Logger: zap.NewNop()}, factory.CreateDefaultConfig(), nil) | ||
require.Nil(t, exporter) | ||
assert.EqualError(t, err, "kafka: client has run out of available brokers to talk to (Is your cluster reachable?)") | ||
} | ||
|
||
func TestCreateTraceExporter_nilConfig(t *testing.T) { | ||
factory := &Factory{} | ||
exporter, err := factory.CreateTraceReceiver(context.Background(), component.ReceiverCreateParams{}, nil, nil) | ||
require.Nil(t, exporter) | ||
assert.EqualError(t, err, "could not cast configuration to jaeger_kafka") | ||
} | ||
|
||
func TestCreateMetricsExporter(t *testing.T) { | ||
f := Factory{OptionsFactory: DefaultOptions} | ||
mReceiver, err := f.CreateMetricsReceiver(context.Background(), component.ReceiverCreateParams{}, f.CreateDefaultConfig(), nil) | ||
assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported) | ||
assert.Nil(t, mReceiver) | ||
} | ||
|
||
func TestCreateDefaultConfig(t *testing.T) { | ||
factory := Factory{OptionsFactory: DefaultOptions} | ||
cfg := factory.CreateDefaultConfig() | ||
assert.NotNil(t, cfg, "failed to create default config") | ||
assert.NoError(t, configcheck.ValidateConfig(cfg)) | ||
} | ||
|
||
func TestType(t *testing.T) { | ||
factory := Factory{OptionsFactory: DefaultOptions} | ||
assert.Equal(t, configmodels.Type(TypeStr), factory.Type()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to allow one of the flag values to be passed to the final config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kafkaCfg.Options.Kerberos.Username
is passed from jaeger config fileThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that none of the CLI flag values are making it into the final config - would be good if atleast one did for completeness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flags or config file are the same source for viper. A couple of lines above we test that flags are passed to the factory.