diff --git a/go.mod b/go.mod index eab340841a2..4c2c1c24a35 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.8.5 github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/jaegertracing/jaeger v1.9.0 + github.com/mitchellh/mapstructure v1.1.2 // indirect github.com/omnition/scribe-go v0.0.0-20190131012523-9e3c68f31124 github.com/opentracing/opentracing-go v1.1.0 // indirect github.com/openzipkin/zipkin-go v0.1.6 @@ -34,6 +35,7 @@ require ( github.com/spf13/cobra v0.0.3 github.com/spf13/viper v1.2.1 github.com/streadway/quantile v0.0.0-20150917103942-b0c588724d25 // indirect + github.com/stretchr/objx v0.1.1 // indirect github.com/stretchr/testify v1.3.0 github.com/uber-go/atomic v1.3.2 // indirect github.com/uber/jaeger-client-go v2.16.0+incompatible // indirect diff --git a/go.sum b/go.sum index c4cdcd9ea18..cb43eec48f8 100644 --- a/go.sum +++ b/go.sum @@ -215,6 +215,8 @@ github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdI github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/mapstructure v1.0.0 h1:vVpGvMXJPqSDh2VYHF7gsfQj8Ncx+Xw5Y1KHeTRY+7I= github.com/mitchellh/mapstructure v1.0.0/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -324,6 +326,8 @@ github.com/streadway/quantile v0.0.0-20150917103942-b0c588724d25 h1:7z3LSn867ex6 github.com/streadway/quantile v0.0.0-20150917103942-b0c588724d25/go.mod h1:lbP8tGiBjZ5YWIc2fzuRpTaz0b/53vT6PEs3QuAWzuU= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/receiver/zipkinreceiver/config.go b/receiver/zipkinreceiver/config.go new file mode 100644 index 00000000000..f31305a0a2b --- /dev/null +++ b/receiver/zipkinreceiver/config.go @@ -0,0 +1,22 @@ +// Copyright 2019, OpenCensus 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 zipkinreceiver + +import "github.com/open-telemetry/opentelemetry-service/internal/configmodels" + +// ConfigV2 defines configuration for Zipkin receiver. +type ConfigV2 struct { + configmodels.ReceiverSettings `mapstructure:",squash"` +} diff --git a/receiver/zipkinreceiver/config_test.go b/receiver/zipkinreceiver/config_test.go new file mode 100644 index 00000000000..7136262a6d8 --- /dev/null +++ b/receiver/zipkinreceiver/config_test.go @@ -0,0 +1,54 @@ +// Copyright 2019, OpenCensus 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 zipkinreceiver + +import ( + "path" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/open-telemetry/opentelemetry-service/internal/configmodels" + "github.com/open-telemetry/opentelemetry-service/internal/configv2" + "github.com/open-telemetry/opentelemetry-service/internal/factories" +) + +var _ = configv2.RegisterTestFactories() + +func TestLoadConfig(t *testing.T) { + factory := factories.GetReceiverFactory(typeStr) + + config, err := configv2.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml")) + + require.NoError(t, err) + require.NotNil(t, config) + + assert.Equal(t, len(config.Receivers), 2) + + r0 := config.Receivers["zipkin"] + assert.Equal(t, r0, factory.CreateDefaultConfig()) + + r1 := config.Receivers["zipkin/customname"].(*ConfigV2) + assert.Equal(t, r1, + &ConfigV2{ + ReceiverSettings: configmodels.ReceiverSettings{ + TypeVal: typeStr, + NameVal: "zipkin/customname", + Endpoint: "127.0.0.1:8765", + Enabled: true, + }, + }) +} diff --git a/receiver/zipkinreceiver/factory.go b/receiver/zipkinreceiver/factory.go new file mode 100644 index 00000000000..2406245bea5 --- /dev/null +++ b/receiver/zipkinreceiver/factory.go @@ -0,0 +1,79 @@ +// Copyright 2019, OpenCensus 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 zipkinreceiver + +import ( + "context" + + "github.com/open-telemetry/opentelemetry-service/consumer" + "github.com/open-telemetry/opentelemetry-service/internal/configmodels" + "github.com/open-telemetry/opentelemetry-service/internal/factories" + "github.com/open-telemetry/opentelemetry-service/receiver" +) + +// This file implements config V2 for Zipkin receiver. + +var _ = factories.RegisterReceiverFactory(&ReceiverFactory{}) + +const ( + // The value of "type" key in configuration. + typeStr = "zipkin" + + defaultBindEndpoint = "127.0.0.1:9411" +) + +// ReceiverFactory is the factory for Zipkin receiver. +type ReceiverFactory struct { +} + +// Type gets the type of the Receiver config created by this factory. +func (f *ReceiverFactory) Type() string { + return typeStr +} + +// CustomUnmarshaler returns nil because we don't need custom unmarshaling for this config. +func (f *ReceiverFactory) CustomUnmarshaler() factories.CustomUnmarshaler { + return nil +} + +// CreateDefaultConfig creates the default configuration for Jaeger receiver. +func (f *ReceiverFactory) CreateDefaultConfig() configmodels.Receiver { + return &ConfigV2{ + ReceiverSettings: configmodels.ReceiverSettings{ + TypeVal: typeStr, + NameVal: typeStr, + Endpoint: defaultBindEndpoint, + }, + } +} + +// CreateTraceReceiver creates a trace receiver based on provided config. +func (f *ReceiverFactory) CreateTraceReceiver( + ctx context.Context, + cfg configmodels.Receiver, + nextConsumer consumer.TraceConsumer, +) (receiver.TraceReceiver, error) { + + rCfg := cfg.(*ConfigV2) + return New(rCfg.Endpoint, nextConsumer) +} + +// CreateMetricsReceiver creates a metrics receiver based on provided config. +func (f *ReceiverFactory) CreateMetricsReceiver( + cfg configmodels.Receiver, + consumer consumer.MetricsConsumer, +) (receiver.MetricsReceiver, error) { + return nil, factories.ErrDataTypeIsNotSupported +} diff --git a/receiver/zipkinreceiver/factory_test.go b/receiver/zipkinreceiver/factory_test.go new file mode 100644 index 00000000000..37aabce9f85 --- /dev/null +++ b/receiver/zipkinreceiver/factory_test.go @@ -0,0 +1,49 @@ +// Copyright 2019, OpenCensus 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 zipkinreceiver + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/open-telemetry/opentelemetry-service/data" + "github.com/open-telemetry/opentelemetry-service/internal/factories" +) + +func TestCreateDefaultConfig(t *testing.T) { + factory := factories.GetReceiverFactory(typeStr) + cfg := factory.CreateDefaultConfig() + assert.NotNil(t, cfg, "failed to create default config") +} + +type mockTraceConsumer struct { +} + +func (m *mockTraceConsumer) ConsumeTraceData(ctx context.Context, td data.TraceData) error { return nil } + +func TestCreateReceiver(t *testing.T) { + factory := factories.GetReceiverFactory(typeStr) + cfg := factory.CreateDefaultConfig() + + tReceiver, err := factory.CreateTraceReceiver(context.Background(), cfg, &mockTraceConsumer{}) + assert.Nil(t, err, "receiver creation failed") + assert.NotNil(t, tReceiver, "receiver creation failed") + + mReceiver, err := factory.CreateMetricsReceiver(cfg, nil) + assert.Equal(t, err, factories.ErrDataTypeIsNotSupported) + assert.Nil(t, mReceiver) +} diff --git a/receiver/zipkinreceiver/testdata/config.yaml b/receiver/zipkinreceiver/testdata/config.yaml new file mode 100644 index 00000000000..bf6e7af9c88 --- /dev/null +++ b/receiver/zipkinreceiver/testdata/config.yaml @@ -0,0 +1,18 @@ +receivers: + zipkin: + zipkin/customname: + endpoint: "127.0.0.1:8765" + enabled: true + +processors: + exampleprocessor: + +exporters: + exampleexporter: + +pipelines: + traces: + receivers: [zipkin] + processors: [exampleprocessor] + exporters: [exampleexporter] +