forked from jaegertracing/jaeger
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Kafka OTEL receiver/ingester (jaegertracing#2221)
* Add Kafka OTEL receiver/ingester Signed-off-by: Pavol Loffay <ploffay@redhat.com> * Fix review Signed-off-by: Pavol Loffay <ploffay@redhat.com> * Use tls.cert from flags Signed-off-by: Pavol Loffay <ploffay@redhat.com>
- Loading branch information
1 parent
6cdaea8
commit ef8205d
Showing
21 changed files
with
629 additions
and
54 deletions.
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
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) | ||
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 | ||
} |
Oops, something went wrong.