Skip to content

Commit 74f17f1

Browse files
author
Davit Yeghshatyan
committed
Move flags into builder package
Signed-off-by: Davit Yeghshatyan <davo@uber.com>
1 parent 788dc1d commit 74f17f1

File tree

6 files changed

+87
-90
lines changed

6 files changed

+87
-90
lines changed

cmd/ingester/app/builder/.nocover

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CreateConsumer requires connection to Kafka

cmd/ingester/app/builder/builder.go

-31
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,6 @@ import (
2929
"github.com/jaegertracing/jaeger/storage/spanstore"
3030
)
3131

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-
6332
// Builder stores the configuration options for the Ingester
6433
type Builder struct {
6534
kafkaConsumer.Configuration

cmd/ingester/app/builder/flags.go

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) 2018 The Jaeger 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 builder
16+
17+
import (
18+
"flag"
19+
"fmt"
20+
"strconv"
21+
)
22+
23+
const (
24+
// EncodingJSON indicates spans are encoded as a json byte array
25+
EncodingJSON = "json"
26+
// EncodingProto indicates spans are encoded as a protobuf byte array
27+
EncodingProto = "protobuf"
28+
29+
// ConfigPrefix is a prefix fro the ingester flags
30+
ConfigPrefix = "ingester"
31+
// SuffixBrokers is a suffix for the brokers flag
32+
SuffixBrokers = ".brokers"
33+
// SuffixTopic is a suffix for the topic flag
34+
SuffixTopic = ".topic"
35+
// SuffixGroupID is a suffix for the group-id flag
36+
SuffixGroupID = ".group-id"
37+
// SuffixParallelism is a suffix for the parallelism flag
38+
SuffixParallelism = ".parallelism"
39+
// SuffixEncoding is a suffix for the encoding flag
40+
SuffixEncoding = ".encoding"
41+
42+
// DefaultBroker is the default kafka broker
43+
DefaultBroker = "127.0.0.1:9092"
44+
// DefaultTopic is the default kafka topic
45+
DefaultTopic = "jaeger-spans"
46+
// DefaultGroupID is the default consumer Group ID
47+
DefaultGroupID = "jaeger-ingester"
48+
// DefaultParallelism is the default parallelism for the span processor
49+
DefaultParallelism = 1000
50+
// DefaultEncoding is the default span encoding
51+
DefaultEncoding = EncodingProto
52+
)
53+
54+
// AddFlags adds flags for Builder
55+
func AddFlags(flagSet *flag.FlagSet) {
56+
flagSet.String(
57+
ConfigPrefix+SuffixBrokers,
58+
DefaultBroker,
59+
"The comma-separated list of kafka brokers. i.e. '127.0.0.1:9092,0.0.0:1234'")
60+
flagSet.String(
61+
ConfigPrefix+SuffixTopic,
62+
DefaultTopic,
63+
"The name of the kafka topic to consume from")
64+
flagSet.String(
65+
ConfigPrefix+SuffixGroupID,
66+
DefaultGroupID,
67+
"The Consumer Group that ingester will be consuming on behalf of")
68+
flagSet.String(
69+
ConfigPrefix+SuffixParallelism,
70+
strconv.Itoa(DefaultParallelism),
71+
"The number of messages to process in parallel")
72+
flagSet.String(
73+
ConfigPrefix+SuffixEncoding,
74+
DefaultEncoding,
75+
fmt.Sprintf(`The encoding of spans ("%s" or "%s") consumed from kafka`, EncodingProto, EncodingJSON))
76+
}

cmd/ingester/app/flags_test.go cmd/ingester/app/builder/flags_test.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package app
15+
package builder
1616

1717
import (
1818
"testing"
1919

2020
"github.com/stretchr/testify/assert"
2121

22-
"github.com/jaegertracing/jaeger/cmd/ingester/app/builder"
2322
"github.com/jaegertracing/jaeger/pkg/config"
2423
)
2524

2625
func TestOptionsWithFlags(t *testing.T) {
27-
b := &builder.Builder{}
26+
b := &Builder{}
2827
v, command := config.Viperize(AddFlags)
2928
command.ParseFlags([]string{
3029
"--ingester.topic=topic1",
@@ -38,18 +37,18 @@ func TestOptionsWithFlags(t *testing.T) {
3837
assert.Equal(t, []string{"127.0.0.1:9092", "0.0.0:1234"}, b.Brokers)
3938
assert.Equal(t, "group1", b.GroupID)
4039
assert.Equal(t, 5, b.Parallelism)
41-
assert.Equal(t, builder.EncodingJSON, b.Encoding)
40+
assert.Equal(t, EncodingJSON, b.Encoding)
4241
}
4342

4443
func TestFlagDefaults(t *testing.T) {
45-
b := &builder.Builder{}
44+
b := &Builder{}
4645
v, command := config.Viperize(AddFlags)
4746
command.ParseFlags([]string{})
4847
b.InitFromViper(v)
4948

50-
assert.Equal(t, builder.DefaultTopic, b.Topic)
51-
assert.Equal(t, []string{builder.DefaultBroker}, b.Brokers)
52-
assert.Equal(t, builder.DefaultGroupID, b.GroupID)
53-
assert.Equal(t, builder.DefaultParallelism, b.Parallelism)
54-
assert.Equal(t, builder.DefaultEncoding, b.Encoding)
49+
assert.Equal(t, DefaultTopic, b.Topic)
50+
assert.Equal(t, []string{DefaultBroker}, b.Brokers)
51+
assert.Equal(t, DefaultGroupID, b.GroupID)
52+
assert.Equal(t, DefaultParallelism, b.Parallelism)
53+
assert.Equal(t, DefaultEncoding, b.Encoding)
5554
}

cmd/ingester/app/flags.go

-47
This file was deleted.

cmd/ingester/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828

2929
"github.com/jaegertracing/jaeger/cmd/env"
3030
"github.com/jaegertracing/jaeger/cmd/flags"
31-
"github.com/jaegertracing/jaeger/cmd/ingester/app"
3231
"github.com/jaegertracing/jaeger/cmd/ingester/app/builder"
3332
"github.com/jaegertracing/jaeger/pkg/config"
3433
pMetrics "github.com/jaegertracing/jaeger/pkg/metrics"
@@ -120,7 +119,7 @@ func main() {
120119
flags.AddFlags,
121120
storageFactory.AddFlags,
122121
pMetrics.AddFlags,
123-
app.AddFlags,
122+
builder.AddFlags,
124123
)
125124

126125
if err := command.Execute(); err != nil {

0 commit comments

Comments
 (0)