@@ -23,9 +23,7 @@ type KafkaMdm struct {
23
23
config * sarama.Config
24
24
client sarama.SyncProducer
25
25
hash hash.Hash32
26
- part * p.Kafka
27
- lmPart LastNumPartitioner
28
- partScheme string
26
+ part p.Partitioner
29
27
numPartitions int32
30
28
}
31
29
@@ -46,11 +44,6 @@ func (p *LastNumPartitioner) Partition(m schema.PartitionedMetric, numPartitions
46
44
return int32 (part ), nil
47
45
}
48
46
49
- // key is by metric name, but won't be used for partition setting
50
- func (p * LastNumPartitioner ) GetPartition (m schema.PartitionedMetric , numPartitions int32 ) (int32 , error ) {
51
- return m .PartitionID (schema .PartitionBySeries , numPartitions )
52
- }
53
-
54
47
func New (topic string , brokers []string , codec string , stats met.Backend , partitionScheme string , numPartitions int32 ) (* KafkaMdm , error ) {
55
48
// We are looking for strong consistency semantics.
56
49
// Because we don't change the flush settings, sarama will try to produce messages
@@ -81,8 +74,7 @@ func New(topic string, brokers []string, codec string, stats met.Backend, partit
81
74
if err != nil {
82
75
return nil , err
83
76
}
84
- var part * p.Kafka
85
- var lmPart LastNumPartitioner
77
+ var part p.Partitioner
86
78
switch partitionScheme {
87
79
case "byOrg" :
88
80
part , err = p .NewKafka ("byOrg" )
@@ -91,11 +83,9 @@ func New(topic string, brokers []string, codec string, stats met.Backend, partit
91
83
case "bySeriesWithTags" :
92
84
part , err = p .NewKafka ("bySeriesWithTags" )
93
85
case "lastNum" :
94
- lmPart = LastNumPartitioner {}
95
- // sets partition based on message partition field
96
- config .Producer .Partitioner = sarama .NewManualPartitioner
86
+ part = & LastNumPartitioner {}
97
87
default :
98
- err = fmt .Errorf ("partitionScheme must be one of 'byOrg|bySeries|lastNum'. got %s" , partitionScheme )
88
+ err = fmt .Errorf ("partitionScheme must be one of 'byOrg|bySeries|bySeriesWithTags| lastNum'. got %s" , partitionScheme )
99
89
}
100
90
if err != nil {
101
91
return nil , err
@@ -109,8 +99,6 @@ func New(topic string, brokers []string, codec string, stats met.Backend, partit
109
99
client : client ,
110
100
hash : fnv .New32a (),
111
101
part : part ,
112
- lmPart : lmPart ,
113
- partScheme : partitionScheme ,
114
102
numPartitions : numPartitions ,
115
103
}, nil
116
104
}
@@ -139,28 +127,15 @@ func (k *KafkaMdm) Flush(metrics []*schema.MetricData) error {
139
127
140
128
k .MessageBytes .Value (int64 (len (data )))
141
129
142
- if k .partScheme == "lastNum" {
143
- partition , err := k .lmPart .Partition (metric , 0 )
144
- if err != nil {
145
- return fmt .Errorf ("Failed to get partition for metric. %s" , err )
146
- }
147
-
148
- payload [i ] = & sarama.ProducerMessage {
149
- Partition : partition ,
150
- Topic : k .topic ,
151
- Value : sarama .ByteEncoder (data ),
152
- }
153
- } else {
154
- partition , err := k .part .GetPartition (metric , k .numPartitions )
155
- if err != nil {
156
- return fmt .Errorf ("Failed to get partition for metric. %s" , err )
157
- }
130
+ partition , err := k .part .Partition (metric , k .numPartitions )
131
+ if err != nil {
132
+ return fmt .Errorf ("Failed to get partition for metric. %s" , err )
133
+ }
158
134
159
- payload [i ] = & sarama.ProducerMessage {
160
- Partition : partition ,
161
- Topic : k .topic ,
162
- Value : sarama .ByteEncoder (data ),
163
- }
135
+ payload [i ] = & sarama.ProducerMessage {
136
+ Partition : partition ,
137
+ Topic : k .topic ,
138
+ Value : sarama .ByteEncoder (data ),
164
139
}
165
140
166
141
}
0 commit comments