Skip to content

Commit abfb145

Browse files
author
Paulo Janotti
authored
Merge pull request #12 from pjanotti/add-zipkin-scribe-receiver
Move Zipkin-Scribe from core to contrib
2 parents 1bfdb1a + e755455 commit abfb145

File tree

12 files changed

+1181
-2
lines changed

12 files changed

+1181
-2
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
EXPORTERS := $(wildcard exporter/*/.)
2+
RECEIVERS := $(wildcard receiver/*/.)
23

34
.DEFAULT_GOAL := all
45

5-
.PHONY: all $(EXPORTERS)
6-
all: $(EXPORTERS)
6+
.PHONY: all $(EXPORTERS) $(RECEIVERS)
7+
all: $(EXPORTERS) $(RECEIVERS)
78
$(EXPORTERS):
89
$(MAKE) -C $@
10+
$(RECEIVERS):
11+
$(MAKE) -C $@
912

1013
.PHONY: install-tools
1114
install-tools:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../../Makefile.Common
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2019, OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package zipkinscribereceiver
16+
17+
import "github.com/open-telemetry/opentelemetry-service/config/configmodels"
18+
19+
// Config defines configuration for Zipkin-Scribe receiver.
20+
type Config struct {
21+
configmodels.ReceiverSettings `mapstructure:",squash"`
22+
23+
// Category is the string that will be used to identify the scribe log
24+
// messages that contain Zipkin spans.
25+
Category string `mapstructure:"category"`
26+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2019, OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package zipkinscribereceiver
16+
17+
import (
18+
"path"
19+
"testing"
20+
21+
"github.com/stretchr/testify/assert"
22+
"github.com/stretchr/testify/require"
23+
24+
"github.com/open-telemetry/opentelemetry-service/config"
25+
"github.com/open-telemetry/opentelemetry-service/config/configmodels"
26+
)
27+
28+
func TestLoadConfig(t *testing.T) {
29+
receivers, processors, exporters, err := config.ExampleComponents()
30+
assert.Nil(t, err)
31+
32+
factory := &Factory{}
33+
receivers[typeStr] = factory
34+
cfg, err := config.LoadConfigFile(
35+
t, path.Join(".", "testdata", "config.yaml"), receivers, processors, exporters,
36+
)
37+
38+
require.NoError(t, err)
39+
require.NotNil(t, cfg)
40+
41+
assert.Equal(t, len(cfg.Receivers), 2)
42+
43+
r0 := cfg.Receivers["zipkin-scribe"]
44+
assert.Equal(t, r0, factory.CreateDefaultConfig())
45+
46+
r1 := cfg.Receivers["zipkin-scribe/category"].(*Config)
47+
assert.Equal(t, r1,
48+
&Config{
49+
ReceiverSettings: configmodels.ReceiverSettings{
50+
TypeVal: typeStr,
51+
NameVal: "zipkin-scribe/category",
52+
Endpoint: "127.0.0.1:12345",
53+
},
54+
Category: "test-category",
55+
})
56+
}

receiver/zipkinscribereceiver/doc.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2019, OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package zipkinscribereceiver implements a receiver that can be used by the
16+
// OpenTelemetry service to receive traces in the Zipkin-Scribe format.
17+
package zipkinscribereceiver
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright 2019, OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package zipkinscribereceiver
16+
17+
import (
18+
"context"
19+
20+
"go.uber.org/zap"
21+
22+
"github.com/open-telemetry/opentelemetry-service/config/configerror"
23+
"github.com/open-telemetry/opentelemetry-service/config/configmodels"
24+
"github.com/open-telemetry/opentelemetry-service/consumer"
25+
"github.com/open-telemetry/opentelemetry-service/receiver"
26+
)
27+
28+
// This file implements factory for Zipkin-Scribe receiver.
29+
30+
const (
31+
// The value of "type" key in configuration.
32+
typeStr = "zipkin-scribe"
33+
34+
defaultBindEndpoint = "127.0.0.1:9410"
35+
36+
defaultCategory = "zipkin"
37+
)
38+
39+
// Factory is the factory for Zipkin-Scribe receiver.
40+
type Factory struct {
41+
}
42+
43+
// Type gets the type of the Receiver config created by this factory.
44+
func (f *Factory) Type() string {
45+
return typeStr
46+
}
47+
48+
// CustomUnmarshaler returns nil because we don't need custom unmarshaling for this config.
49+
func (f *Factory) CustomUnmarshaler() receiver.CustomUnmarshaler {
50+
return nil
51+
}
52+
53+
// CreateDefaultConfig creates the default configuration for Jaeger receiver.
54+
func (f *Factory) CreateDefaultConfig() configmodels.Receiver {
55+
return &Config{
56+
ReceiverSettings: configmodels.ReceiverSettings{
57+
TypeVal: typeStr,
58+
NameVal: typeStr,
59+
Endpoint: defaultBindEndpoint,
60+
},
61+
Category: defaultCategory,
62+
}
63+
}
64+
65+
// CreateTraceReceiver creates a trace receiver based on provided config.
66+
func (f *Factory) CreateTraceReceiver(
67+
ctx context.Context,
68+
logger *zap.Logger,
69+
cfg configmodels.Receiver,
70+
nextConsumer consumer.TraceConsumer,
71+
) (receiver.TraceReceiver, error) {
72+
73+
rCfg := cfg.(*Config)
74+
return New(rCfg.Endpoint, rCfg.Category, nextConsumer)
75+
}
76+
77+
// CreateMetricsReceiver creates a metrics receiver based on provided config.
78+
func (f *Factory) CreateMetricsReceiver(
79+
logger *zap.Logger,
80+
cfg configmodels.Receiver,
81+
consumer consumer.MetricsConsumer,
82+
) (receiver.MetricsReceiver, error) {
83+
return nil, configerror.ErrDataTypeIsNotSupported
84+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2019, OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package zipkinscribereceiver
16+
17+
import (
18+
"context"
19+
"testing"
20+
21+
"go.uber.org/zap"
22+
23+
"github.com/stretchr/testify/assert"
24+
25+
"github.com/open-telemetry/opentelemetry-service/config/configerror"
26+
"github.com/open-telemetry/opentelemetry-service/consumer/consumerdata"
27+
)
28+
29+
func TestCreateDefaultConfig(t *testing.T) {
30+
factory := &Factory{}
31+
cfg := factory.CreateDefaultConfig()
32+
assert.NotNil(t, cfg, "failed to create default config")
33+
}
34+
35+
type mockTraceConsumer struct {
36+
}
37+
38+
func (m *mockTraceConsumer) ConsumeTraceData(ctx context.Context, td consumerdata.TraceData) error {
39+
return nil
40+
}
41+
42+
func TestCreateReceiver(t *testing.T) {
43+
factory := &Factory{}
44+
cfg := factory.CreateDefaultConfig()
45+
46+
tReceiver, err := factory.CreateTraceReceiver(context.Background(), zap.NewNop(), cfg, &mockTraceConsumer{})
47+
assert.Nil(t, err, "receiver creation failed")
48+
assert.NotNil(t, tReceiver, "receiver creation failed")
49+
50+
tReceiver, err = factory.CreateTraceReceiver(context.Background(), zap.NewNop(), cfg, &mockTraceConsumer{})
51+
assert.Nil(t, err, "receiver creation failed")
52+
assert.NotNil(t, tReceiver, "receiver creation failed")
53+
54+
mReceiver, err := factory.CreateMetricsReceiver(zap.NewNop(), cfg, nil)
55+
assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported)
56+
assert.Nil(t, mReceiver)
57+
}

receiver/zipkinscribereceiver/go.mod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module github.com/open-telemetry/opentelemetry-service-contrib/receiver/zipkinscribereceiver
2+
3+
go 1.12
4+
5+
require (
6+
github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7
7+
github.com/census-instrumentation/opencensus-proto v0.2.1
8+
github.com/golang/protobuf v1.3.2
9+
github.com/jaegertracing/jaeger v1.9.0
10+
github.com/omnition/scribe-go v1.0.0
11+
github.com/open-telemetry/opentelemetry-service v0.0.1
12+
github.com/stretchr/testify v1.3.0
13+
go.uber.org/zap v1.10.0
14+
)

0 commit comments

Comments
 (0)