-
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 Cassandra OTEL exporter #2139
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 cassandra | ||
|
||
import ( | ||
"github.com/open-telemetry/opentelemetry-collector/config/configmodels" | ||
|
||
"github.com/jaegertracing/jaeger/plugin/storage/cassandra" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also we should consider naming this import There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is only in one file, where there is a conflict in imports. |
||
) | ||
|
||
// Config holds configuration of Jaeger Cassandra exporter/storage. | ||
type Config struct { | ||
configmodels.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. | ||
cassandra.Options `mapstructure:",squash"` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// 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 cassandra | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
"time" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector/config" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/jaegertracing/jaeger/cmd/flags" | ||
jConfig "github.com/jaegertracing/jaeger/pkg/config" | ||
"github.com/jaegertracing/jaeger/plugin/storage/cassandra" | ||
) | ||
|
||
func TestDefaultConfig(t *testing.T) { | ||
factory := &Factory{OptionsFactory: func() *cassandra.Options { | ||
v, _ := jConfig.Viperize(DefaultOptions().AddFlags) | ||
opts := DefaultOptions() | ||
opts.InitFromViper(v) | ||
return opts | ||
}} | ||
defaultCfg := factory.CreateDefaultConfig().(*Config) | ||
assert.Equal(t, []string{"127.0.0.1"}, defaultCfg.Options.GetPrimary().Servers) | ||
assert.Equal(t, []string{"127.0.0.1"}, defaultCfg.Options.Primary.Servers) | ||
assert.Equal(t, 2, defaultCfg.Primary.ConnectionsPerHost) | ||
assert.Equal(t, "jaeger_v1_test", defaultCfg.Primary.Keyspace) | ||
assert.Equal(t, 3, defaultCfg.Primary.MaxRetryAttempts) | ||
assert.Equal(t, 4, defaultCfg.Primary.ProtoVersion) | ||
assert.Equal(t, time.Minute, defaultCfg.Primary.ReconnectInterval) | ||
assert.Equal(t, time.Hour*12, defaultCfg.SpanStoreWriteCacheTTL) | ||
assert.Equal(t, true, defaultCfg.Index.Tags) | ||
assert.Equal(t, true, defaultCfg.Index.Logs) | ||
assert.Equal(t, true, defaultCfg.Index.ProcessTags) | ||
} | ||
|
||
func TestLoadConfigAndFlags(t *testing.T) { | ||
factories, err := config.ExampleComponents() | ||
require.NoError(t, err) | ||
|
||
v, c := jConfig.Viperize(DefaultOptions().AddFlags, flags.AddConfigFileFlag) | ||
err = c.ParseFlags([]string{"--cassandra.servers=bar", "--cassandra.port=9000", "--config-file=./testdata/jaeger-config.yaml"}) | ||
require.NoError(t, err) | ||
|
||
err = flags.TryLoadConfigFile(v) | ||
require.NoError(t, err) | ||
|
||
factory := &Factory{OptionsFactory: func() *cassandra.Options { | ||
opts := DefaultOptions() | ||
opts.InitFromViper(v) | ||
require.Equal(t, []string{"bar"}, opts.GetPrimary().Servers) | ||
return opts | ||
}} | ||
|
||
factories.Exporters[TypeStr] = factory | ||
colConfig, err := config.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) | ||
require.NoError(t, err) | ||
require.NotNil(t, colConfig) | ||
|
||
cfg := colConfig.Exporters[TypeStr].(*Config) | ||
assert.Equal(t, TypeStr, cfg.Name()) | ||
assert.Equal(t, []string{"first", "second"}, cfg.Primary.Servers) | ||
assert.Equal(t, 9000, cfg.Primary.Port) | ||
assert.Equal(t, false, cfg.Index.Tags) | ||
assert.Equal(t, "my-keyspace", cfg.Primary.Keyspace) | ||
assert.Equal(t, false, cfg.Index.Tags) | ||
assert.Equal(t, true, cfg.Index.Logs) | ||
assert.Equal(t, "user", cfg.Primary.Authenticator.Basic.Username) | ||
assert.Equal(t, "pass", cfg.Primary.Authenticator.Basic.Password) | ||
assert.Equal(t, time.Second*12, cfg.SpanStoreWriteCacheTTL) | ||
assert.Equal(t, true, cfg.Primary.TLS.Enabled) | ||
assert.Equal(t, "/foo/bar", cfg.Primary.TLS.CAPath) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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 cassandra implements Jaeger Cassandra storage as OpenTelemetry exporter. | ||
package cassandra |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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 cassandra | ||
|
||
import ( | ||
"github.com/open-telemetry/opentelemetry-collector/exporter" | ||
"github.com/uber/jaeger-lib/metrics" | ||
"go.uber.org/zap" | ||
|
||
storageOtelExporter "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter" | ||
"github.com/jaegertracing/jaeger/plugin/storage/cassandra" | ||
) | ||
|
||
// New creates Cassandra exporter/storage | ||
func New(config *Config, log *zap.Logger) (exporter.TraceExporter, error) { | ||
f := cassandra.NewFactory() | ||
f.InitFromOptions(&config.Options) | ||
|
||
err := f.Initialize(metrics.NullFactory, log) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return storageOtelExporter.NewSpanWriterExporter(config, f) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// 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 cassandra | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector/config/configerror" | ||
"github.com/open-telemetry/opentelemetry-collector/config/configmodels" | ||
"github.com/open-telemetry/opentelemetry-collector/exporter" | ||
"go.uber.org/zap" | ||
|
||
"github.com/jaegertracing/jaeger/plugin/storage/cassandra" | ||
) | ||
|
||
const ( | ||
// TypeStr defines type of the Cassandra exporter. | ||
TypeStr = "jaeger_cassandra" | ||
) | ||
|
||
// OptionsFactory returns initialized cassandra.OptionsFactory structure. | ||
type OptionsFactory func() *cassandra.Options | ||
|
||
// DefaultOptions creates Cassandra options supported by this exporter. | ||
func DefaultOptions() *cassandra.Options { | ||
return cassandra.NewOptions("cassandra") | ||
} | ||
|
||
// Factory is the factory for Jaeger Cassandra exporter. | ||
type Factory struct { | ||
OptionsFactory OptionsFactory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in what scenarios does this need to be a function instead of a struct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to initialize the We can revisit this and instead pass a viper instance and run the initialization in |
||
} | ||
|
||
// Type gets the type of exporter. | ||
func (Factory) Type() string { | ||
return TypeStr | ||
} | ||
|
||
// CreateDefaultConfig returns default configuration of Factory. | ||
func (f Factory) CreateDefaultConfig() configmodels.Exporter { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the name CreateDefaultConfig required by some external API? We usually mention it in the comment. Given that the result of this function depends on externally provided (via OptionsFactory) options, the name "default" is confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
OTEL service applies config file changes to the returned instance. We cannot override them by config supplied as legacy jaeger flags. The OTEL config takes precedence over legacy jaeger configuration. |
||
opts := f.OptionsFactory() | ||
return &Config{ | ||
Options: *opts, | ||
ExporterSettings: configmodels.ExporterSettings{ | ||
TypeVal: TypeStr, | ||
NameVal: TypeStr, | ||
}, | ||
} | ||
} | ||
|
||
// CreateTraceExporter creates Jaeger Cassandra trace exporter. | ||
func (Factory) CreateTraceExporter(log *zap.Logger, cfg configmodels.Exporter) (exporter.TraceExporter, error) { | ||
config, ok := cfg.(*Config) | ||
if !ok { | ||
return nil, fmt.Errorf("could not cast configuration to %s", TypeStr) | ||
} | ||
return New(config, log) | ||
} | ||
|
||
// CreateMetricsExporter is not implemented. | ||
func (Factory) CreateMetricsExporter(*zap.Logger, configmodels.Exporter) (exporter.MetricsExporter, error) { | ||
return nil, configerror.ErrDataTypeIsNotSupported | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// 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 cassandra | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector/config/configcheck" | ||
"github.com/open-telemetry/opentelemetry-collector/config/configerror" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap" | ||
|
||
jConfig "github.com/jaegertracing/jaeger/pkg/config" | ||
"github.com/jaegertracing/jaeger/plugin/storage/cassandra" | ||
) | ||
|
||
func TestCreateTraceExporter(t *testing.T) { | ||
v, _ := jConfig.Viperize(DefaultOptions().AddFlags) | ||
opts := DefaultOptions() | ||
opts.InitFromViper(v) | ||
factory := Factory{OptionsFactory: func() *cassandra.Options { | ||
return opts | ||
}} | ||
exporter, err := factory.CreateTraceExporter(zap.NewNop(), factory.CreateDefaultConfig()) | ||
require.Nil(t, exporter) | ||
assert.EqualError(t, err, "gocql: unable to create session: control: unable to connect to initial hosts: dial tcp 127.0.0.1:9042: connect: connection refused") | ||
} | ||
|
||
func TestCreateTraceExporter_NilConfig(t *testing.T) { | ||
factory := Factory{} | ||
exporter, err := factory.CreateTraceExporter(zap.NewNop(), nil) | ||
require.Nil(t, exporter) | ||
assert.EqualError(t, err, "could not cast configuration to jaeger_cassandra") | ||
} | ||
|
||
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 TestCreateMetricsExporter(t *testing.T) { | ||
f := Factory{OptionsFactory: DefaultOptions} | ||
mReceiver, err := f.CreateMetricsExporter(zap.NewNop(), f.CreateDefaultConfig()) | ||
assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported) | ||
assert.Nil(t, mReceiver) | ||
} | ||
|
||
func TestType(t *testing.T) { | ||
factory := Factory{} | ||
assert.Equal(t, TypeStr, factory.Type()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
receivers: | ||
examplereceiver: | ||
|
||
processors: | ||
exampleprocessor: | ||
|
||
exporters: | ||
jaeger_cassandra: | ||
servers: "first,second" | ||
index: | ||
tags: false | ||
username: user | ||
password: pass | ||
span_store_write_cache_ttl: 12s | ||
tls: | ||
enabled: true | ||
ca: /foo/bar | ||
|
||
service: | ||
pipelines: | ||
traces: | ||
receivers: [examplereceiver] | ||
processors: [exampleprocessor] | ||
exporters: [jaeger_cassandra] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cassandra: | ||
keyspace: my-keyspace |
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.
No harm in testing again, but default values are tested in
cmd/opentelemetry-collector/app/exporter/cassandra/config_test.go
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.
Double-check that the default values have been applied. I will consider changing
defaults
interface to include cobra command and install Jaeger flags by default.