forked from open-telemetry/opentelemetry-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add factory and new-style config for Zipkin receiver
This is part of remaining migration to new configuration format. Github issue: open-telemetry#34 Testing done: make
- Loading branch information
Tigran Najaryan
committed
Jun 21, 2019
1 parent
08eae6f
commit edb568b
Showing
5 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 factory 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
|