Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit f34bc81

Browse files
author
Paulo Janotti
authored
Add support to zipkin scribe (#359)
Add a "zipkin-scribe" receiver to handle zipkin v1 thrift spans sent via the scribe protocol.
1 parent d17cdd6 commit f34bc81

14 files changed

Lines changed: 662 additions & 18 deletions

File tree

cmd/ocagent/main.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"github.com/census-instrumentation/opencensus-service/receiver/jaeger"
4040
"github.com/census-instrumentation/opencensus-service/receiver/opencensus"
4141
"github.com/census-instrumentation/opencensus-service/receiver/zipkin"
42+
"github.com/census-instrumentation/opencensus-service/receiver/zipkin/scribe"
4243
)
4344

4445
var configYAMLFile string
@@ -117,6 +118,14 @@ func runOCAgent() {
117118
closeFns = append(closeFns, zipkinReceiverDoneFn)
118119
}
119120

121+
if agentConfig.ZipkinScribeReceiverEnabled() {
122+
zipkinScribeDoneFn, err := runZipkinScribeReceiver(agentConfig.ZipkinScribeConfig(), commonSpanSink)
123+
if err != nil {
124+
log.Fatal(err)
125+
}
126+
closeFns = append(closeFns, zipkinScribeDoneFn)
127+
}
128+
120129
if agentConfig.JaegerReceiverEnabled() {
121130
collectorHTTPPort, collectorThriftPort := agentConfig.JaegerReceiverPorts()
122131
jaegerDoneFn, err := runJaegerReceiver(collectorThriftPort, collectorHTTPPort, commonSpanSink)
@@ -243,3 +252,19 @@ func runZipkinReceiver(addr string, sr receiver.TraceReceiverSink) (doneFn func(
243252
log.Printf("Running Zipkin receiver with address %q", addr)
244253
return doneFn, nil
245254
}
255+
256+
func runZipkinScribeReceiver(config *config.ScribeReceiverConfig, sr receiver.TraceReceiverSink) (doneFn func() error, err error) {
257+
zs, err := scribe.NewReceiver(config.Address, config.Port, config.Category)
258+
if err != nil {
259+
return nil, fmt.Errorf("Failed to create the Zipkin Scribe receiver: %v", err)
260+
}
261+
262+
if err := zs.StartTraceReception(context.Background(), sr); err != nil {
263+
return nil, fmt.Errorf("Cannot start Zipkin Scribe receiver with %v: %v", config, err)
264+
}
265+
doneFn = func() error {
266+
return zs.StopTraceReception(context.Background())
267+
}
268+
log.Printf("Running Zipkin Scribe receiver with %+v", *config)
269+
return doneFn, nil
270+
}

cmd/occollector/app/builder/builder.go

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@ import (
2323
)
2424

2525
const (
26-
receiversRoot = "receivers"
27-
jaegerEntry = "jaeger"
28-
opencensusEntry = "opencensus"
29-
zipkinEntry = "zipkin"
26+
receiversRoot = "receivers"
27+
jaegerEntry = "jaeger"
28+
opencensusEntry = "opencensus"
29+
zipkinEntry = "zipkin"
30+
zipkinScribeEntry = "zipkin-scribe"
3031

3132
// flags
32-
configCfg = "config"
33-
jaegerReceiverFlg = "receive-jaeger"
34-
ocReceiverFlg = "receive-oc-trace"
35-
zipkinReceiverFlg = "receive-zipkin"
36-
debugProcessorFlg = "debug-processor"
33+
configCfg = "config"
34+
jaegerReceiverFlg = "receive-jaeger"
35+
ocReceiverFlg = "receive-oc-trace"
36+
zipkinReceiverFlg = "receive-zipkin"
37+
zipkinScribeReceiverFlg = "receive-zipkin-scribe"
38+
debugProcessorFlg = "debug-processor"
3739
)
3840

3941
// Flags adds flags related to basic building of the collector application to the given flagset.
@@ -45,6 +47,8 @@ func Flags(flags *flag.FlagSet) {
4547
fmt.Sprintf("Flag to run the OpenCensus trace receiver, default settings: %+v", *NewDefaultOpenCensusReceiverCfg()))
4648
flags.Bool(zipkinReceiverFlg, false,
4749
fmt.Sprintf("Flag to run the Zipkin receiver, default settings: %+v", *NewDefaultZipkinReceiverCfg()))
50+
flags.Bool(zipkinScribeReceiverFlg, false,
51+
fmt.Sprintf("Flag to run the Zipkin Scribe receiver, default settings: %+v", *NewDefaultZipkinScribeReceiverCfg()))
4852
flags.Bool(debugProcessorFlg, false, "Flag to add a debug processor (combine with log level DEBUG to log incoming spans)")
4953
}
5054

@@ -136,6 +140,41 @@ func (cfg *ZipkinReceiverCfg) InitFromViper(v *viper.Viper) (*ZipkinReceiverCfg,
136140
return cfg, initFromViper(cfg, v, receiversRoot, zipkinEntry)
137141
}
138142

143+
// ScribeReceiverCfg carries the settings for the Zipkin Scribe receiver.
144+
type ScribeReceiverCfg struct {
145+
// Address is an IP address or a name that can be resolved to a local address.
146+
//
147+
// It can use a name, but this is not recommended, because it will create
148+
// a listener for at most one of the host's IP addresses.
149+
//
150+
// The default value bind to all available interfaces on the local computer.
151+
Address string `mapstructure:"address"`
152+
Port uint16 `mapstructure:"port"`
153+
// Category is the string that will be used to identify the scribe log messages
154+
// that contain Zipkin spans.
155+
Category string `mapstructure:"category"`
156+
}
157+
158+
// ZipkinScribeReceiverEnabled checks if the Zipkin Scribe receiver is enabled, via a command-line flag, environment
159+
// variable, or configuration file.
160+
func ZipkinScribeReceiverEnabled(v *viper.Viper) bool {
161+
return featureEnabled(v, zipkinScribeReceiverFlg, receiversRoot, zipkinScribeEntry)
162+
}
163+
164+
// NewDefaultZipkinScribeReceiverCfg returns an instance of config.ScribeReceiverConfig with default values.
165+
func NewDefaultZipkinScribeReceiverCfg() *ScribeReceiverCfg {
166+
opts := &ScribeReceiverCfg{
167+
Port: 9410,
168+
Category: "zipkin",
169+
}
170+
return opts
171+
}
172+
173+
// InitFromViper returns a ScribeReceiverCfg according to the configuration.
174+
func (cfg *ScribeReceiverCfg) InitFromViper(v *viper.Viper) (*ScribeReceiverCfg, error) {
175+
return cfg, initFromViper(cfg, v, receiversRoot, zipkinEntry)
176+
}
177+
139178
// Helper functions
140179

141180
func initFromViper(cfg interface{}, v *viper.Viper, labels ...string) error {

cmd/occollector/app/builder/builder_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ func TestReceiversEnabledByPresenceWithDefaultSettings(t *testing.T) {
2828
t.Fatalf("Failed to load viper from test file: %v", err)
2929
}
3030

31-
jaegerEnabled, opencensusEnabled, zipkinEnabled := JaegerReceiverEnabled(v), OpenCensusReceiverEnabled(v), ZipkinReceiverEnabled(v)
32-
if !jaegerEnabled || !opencensusEnabled || !zipkinEnabled {
33-
t.Fatalf("Some of the expected receivers were not enabled j:%v oc:%v z:%v", jaegerEnabled, opencensusEnabled, zipkinEnabled)
31+
jaegerEnabled, opencensusEnabled, zipkinEnabled, scribeEnabled :=
32+
JaegerReceiverEnabled(v), OpenCensusReceiverEnabled(v), ZipkinReceiverEnabled(v), ZipkinScribeReceiverEnabled(v)
33+
if !jaegerEnabled || !opencensusEnabled || !zipkinEnabled || !scribeEnabled {
34+
t.Fatalf("Some of the expected receivers were not enabled j:%v oc:%v z:%v scribe:%v", jaegerEnabled, opencensusEnabled, zipkinEnabled, scribeEnabled)
3435
}
3536

3637
wj := NewDefaultJaegerReceiverCfg()
@@ -56,6 +57,14 @@ func TestReceiversEnabledByPresenceWithDefaultSettings(t *testing.T) {
5657
} else if !reflect.DeepEqual(wz, gz) {
5758
t.Errorf("Incorrect config for Zipkin receiver, want %v got %v", wz, gz)
5859
}
60+
61+
wscrb := NewDefaultZipkinScribeReceiverCfg()
62+
gscrb, err := wscrb.InitFromViper(v)
63+
if err != nil {
64+
t.Errorf("Failed to InitFromViper for Zipkin Scribe receiver: %v", err)
65+
} else if !reflect.DeepEqual(wscrb, gscrb) {
66+
t.Errorf("Incorrect config for Zipkin Scribe receiver, want %v got %v", wscrb, gscrb)
67+
}
5968
}
6069

6170
func TestReceiversDisabledByPresenceWithDefaultSettings(t *testing.T) {
@@ -64,9 +73,10 @@ func TestReceiversDisabledByPresenceWithDefaultSettings(t *testing.T) {
6473
t.Fatalf("Failed to load viper from test file: %v", err)
6574
}
6675

67-
jaegerEnabled, opencensusEnabled, zipkinEnabled := JaegerReceiverEnabled(v), OpenCensusReceiverEnabled(v), ZipkinReceiverEnabled(v)
76+
jaegerEnabled, opencensusEnabled, zipkinEnabled, scribeEnabled :=
77+
JaegerReceiverEnabled(v), OpenCensusReceiverEnabled(v), ZipkinReceiverEnabled(v), ZipkinScribeReceiverEnabled(v)
6878
if jaegerEnabled || opencensusEnabled || zipkinEnabled {
69-
t.Fatalf("Not all receivers were disabled j:%v oc:%v z:%v", jaegerEnabled, opencensusEnabled, zipkinEnabled)
79+
t.Fatalf("Not all receivers were disabled j:%v oc:%v z:%v scribe:%v", jaegerEnabled, opencensusEnabled, zipkinEnabled, scribeEnabled)
7080
}
7181
}
7282

cmd/occollector/app/builder/testdata/receivers_disabled.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ receivers:
33
# jaeger: {}
44
# opencensus: {}
55
# zipkin: {}
6+
# zipkin-scribe: {}

cmd/occollector/app/builder/testdata/receivers_enabled.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ receivers:
33
jaeger: {}
44
opencensus: {}
55
zipkin: {}
6+
zipkin-scribe: {}

cmd/occollector/app/collector/receivers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/census-instrumentation/opencensus-service/internal/collector/opencensus"
2727
"github.com/census-instrumentation/opencensus-service/internal/collector/processor"
2828
"github.com/census-instrumentation/opencensus-service/internal/collector/zipkin"
29+
"github.com/census-instrumentation/opencensus-service/internal/collector/zipkin/scribe"
2930
"github.com/census-instrumentation/opencensus-service/receiver"
3031
)
3132

@@ -39,6 +40,7 @@ func createReceivers(v *viper.Viper, logger *zap.Logger, spanProcessor processor
3940
{"Jaeger", jaegerreceiver.Start, builder.JaegerReceiverEnabled(v)},
4041
{"OpenCensus", ocreceiver.Start, builder.OpenCensusReceiverEnabled(v)},
4142
{"Zipkin", zipkinreceiver.Start, builder.ZipkinReceiverEnabled(v)},
43+
{"Zipkin-Scribe", zipkinscribereceiver.Start, builder.ZipkinScribeReceiverEnabled(v)},
4244
}
4345

4446
var startedTraceReceivers []receiver.TraceReceiver

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require (
44
cloud.google.com/go v0.32.0 // indirect
55
contrib.go.opencensus.io/exporter/ocagent v0.4.3
66
contrib.go.opencensus.io/exporter/stackdriver v0.9.1
7-
git.apache.org/thrift.git v0.0.0-20181101003639-92be4f312b88 // indirect
7+
git.apache.org/thrift.git v0.0.0-20181101003639-92be4f312b88
88
github.com/BurntSushi/toml v0.3.1 // indirect
99
github.com/DataDog/datadog-go v0.0.0-20180822151419-281ae9f2d895 // indirect
1010
github.com/DataDog/opencensus-go-exporter-datadog v0.0.0-20181026070331-e7c4bd17b329
@@ -26,6 +26,7 @@ require (
2626
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
2727
github.com/kr/pretty v0.1.0 // indirect
2828
github.com/mitchellh/mapstructure v1.1.2 // indirect
29+
github.com/omnition/scribe-go v0.0.0-20190131012523-9e3c68f31124
2930
github.com/opentracing/opentracing-go v1.0.2 // indirect
3031
github.com/openzipkin/zipkin-go v0.1.3
3132
github.com/orijtech/prometheus-go-metrics-exporter v0.0.2
@@ -34,6 +35,7 @@ require (
3435
github.com/pmezard/go-difflib v1.0.0 // indirect
3536
github.com/prashantv/protectmem v0.0.0-20171002184600-e20412882b3a // indirect
3637
github.com/prometheus/client_golang v0.8.0
38+
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273
3739
github.com/rs/cors v1.6.0
3840
github.com/soheilhy/cmux v0.1.4
3941
github.com/spf13/cast v1.2.0
@@ -57,6 +59,7 @@ require (
5759
golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc
5860
golang.org/x/oauth2 v0.0.0-20181102170140-232e45548389 // indirect
5961
golang.org/x/sys v0.0.0-20181031143558-9b800f95dbbc // indirect
62+
golang.org/x/text v0.3.0
6063
google.golang.org/api v0.0.0-20181102150758-04bb50b6b83d
6164
google.golang.org/appengine v1.3.0 // indirect
6265
google.golang.org/genproto v0.0.0-20181101192439-c830210a61df // indirect

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ cloud.google.com/go v0.32.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
77
contrib.go.opencensus.io/exporter/ocagent v0.3.0 h1:fyqPXp7d+BBV3tXa7EE1CYrObJr7R9jTAOO/AsdcQBg=
88
contrib.go.opencensus.io/exporter/ocagent v0.3.0/go.mod h1:0fnkYHF+ORKj7HWzOExKkUHeFX79gXSKUQbpnAM+wzo=
99
contrib.go.opencensus.io/exporter/ocagent v0.4.2/go.mod h1:YuG83h+XWwqWjvCqn7vK4KSyLKhThY3+gNGQ37iS2V0=
10+
contrib.go.opencensus.io/exporter/ocagent v0.4.3 h1:QjNm697iO7CZ09IxxSiCUzOhALENIsLsixdPwjV1yGs=
1011
contrib.go.opencensus.io/exporter/ocagent v0.4.3/go.mod h1:YuG83h+XWwqWjvCqn7vK4KSyLKhThY3+gNGQ37iS2V0=
1112
contrib.go.opencensus.io/exporter/stackdriver v0.7.0 h1:pmo1ol3uPcrLmvOET8bEbu5sialRZDDSHqJso0vo28o=
1213
contrib.go.opencensus.io/exporter/stackdriver v0.7.0/go.mod h1:hNe5qQofPbg6bLQY5wHCvQ7o+2E5P8PkegEuQ+MyRw0=
1314
contrib.go.opencensus.io/exporter/stackdriver v0.9.1 h1:W6APgQ9we4BH8U8bnq/FvwLKo2WSMHuiMkkS/Slkg30=
1415
contrib.go.opencensus.io/exporter/stackdriver v0.9.1/go.mod h1:hNe5qQofPbg6bLQY5wHCvQ7o+2E5P8PkegEuQ+MyRw0=
1516
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999 h1:sihTnRgTOUSCQz0iS0pjZuFQy/z7GXCJgSBg3+rZKHw=
1617
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
18+
git.apache.org/thrift.git v0.0.0-20181101003639-92be4f312b88 h1:c+lV5k88kQl9zle5Wstbsf1rW2Y9bMfuVyhJeIk5hgM=
1719
git.apache.org/thrift.git v0.0.0-20181101003639-92be4f312b88/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
1820
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
1921
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
@@ -27,6 +29,7 @@ github.com/Shopify/toxiproxy v2.1.3+incompatible h1:awiJqUYH4q4OmoBiRccJykjd7B+w
2729
github.com/Shopify/toxiproxy v2.1.3+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
2830
github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE=
2931
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
32+
github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7 h1:Fv9bK1Q+ly/ROk4aJsVMeuIwPel4bEnD8EPiI91nZMg=
3033
github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
3134
github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
3235
github.com/aws/aws-sdk-go v1.15.31/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
@@ -107,6 +110,8 @@ github.com/mitchellh/mapstructure v1.0.0 h1:vVpGvMXJPqSDh2VYHF7gsfQj8Ncx+Xw5Y1KH
107110
github.com/mitchellh/mapstructure v1.0.0/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
108111
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
109112
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
113+
github.com/omnition/scribe-go v0.0.0-20190131012523-9e3c68f31124 h1:mJ3GKMlsntao+kIP06AjcDxTQ5M4uG+cFKp8rRLTJG8=
114+
github.com/omnition/scribe-go v0.0.0-20190131012523-9e3c68f31124/go.mod h1:GnPmaNTr3pdt/V0JmVNVgDq+JEMb/oXxNlsG+pN6gg4=
110115
github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg=
111116
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
112117
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2019, OpenCensus 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 wraps the functionality to start the end-point that
16+
// receives Zipkin Scribe spans.
17+
package zipkinscribereceiver
18+
19+
import (
20+
"context"
21+
"fmt"
22+
23+
"github.com/spf13/viper"
24+
"go.uber.org/zap"
25+
26+
"github.com/census-instrumentation/opencensus-service/cmd/occollector/app/builder"
27+
"github.com/census-instrumentation/opencensus-service/internal/collector/processor"
28+
"github.com/census-instrumentation/opencensus-service/receiver"
29+
"github.com/census-instrumentation/opencensus-service/receiver/zipkin/scribe"
30+
)
31+
32+
// Start starts the Zipkin Scribe receiver endpoint.
33+
func Start(logger *zap.Logger, v *viper.Viper, spanProc processor.SpanProcessor) (receiver.TraceReceiver, error) {
34+
rOpts, err := builder.NewDefaultZipkinScribeReceiverCfg().InitFromViper(v)
35+
if err != nil {
36+
return nil, err
37+
}
38+
39+
sr, err := scribe.NewReceiver(rOpts.Address, rOpts.Port, rOpts.Category)
40+
if err != nil {
41+
return nil, fmt.Errorf("Failed to create the Zipkin Scribe receiver: %v", err)
42+
}
43+
ss := processor.WrapWithSpanSink("zipkin-scribe", spanProc)
44+
45+
if err := sr.StartTraceReception(context.Background(), ss); err != nil {
46+
return nil, fmt.Errorf("Cannot start Zipkin Scribe receiver %+v: %v", rOpts, err)
47+
}
48+
49+
logger.Info("Zipkin Scribe receiver is running.", zap.Uint16("port", rOpts.Port), zap.String("category", rOpts.Category))
50+
51+
return sr, nil
52+
}

internal/config/config.go

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ const (
5353

5454
var defaultOCReceiverCorsAllowedOrigins = []string{}
5555

56+
var defaultScribeConfiguration = &ScribeReceiverConfig{
57+
Port: 9410,
58+
Category: "zipkin",
59+
}
60+
5661
// Config denotes the configuration for the various elements of an agent, that is:
5762
// * Receivers
5863
// * ZPages
@@ -68,9 +73,10 @@ type Config struct {
6873
// * OpenCensus
6974
// * Zipkin
7075
type Receivers struct {
71-
OpenCensus *ReceiverConfig `yaml:"opencensus"`
72-
Zipkin *ReceiverConfig `yaml:"zipkin"`
73-
Jaeger *ReceiverConfig `yaml:"jaeger"`
76+
OpenCensus *ReceiverConfig `yaml:"opencensus"`
77+
Zipkin *ReceiverConfig `yaml:"zipkin"`
78+
Jaeger *ReceiverConfig `yaml:"jaeger"`
79+
Scribe *ScribeReceiverConfig `yaml:"zipkin-scribe"`
7480
}
7581

7682
// ReceiverConfig is the per-receiver configuration that identifies attributes
@@ -95,6 +101,21 @@ type ReceiverConfig struct {
95101
DisableMetrics bool `yaml:"disable_metrics"`
96102
}
97103

104+
// ScribeReceiverConfig carries the settings for the Zipkin Scribe receiver.
105+
type ScribeReceiverConfig struct {
106+
// Address is an IP address or a name that can be resolved to a local address.
107+
//
108+
// It can use a name, but this is not recommended, because it will create
109+
// a listener for at most one of the host's IP addresses.
110+
//
111+
// The default value bind to all available interfaces on the local computer.
112+
Address string `yaml:"address" mapstructure:"address"`
113+
Port uint16 `yaml:"port" mapstructure:"port"`
114+
// Category is the string that will be used to identify the scribe log messages
115+
// that contain Zipkin spans.
116+
Category string `yaml:"category" mapstructure:"category"`
117+
}
118+
98119
// Exporters denotes the configurations for the various backends
99120
// that this service exports observability signals to.
100121
type Exporters struct {
@@ -180,6 +201,15 @@ func (c *Config) ZipkinReceiverEnabled() bool {
180201
return c.Receivers != nil && c.Receivers.Zipkin != nil
181202
}
182203

204+
// ZipkinScribeReceiverEnabled returns true if Config is non-nil
205+
// and if the Scribe receiver configuration is also non-nil.
206+
func (c *Config) ZipkinScribeReceiverEnabled() bool {
207+
if c == nil {
208+
return false
209+
}
210+
return c.Receivers != nil && c.Receivers.Scribe != nil
211+
}
212+
183213
// JaegerReceiverEnabled returns true if Config is non-nil
184214
// and if the Jaeger receiver configuration is also non-nil.
185215
func (c *Config) JaegerReceiverEnabled() bool {
@@ -204,6 +234,22 @@ func (c *Config) ZipkinReceiverAddress() string {
204234
return inCfg.Zipkin.Address
205235
}
206236

237+
// ZipkinScribeConfig is a helper to safely retrieve the Zipkin Scribe
238+
// configuration.
239+
func (c *Config) ZipkinScribeConfig() *ScribeReceiverConfig {
240+
if c == nil || c.Receivers == nil || c.Receivers.Scribe == nil {
241+
return defaultScribeConfiguration
242+
}
243+
cfg := c.Receivers.Scribe
244+
if cfg.Port == 0 {
245+
cfg.Port = defaultScribeConfiguration.Port
246+
}
247+
if cfg.Category == "" {
248+
cfg.Category = defaultScribeConfiguration.Category
249+
}
250+
return cfg
251+
}
252+
207253
// JaegerReceiverPorts is a helper to safely retrieve the address
208254
// that the Jaeger receiver will run on.
209255
func (c *Config) JaegerReceiverPorts() (collectorPort, thriftPort int) {

0 commit comments

Comments
 (0)