@@ -16,67 +16,28 @@ package builder
16
16
17
17
import (
18
18
"fmt"
19
- "strings"
20
19
21
- "github.com/spf13/viper"
22
20
"github.com/uber/jaeger-lib/metrics"
23
21
"go.uber.org/zap"
24
22
23
+ "github.com/jaegertracing/jaeger/cmd/ingester/app"
25
24
"github.com/jaegertracing/jaeger/cmd/ingester/app/consumer"
26
25
"github.com/jaegertracing/jaeger/cmd/ingester/app/processor"
27
26
kafkaConsumer "github.com/jaegertracing/jaeger/pkg/kafka/consumer"
28
27
"github.com/jaegertracing/jaeger/plugin/storage/kafka"
29
28
"github.com/jaegertracing/jaeger/storage/spanstore"
30
29
)
31
30
32
- const (
33
- // EncodingJSON indicates spans are encoded as a json byte array
34
- EncodingJSON = "json"
35
- // EncodingProto indicates spans are encoded as a protobuf byte array
36
- EncodingProto = "protobuf"
37
-
38
- // ConfigPrefix is a prefix fro the ingester flags
39
- ConfigPrefix = "ingester"
40
- // SuffixBrokers is a suffix for the brokers flag
41
- SuffixBrokers = ".brokers"
42
- // SuffixTopic is a suffix for the topic flag
43
- SuffixTopic = ".topic"
44
- // SuffixGroupID is a suffix for the group-id flag
45
- SuffixGroupID = ".group-id"
46
- // SuffixParallelism is a suffix for the parallelism flag
47
- SuffixParallelism = ".parallelism"
48
- // SuffixEncoding is a suffix for the encoding flag
49
- SuffixEncoding = ".encoding"
50
-
51
- // DefaultBroker is the default kafka broker
52
- DefaultBroker = "127.0.0.1:9092"
53
- // DefaultTopic is the default kafka topic
54
- DefaultTopic = "jaeger-spans"
55
- // DefaultGroupID is the default consumer Group ID
56
- DefaultGroupID = "jaeger-ingester"
57
- // DefaultParallelism is the default parallelism for the span processor
58
- DefaultParallelism = 1000
59
- // DefaultEncoding is the default span encoding
60
- DefaultEncoding = EncodingProto
61
- )
62
-
63
- // Builder stores the configuration options for the Ingester
64
- type Builder struct {
65
- kafkaConsumer.Configuration
66
- Parallelism int
67
- Encoding string
68
- }
69
-
70
31
// CreateConsumer creates a new span consumer for the ingester
71
- func ( b * Builder ) CreateConsumer (logger * zap.Logger , metricsFactory metrics.Factory , spanWriter spanstore.Writer ) (* consumer.Consumer , error ) {
32
+ func CreateConsumer (logger * zap.Logger , metricsFactory metrics.Factory , spanWriter spanstore.Writer , options app. Options ) (* consumer.Consumer , error ) {
72
33
var unmarshaller kafka.Unmarshaller
73
- if b .Encoding == EncodingJSON {
34
+ if options .Encoding == app . EncodingJSON {
74
35
unmarshaller = kafka .NewJSONUnmarshaller ()
75
- } else if b .Encoding == EncodingProto {
36
+ } else if options .Encoding == app . EncodingProto {
76
37
unmarshaller = kafka .NewProtobufUnmarshaller ()
77
38
} else {
78
39
return nil , fmt .Errorf (`encoding '%s' not recognised, use one of ("%s" or "%s")` ,
79
- b .Encoding , EncodingProto , EncodingJSON )
40
+ options .Encoding , app . EncodingProto , app . EncodingJSON )
80
41
}
81
42
82
43
spParams := processor.SpanProcessorParams {
@@ -86,18 +47,18 @@ func (b *Builder) CreateConsumer(logger *zap.Logger, metricsFactory metrics.Fact
86
47
spanProcessor := processor .NewSpanProcessor (spParams )
87
48
88
49
consumerConfig := kafkaConsumer.Configuration {
89
- Brokers : b .Brokers ,
90
- Topic : b .Topic ,
91
- GroupID : b .GroupID ,
50
+ Brokers : options .Brokers ,
51
+ Topic : options .Topic ,
52
+ GroupID : options .GroupID ,
92
53
}
93
54
saramaConsumer , err := consumerConfig .NewConsumer ()
94
55
if err != nil {
95
56
return nil , err
96
57
}
97
58
98
59
factoryParams := consumer.ProcessorFactoryParams {
99
- Topic : b .Topic ,
100
- Parallelism : b .Parallelism ,
60
+ Topic : options .Topic ,
61
+ Parallelism : options .Parallelism ,
101
62
SaramaConsumer : saramaConsumer ,
102
63
BaseProcessor : spanProcessor ,
103
64
Logger : logger ,
@@ -116,12 +77,3 @@ func (b *Builder) CreateConsumer(logger *zap.Logger, metricsFactory metrics.Fact
116
77
}
117
78
return consumer .New (consumerParams )
118
79
}
119
-
120
- // InitFromViper initializes Builder with properties from viper
121
- func (b * Builder ) InitFromViper (v * viper.Viper ) {
122
- b .Brokers = strings .Split (v .GetString (ConfigPrefix + SuffixBrokers ), "," )
123
- b .Topic = v .GetString (ConfigPrefix + SuffixTopic )
124
- b .GroupID = v .GetString (ConfigPrefix + SuffixGroupID )
125
- b .Parallelism = v .GetInt (ConfigPrefix + SuffixParallelism )
126
- b .Encoding = v .GetString (ConfigPrefix + SuffixEncoding )
127
- }
0 commit comments