-
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 Badger OTEL exporter #2269
Merged
Merged
Add Badger OTEL exporter #2269
Changes from all commits
Commits
Show all changes
4 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 badger | ||
|
||
import ( | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
|
||
"github.com/jaegertracing/jaeger/plugin/storage/badger" | ||
) | ||
|
||
// Config holds configuration of Jaeger Badger exporter/storage. | ||
type Config struct { | ||
badger.Options `mapstructure:",squash"` | ||
configmodels.ExporterSettings `mapstructure:",squash"` | ||
} |
77 changes: 77 additions & 0 deletions
77
cmd/opentelemetry-collector/app/exporter/badger/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,77 @@ | ||
// 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 badger | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/config" | ||
|
||
"github.com/jaegertracing/jaeger/cmd/flags" | ||
jConfig "github.com/jaegertracing/jaeger/pkg/config" | ||
"github.com/jaegertracing/jaeger/plugin/storage/badger" | ||
) | ||
|
||
func TestDefaultConfig(t *testing.T) { | ||
factory := NewFactory(func() *badger.Options { | ||
opts := DefaultOptions() | ||
v, _ := jConfig.Viperize(opts.AddFlags) | ||
opts.InitFromViper(v) | ||
return opts | ||
}) | ||
defaultCfg := factory.CreateDefaultConfig().(*Config) | ||
opts := defaultCfg.Options.GetPrimary() | ||
assert.Contains(t, opts.KeyDirectory, "/data/keys") | ||
assert.Contains(t, opts.ValueDirectory, "/data/values") | ||
assert.Equal(t, true, opts.Ephemeral) | ||
assert.Equal(t, false, opts.ReadOnly) | ||
assert.Equal(t, false, opts.SyncWrites) | ||
assert.Equal(t, false, opts.Truncate) | ||
assert.Equal(t, time.Second*10, opts.MetricsUpdateInterval) | ||
assert.Equal(t, time.Minute*5, opts.MaintenanceInterval) | ||
assert.Equal(t, time.Hour*72, opts.SpanStoreTTL) | ||
} | ||
|
||
func TestLoadConfigAndFlags(t *testing.T) { | ||
factories, err := config.ExampleComponents() | ||
require.NoError(t, err) | ||
|
||
v, c := jConfig.Viperize(DefaultOptions().AddFlags) | ||
err = c.ParseFlags([]string{"--badger.directory-key=bar"}) | ||
require.NoError(t, err) | ||
|
||
err = flags.TryLoadConfigFile(v) | ||
require.NoError(t, err) | ||
|
||
factory := NewFactory(func() *badger.Options { | ||
opts := DefaultOptions() | ||
opts.InitFromViper(v) | ||
require.Equal(t, "bar", opts.GetPrimary().KeyDirectory) | ||
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, "key", cfg.GetPrimary().KeyDirectory) | ||
} |
131 changes: 131 additions & 0 deletions
131
cmd/opentelemetry-collector/app/exporter/badger/factory.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,131 @@ | ||
// 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 badger | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"sync" | ||
|
||
"github.com/uber/jaeger-lib/metrics" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config/configerror" | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
|
||
"github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter" | ||
"github.com/jaegertracing/jaeger/plugin/storage/badger" | ||
"github.com/jaegertracing/jaeger/storage" | ||
) | ||
|
||
const ( | ||
// TypeStr defines type of the Badger exporter. | ||
TypeStr = "jaeger_badger" | ||
) | ||
|
||
// OptionsFactory returns initialized badger.Options structure. | ||
type OptionsFactory func() *badger.Options | ||
|
||
// DefaultOptions creates Badger options supported by this exporter. | ||
func DefaultOptions() *badger.Options { | ||
return badger.NewOptions("badger") | ||
} | ||
|
||
// Factory is the factory for Jaeger Cassandra exporter. | ||
type Factory struct { | ||
mutex *sync.Mutex | ||
optionsFactory OptionsFactory | ||
} | ||
|
||
// NewFactory creates new Factory instance. | ||
func NewFactory(optionsFactory OptionsFactory) *Factory { | ||
return &Factory{ | ||
optionsFactory: optionsFactory, | ||
mutex: &sync.Mutex{}, | ||
} | ||
} | ||
|
||
var _ component.ExporterFactory = (*Factory)(nil) | ||
|
||
// singleton instance of the factory | ||
// the badger exporter factory always returns this instance | ||
// the singleton instance is shared between OTEL collector and query service | ||
var instance storage.Factory | ||
|
||
// GetFactory returns singleton instance of the storage factory. | ||
func GetFactory() storage.Factory { | ||
return instance | ||
} | ||
|
||
// Type gets the type of exporter. | ||
func (f Factory) Type() configmodels.Type { | ||
return TypeStr | ||
} | ||
|
||
// CreateDefaultConfig returns default configuration of Factory. | ||
// This function implements OTEL component.ExporterFactoryBase interface. | ||
func (f Factory) CreateDefaultConfig() configmodels.Exporter { | ||
opts := f.optionsFactory() | ||
return &Config{ | ||
Options: *opts, | ||
ExporterSettings: configmodels.ExporterSettings{ | ||
TypeVal: TypeStr, | ||
NameVal: TypeStr, | ||
}, | ||
} | ||
} | ||
|
||
// CreateTraceExporter creates Jaeger Cassandra trace exporter. | ||
// This function implements OTEL component.ExporterFactory interface. | ||
func (f Factory) CreateTraceExporter( | ||
_ context.Context, | ||
params component.ExporterCreateParams, | ||
cfg configmodels.Exporter, | ||
) (component.TraceExporter, error) { | ||
factory, err := f.createStorageFactory(params, cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return exporter.NewSpanWriterExporter(cfg, factory) | ||
} | ||
|
||
// CreateMetricsExporter is not implemented. | ||
// This function implements OTEL component.ExporterFactory interface. | ||
func (f Factory) CreateMetricsExporter( | ||
_ context.Context, | ||
_ component.ExporterCreateParams, | ||
_ configmodels.Exporter, | ||
) (component.MetricsExporter, error) { | ||
return nil, configerror.ErrDataTypeIsNotSupported | ||
} | ||
|
||
func (f Factory) createStorageFactory(params component.ExporterCreateParams, cfg configmodels.Exporter) (storage.Factory, error) { | ||
config, ok := cfg.(*Config) | ||
if !ok { | ||
return nil, fmt.Errorf("could not cast configuration to %s", TypeStr) | ||
} | ||
f.mutex.Lock() | ||
if instance != nil { | ||
return instance, nil | ||
} | ||
factory := badger.NewFactory() | ||
factory.InitFromOptions(config.Options) | ||
err := factory.Initialize(metrics.NullFactory, params.Logger) | ||
if err != nil { | ||
return nil, err | ||
} | ||
instance = factory | ||
f.mutex.Unlock() | ||
return factory, nil | ||
} |
69 changes: 69 additions & 0 deletions
69
cmd/opentelemetry-collector/app/exporter/badger/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,69 @@ | ||
// 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 badger | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config/configcheck" | ||
"go.opentelemetry.io/collector/config/configerror" | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
"go.uber.org/zap" | ||
|
||
jConfig "github.com/jaegertracing/jaeger/pkg/config" | ||
"github.com/jaegertracing/jaeger/plugin/storage/badger" | ||
) | ||
|
||
func TestCreateTraceExporter(t *testing.T) { | ||
v, _ := jConfig.Viperize(DefaultOptions().AddFlags) | ||
opts := DefaultOptions() | ||
opts.InitFromViper(v) | ||
factory := NewFactory(func() *badger.Options { | ||
return opts | ||
}) | ||
exporter, err := factory.CreateTraceExporter(context.Background(), component.ExporterCreateParams{Logger: zap.NewNop()}, factory.CreateDefaultConfig()) | ||
require.NoError(t, err) | ||
assert.NotNil(t, exporter) | ||
} | ||
|
||
func TestCreateTraceExporter_NilConfig(t *testing.T) { | ||
factory := Factory{} | ||
exporter, err := factory.CreateTraceExporter(context.Background(), component.ExporterCreateParams{}, nil) | ||
require.Nil(t, exporter) | ||
assert.Contains(t, err.Error(), "could not cast configuration to jaeger_badger") | ||
} | ||
|
||
func TestCreateDefaultConfig(t *testing.T) { | ||
factory := NewFactory(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 := NewFactory(DefaultOptions) | ||
mReceiver, err := f.CreateMetricsExporter(context.Background(), component.ExporterCreateParams{}, f.CreateDefaultConfig()) | ||
assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported) | ||
assert.Nil(t, mReceiver) | ||
} | ||
|
||
func TestType(t *testing.T) { | ||
factory := Factory{} | ||
assert.Equal(t, configmodels.Type(TypeStr), factory.Type()) | ||
} |
17 changes: 17 additions & 0 deletions
17
cmd/opentelemetry-collector/app/exporter/badger/testdata/config.yaml
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,17 @@ | ||
receivers: | ||
examplereceiver: | ||
|
||
processors: | ||
exampleprocessor: | ||
|
||
exporters: | ||
jaeger_badger: | ||
ephemeral: false | ||
directory_key: key | ||
|
||
service: | ||
pipelines: | ||
traces: | ||
receivers: [examplereceiver] | ||
processors: [exampleprocessor] | ||
exporters: [jaeger_badger] |
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.
What about the
directory-key/value
defaults?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.
They change based on the executable dir. I have added
assert.contains
for their values.