Skip to content

Commit

Permalink
Increase coverage on otel/app/defaultconfig and otel/app/defaultcompo…
Browse files Browse the repository at this point in the history
…nents (#2515)

* Added grpc and badger tests

Signed-off-by: Joe Elliott <number101010@gmail.com>

* Added test case and refactor merge to increase coverage

Signed-off-by: Joe Elliott <number101010@gmail.com>

* Added otel config capability and increased test coverage

Signed-off-by: Joe Elliott <number101010@gmail.com>

* Added missing config file

Signed-off-by: Joe Elliott <number101010@gmail.com>

* Added second dash

Signed-off-by: Joe Elliott <number101010@gmail.com>
  • Loading branch information
joe-elliott committed Sep 29, 2020
1 parent 55d1913 commit 5cd7e0a
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
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"},
Exporters: []string{"jaeger"},
},
},
},
otelConfig: "testdata/addqueuedprocessor.yaml",
},
{
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})
}

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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
processors:
queued_retry:

service:
pipelines:
traces:
processors: [batch, queued_retry]

0 comments on commit 5cd7e0a

Please sign in to comment.