@@ -55,17 +55,14 @@ var topics []string
55
55
var partitionStr string
56
56
var partitions []int32
57
57
var offsetStr string
58
- var DataDir string
59
58
var config * sarama.Config
60
59
var channelBufferSize int
61
60
var consumerFetchMin int
62
61
var consumerFetchDefault int
63
62
var consumerMaxWaitTime time.Duration
64
63
var consumerMaxProcessingTime time.Duration
65
64
var netMaxOpenRequests int
66
- var offsetMgr * kafka.OffsetMgr
67
65
var offsetDuration time.Duration
68
- var offsetCommitInterval time.Duration
69
66
var partitionOffset map [int32 ]* stats.Gauge64
70
67
var partitionLogSize map [int32 ]* stats.Gauge64
71
68
var partitionLag map [int32 ]* stats.Gauge64
@@ -77,10 +74,8 @@ func ConfigSetup() {
77
74
inKafkaMdm .StringVar (& brokerStr , "brokers" , "kafka:9092" , "tcp address for kafka (may be be given multiple times as a comma-separated list)" )
78
75
inKafkaMdm .StringVar (& kafkaVersionStr , "kafka-version" , "0.10.0.0" , "Kafka version in semver format. All brokers must be this version or newer." )
79
76
inKafkaMdm .StringVar (& topicStr , "topics" , "mdm" , "kafka topic (may be given multiple times as a comma-separated list)" )
80
- inKafkaMdm .StringVar (& offsetStr , "offset" , "last " , "Set the offset to start consuming from. Can be one of newest, oldest,last or a time duration" )
77
+ inKafkaMdm .StringVar (& offsetStr , "offset" , "newest " , "Set the offset to start consuming from. Can be oldest, newest or a time duration" )
81
78
inKafkaMdm .StringVar (& partitionStr , "partitions" , "*" , "kafka partitions to consume. use '*' or a comma separated list of id's" )
82
- inKafkaMdm .DurationVar (& offsetCommitInterval , "offset-commit-interval" , time .Second * 5 , "Interval at which offsets should be saved." )
83
- inKafkaMdm .StringVar (& DataDir , "data-dir" , "" , "Directory to store partition offsets index" )
84
79
inKafkaMdm .IntVar (& channelBufferSize , "channel-buffer-size" , 1000 , "The number of metrics to buffer in internal and external channels" )
85
80
inKafkaMdm .IntVar (& consumerFetchMin , "consumer-fetch-min" , 1 , "The minimum number of message bytes to fetch in a request" )
86
81
inKafkaMdm .IntVar (& consumerFetchDefault , "consumer-fetch-default" , 32768 , "The default number of message bytes to fetch in a request" )
@@ -100,9 +95,6 @@ func ConfigProcess(instance string) {
100
95
log .Fatalf ("kafkamdm: invalid kafka-version. %s" , err )
101
96
}
102
97
103
- if offsetCommitInterval == 0 {
104
- log .Fatal ("kafkamdm: offset-commit-interval must be greater then 0" )
105
- }
106
98
if consumerMaxWaitTime == 0 {
107
99
log .Fatal ("kafkamdm: consumer-max-wait-time must be greater then 0" )
108
100
}
@@ -111,7 +103,6 @@ func ConfigProcess(instance string) {
111
103
}
112
104
113
105
switch offsetStr {
114
- case "last" :
115
106
case "oldest" :
116
107
case "newest" :
117
108
default :
@@ -121,10 +112,6 @@ func ConfigProcess(instance string) {
121
112
}
122
113
}
123
114
124
- offsetMgr , err = kafka .NewOffsetMgr (DataDir )
125
- if err != nil {
126
- log .Fatalf ("kafkamdm: couldnt create offsetMgr. %s" , err )
127
- }
128
115
brokers = strings .Split (brokerStr , "," )
129
116
topics = strings .Split (topicStr , "," )
130
117
@@ -222,12 +209,6 @@ func (k *KafkaMdm) Start(handler input.Handler, cancel context.CancelFunc) error
222
209
offset = sarama .OffsetOldest
223
210
case "newest" :
224
211
offset = sarama .OffsetNewest
225
- case "last" :
226
- offset , err = offsetMgr .Last (topic , partition )
227
- if err != nil {
228
- log .Errorf ("kafkamdm: Failed to get %q duration offset for %s:%d. %q" , offsetStr , topic , partition , err )
229
- return err
230
- }
231
212
default :
232
213
offset , err = k .client .GetOffset (topic , partition , time .Now ().Add (- 1 * offsetDuration ).UnixNano ()/ int64 (time .Millisecond ))
233
214
if err != nil {
@@ -315,26 +296,20 @@ func (k *KafkaMdm) consumePartition(topic string, partition int32, currentOffset
315
296
return
316
297
}
317
298
messages := pc .Messages ()
318
- ticker := time .NewTicker (offsetCommitInterval )
299
+ ticker := time .NewTicker (5 * time . Second )
319
300
for {
320
301
select {
321
302
case msg , ok := <- messages :
322
303
// https://github.com/Shopify/sarama/wiki/Frequently-Asked-Questions#why-am-i-getting-a-nil-message-from-the-sarama-consumer
323
304
if ! ok {
324
305
log .Errorf ("kafkamdm: kafka consumer for %s:%d has shutdown. stop consuming" , topic , partition )
325
- if err := offsetMgr .Commit (topic , partition , currentOffset ); err != nil {
326
- log .Errorf ("kafkamdm: failed to commit offset for %s:%d, %s" , topic , partition , err )
327
- }
328
306
k .cancel ()
329
307
return
330
308
}
331
309
log .Debugf ("kafkamdm: received message: Topic %s, Partition: %d, Offset: %d, Key: %x" , msg .Topic , msg .Partition , msg .Offset , msg .Key )
332
310
k .handleMsg (msg .Value , partition )
333
311
currentOffset = msg .Offset
334
312
case ts := <- ticker .C :
335
- if err := offsetMgr .Commit (topic , partition , currentOffset ); err != nil {
336
- log .Errorf ("kafkamdm: failed to commit offset for %s:%d, %s" , topic , partition , err )
337
- }
338
313
k .lagMonitor .StoreOffset (partition , currentOffset , ts )
339
314
newest , err := k .tryGetOffset (topic , partition , sarama .OffsetNewest , 1 , 0 )
340
315
if err != nil {
@@ -351,9 +326,6 @@ func (k *KafkaMdm) consumePartition(topic string, partition int32, currentOffset
351
326
}
352
327
case <- k .stopConsuming :
353
328
pc .Close ()
354
- if err := offsetMgr .Commit (topic , partition , currentOffset ); err != nil {
355
- log .Errorf ("kafkamdm: failed to commit offset for %s:%d, %s" , topic , partition , err )
356
- }
357
329
log .Infof ("kafkamdm: consumer for %s:%d ended." , topic , partition )
358
330
return
359
331
}
@@ -391,7 +363,6 @@ func (k *KafkaMdm) Stop() {
391
363
close (k .stopConsuming )
392
364
k .wg .Wait ()
393
365
k .client .Close ()
394
- offsetMgr .Close ()
395
366
}
396
367
397
368
func (k * KafkaMdm ) MaintainPriority () {
0 commit comments