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 coverage on otel/app/defaultconfig and otel/app/defaultcomponents #2515

Merged
merged 5 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
9 changes: 9 additions & 0 deletions cmd/opentelemetry/app/defaultcomponents/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ func TestComponents(t *testing.T) {
cassandraFactory := factories.Exporters[cassandraexporter.TypeStr]
cc := cassandraFactory.CreateDefaultConfig().(*cassandraexporter.Config)
assert.Equal(t, []string{"127.0.0.1"}, cc.Options.GetPrimary().Servers)

esFactory := factories.Exporters[elasticsearchexporter.TypeStr]
ec := esFactory.CreateDefaultConfig().(*elasticsearchexporter.Config)
assert.Equal(t, []string{"http://127.0.0.1:9200"}, ec.GetPrimary().Servers)

grpcFactory := factories.Exporters[grpcpluginexporter.TypeStr]
gc := grpcFactory.CreateDefaultConfig().(*grpcpluginexporter.Config)
assert.Equal(t, "", gc.Configuration.PluginBinary)

badgerFactory := factories.Exporters[badgerexporter.TypeStr]
bc := badgerFactory.CreateDefaultConfig().(*badgerexporter.Config)
assert.Equal(t, "", bc.GetPrimary().ValueDirectory)
}
57 changes: 56 additions & 1 deletion cmd/opentelemetry/app/defaultconfig/default_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
package defaultconfig

import (
"flag"
"fmt"
"sort"
"testing"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/service/builder"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/opentelemetry/app"
Expand All @@ -42,6 +45,7 @@ func TestService(t *testing.T) {
cfg ComponentSettings
err string
viperConfig map[string]interface{}
otelConfig string
}{
{
cfg: ComponentSettings{
Expand All @@ -59,6 +63,41 @@ func TestService(t *testing.T) {
},
},
},
{
cfg: ComponentSettings{
ComponentType: Collector,
StorageType: "badger",
},
service: configmodels.Service{
Extensions: []string{"health_check"},
Pipelines: configmodels.Pipelines{
"traces": &configmodels.Pipeline{
InputType: configmodels.TracesDataType,
Receivers: []string{"otlp", "jaeger"},
Processors: []string{"batch"},
Exporters: []string{"jaeger_badger"},
},
},
},
},
{
cfg: ComponentSettings{
ComponentType: Agent,
},
service: configmodels.Service{
Extensions: []string{"health_check"},
Pipelines: configmodels.Pipelines{
"traces": &configmodels.Pipeline{
Name: "traces",
InputType: configmodels.TracesDataType,
Receivers: []string{"otlp", "jaeger"},
Processors: []string{"batch", "queued_retry"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm qretry should not be there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

queued_retry is in here b/c of the missing testdata/addqueuedprocessor.yaml. See my recent push.

Exporters: []string{"jaeger"},
},
},
},
otelConfig: "testdata/addqueuedprocessor.yaml",
joe-elliott marked this conversation as resolved.
Show resolved Hide resolved
},
{
viperConfig: map[string]interface{}{"resource.attributes": "foo=bar"},
cfg: ComponentSettings{
Expand Down Expand Up @@ -136,16 +175,32 @@ func TestService(t *testing.T) {
},
err: "unknown storage type: floppy",
},
{
cfg: ComponentSettings{
ComponentType: Agent,
},
otelConfig: "testdata/doesntexist.yaml",
err: `error loading config file "testdata/doesntexist.yaml": open testdata/doesntexist.yaml: no such file or directory`,
},
}
for _, test := range tests {
t.Run(fmt.Sprintf("%v:%v", test.cfg.ComponentType, test.cfg.StorageType), func(t *testing.T) {
v, _ := jConfig.Viperize(app.AddComponentFlags)
for key, val := range test.viperConfig {
v.Set(key, val)
}

otelFlags := &flag.FlagSet{}
builder.Flags(otelFlags)
if test.otelConfig != "" {
otelFlags.Parse([]string{"-config=" + test.otelConfig})
joe-elliott marked this conversation as resolved.
Show resolved Hide resolved
}

factories := defaultcomponents.Components(v)
test.cfg.Factories = factories
cfg, err := test.cfg.createDefaultConfig()
createDefaultConfig := test.cfg.DefaultConfigFactory(v)

cfg, err := createDefaultConfig(viper.New(), factories)
if test.err != "" {
require.Nil(t, cfg)
assert.Contains(t, err.Error(), test.err)
Expand Down
7 changes: 1 addition & 6 deletions cmd/opentelemetry/app/defaultconfig/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,5 @@ func MergeConfigs(dst, src *configmodels.Config) error {
if src == nil {
return nil
}
err := mergo.Merge(dst, src,
mergo.WithOverride)
if err != nil {
return err
}
return nil
return mergo.Merge(dst, src, mergo.WithOverride)
}