From f619fd6be36178f98954972398fd8319bbce51f5 Mon Sep 17 00:00:00 2001 From: VihasMakwana <121151420+VihasMakwana@users.noreply.github.com> Date: Wed, 1 Nov 2023 05:33:35 +0530 Subject: [PATCH] [encoding/zipkinencodingextension] add default case (#28689) **Description:** Fix bug when err is nil if an invalid version value is supplied. **Link to tracking Issue:** #28686 --------- Co-authored-by: Dmitrii Anoshin --- .chloggen/bugfix-zipkin-encoding.yaml | 27 +++++++++++++++++ .../zipkinencodingextension/extension.go | 6 ++-- .../zipkinencodingextension/extension_test.go | 30 +++++++++++++++++++ .../encoding/zipkinencodingextension/go.mod | 4 +++ .../encoding/zipkinencodingextension/go.sum | 4 +++ 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 .chloggen/bugfix-zipkin-encoding.yaml create mode 100644 extension/encoding/zipkinencodingextension/extension_test.go diff --git a/.chloggen/bugfix-zipkin-encoding.yaml b/.chloggen/bugfix-zipkin-encoding.yaml new file mode 100644 index 000000000000..195a7eeb7670 --- /dev/null +++ b/.chloggen/bugfix-zipkin-encoding.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: extension/zipkinencodingextension + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix bug when err is nil if invalid protocol value is supplied. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [28686] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/extension/encoding/zipkinencodingextension/extension.go b/extension/encoding/zipkinencodingextension/extension.go index 3fcb72ad8046..aa7a7f288b81 100644 --- a/extension/encoding/zipkinencodingextension/extension.go +++ b/extension/encoding/zipkinencodingextension/extension.go @@ -51,7 +51,7 @@ func newExtension(config *Config) (*zipkinExtension, error) { unmarshaler: zipkinv2.NewProtobufTracesUnmarshaler(false, false), } default: - err = fmt.Errorf("unsupported version: %q and protocol: %q", version, protocol) + err = fmt.Errorf("protocol: %q, unsupported version: %q", protocol, version) } case zipkinJSONEncoding: switch version { @@ -77,8 +77,10 @@ func newExtension(config *Config) (*zipkinExtension, error) { unmarshaler: zipkinv1.NewThriftTracesUnmarshaler(), } default: - err = fmt.Errorf("unsupported version: %q and protocol: %q", version, protocol) + err = fmt.Errorf("protocol: %q, unsupported version: %q", protocol, version) } + default: + err = fmt.Errorf("unsupported protocol: %q", protocol) } return ex, err diff --git a/extension/encoding/zipkinencodingextension/extension_test.go b/extension/encoding/zipkinencodingextension/extension_test.go new file mode 100644 index 000000000000..f4d258464b85 --- /dev/null +++ b/extension/encoding/zipkinencodingextension/extension_test.go @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package zipkinencodingextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/zipkinencodingextension" + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/extension/extensiontest" +) + +func TestExtension_Start(t *testing.T) { + j := &zipkinExtension{ + config: createDefaultConfig().(*Config), + } + err := j.Start(context.Background(), componenttest.NewNopHost()) + require.NoError(t, err) +} + +func TestExtension_Err(t *testing.T) { + factory := NewFactory() + cfg := createDefaultConfig().(*Config) + cfg.Protocol = "v3" + _, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg) + require.NotNil(t, err) + require.ErrorContains(t, err, "unsupported protocol: \"v3\"") +} diff --git a/extension/encoding/zipkinencodingextension/go.mod b/extension/encoding/zipkinencodingextension/go.mod index f00ecda41afd..36abaa83da2a 100644 --- a/extension/encoding/zipkinencodingextension/go.mod +++ b/extension/encoding/zipkinencodingextension/go.mod @@ -5,6 +5,7 @@ go 1.20 require ( github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding v0.0.0-00010101000000-000000000000 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin v0.88.0 + github.com/stretchr/testify v1.8.4 go.opentelemetry.io/collector/component v0.88.1-0.20231026220224-6405e152a2d9 go.opentelemetry.io/collector/extension v0.88.1-0.20231026220224-6405e152a2d9 go.opentelemetry.io/collector/pdata v1.0.0-rcv0017.0.20231026220224-6405e152a2d9 @@ -12,6 +13,7 @@ require ( require ( github.com/apache/thrift v0.19.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/jaegertracing/jaeger v1.48.0 // indirect @@ -27,6 +29,7 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.88.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/openzipkin/zipkin-go v0.4.2 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect github.com/uber/jaeger-lib v2.4.1+incompatible // indirect go.opentelemetry.io/collector/config/configtelemetry v0.88.1-0.20231026220224-6405e152a2d9 // indirect @@ -45,6 +48,7 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // 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 ) replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal => ../../../internal/coreinternal diff --git a/extension/encoding/zipkinencodingextension/go.sum b/extension/encoding/zipkinencodingextension/go.sum index eb99187c2e71..0b6e1ede20d0 100644 --- a/extension/encoding/zipkinencodingextension/go.sum +++ b/extension/encoding/zipkinencodingextension/go.sum @@ -50,6 +50,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaOOb6ThwMmTEbhRwtKR97o= github.com/uber/jaeger-client-go v2.30.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg= @@ -122,4 +123,7 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=