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

[chore][extension/encoding] add test cases covering encoding extension #28683

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ extensions:
import: github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/filestorage
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage v0.91.0
import: github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/dbstorage
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/otlpencodingextension v0.91.0
import: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/otlpencodingextension
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jaegerencodingextension v0.91.0
import: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jaegerencodingextension
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension v0.91.0
import: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension v0.91.0
import: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/zipkinencodingextension v0.91.0
import: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/zipkinencodingextension

exporters:
- gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.91.0
Expand Down Expand Up @@ -428,6 +438,12 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure => ../../pkg/translator/azure
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/skywalking => ../../pkg/translator/skywalking
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/collectd => ../../internal/collectd
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding => ../../extension/encoding
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/otlpencodingextension => ../../extension/encoding/otlpencodingextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/zipkinencodingextension => ../../extension/encoding/zipkinencodingextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension => ../../extension/encoding/jsonlogencodingextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension => ../../extension/encoding/textencodingextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jaegerencodingextension => ../../extension/encoding/jaegerencodingextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/remotetapextension => ../../extension/remotetapextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampextension => ../../extension/opampextension
- github.com/open-telemetry/opentelemetry-collector-contrib/testbed/mockdatasenders/mockdatadogagentexporter => ../../testbed/mockdatasenders/mockdatadogagentexporter
Expand Down
10 changes: 10 additions & 0 deletions cmd/otelcontribcol/components.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions cmd/otelcontribcol/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,21 @@ func TestDefaultExtensions(t *testing.T) {
return extFactories["jaegerremotesampling"].CreateDefaultConfig().(*jaegerremotesampling.Config)
},
},
{
extension: "otlp_encoding",
},
{
extension: "text_encoding",
},
{
extension: "jaeger_encoding",
},
{
extension: "json_log_encoding",
},
{
extension: "zipkin_encoding",
},
{
extension: "remotetap",
getConfigFn: func() component.Config {
Expand Down
18 changes: 18 additions & 0 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/extension/awsproxy v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/basicauthextension v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/bearertokenauthextension v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jaegerencodingextension v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/otlpencodingextension v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/zipkinencodingextension v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/headerssetterextension v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension v0.91.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/httpforwarder v0.91.0
Expand Down Expand Up @@ -524,6 +529,7 @@ require (
github.com/nginxinc/nginx-prometheus-exporter v0.8.1-0.20201110005315-f5a5f8086c19 // indirect
github.com/oklog/ulid/v2 v2.1.0 // indirect
github.com/open-telemetry/opamp-go v0.10.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding v0.91.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer v0.91.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil v0.91.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight v0.91.0 // indirect
Expand Down Expand Up @@ -1163,6 +1169,18 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/collectd => ../../internal/collectd

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding => ../../extension/encoding

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/otlpencodingextension => ../../extension/encoding/otlpencodingextension

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/zipkinencodingextension => ../../extension/encoding/zipkinencodingextension

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension => ../../extension/encoding/jsonlogencodingextension

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension => ../../extension/encoding/textencodingextension

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jaegerencodingextension => ../../extension/encoding/jaegerencodingextension

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/remotetapextension => ../../extension/remotetapextension

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampextension => ../../extension/opampextension
Expand Down
6 changes: 4 additions & 2 deletions extension/encoding/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
Expand All @@ -20,6 +21,7 @@ require (
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
go.opentelemetry.io/collector/component v0.91.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.91.0 // indirect
go.opentelemetry.io/collector/confmap v0.91.0 // indirect
Expand All @@ -30,9 +32,9 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
14 changes: 8 additions & 6 deletions extension/encoding/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 40 additions & 4 deletions extension/encoding/jaegerencodingextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,48 @@ import (

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/extension/extensiontest"
)

func TestExtension_Start(t *testing.T) {
j := &jaegerExtension{
config: createDefaultConfig().(*Config),
tests := []struct {
name string
getExtension func() (extension.Extension, error)
expectedErr string
}{
{
name: "jaegerProtobuf",
getExtension: func() (extension.Extension, error) {
factory := NewFactory()
return factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), factory.CreateDefaultConfig())
},
},
{
name: "jaeger_invalid",
getExtension: func() (extension.Extension, error) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
cfg.(*Config).Protocol = "xyz"
return factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg)
},
expectedErr: "unsupported protocol: \"xyz\"",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ext, err := test.getExtension()
if test.expectedErr != "" && err != nil {
require.ErrorContains(t, err, test.expectedErr)
} else {
require.NoError(t, err)
}
err = ext.Start(context.Background(), componenttest.NewNopHost())
if test.expectedErr != "" && err != nil {
require.ErrorContains(t, err, test.expectedErr)
} else {
require.NoError(t, err)
}
})
}
err := j.Start(context.Background(), componenttest.NewNopHost())
require.NoError(t, err)
}
8 changes: 4 additions & 4 deletions extension/encoding/jsonlogencodingextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
Expand All @@ -24,7 +24,7 @@ require (
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.91.0 // indirect
go.opentelemetry.io/collector/confmap v0.91.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.0 // indirect
Expand All @@ -34,9 +34,9 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading