Skip to content

Commit fff91ef

Browse files
committed
Instrument create_time from last message in batch
1 parent 6bd4121 commit fff91ef

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

lib/kafka/consumer.rb

+1
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ def each_batch(min_bytes: 1, max_bytes: 10485760, max_wait_time: 1, automaticall
308308
topic: batch.topic,
309309
partition: batch.partition,
310310
last_offset: batch.last_offset,
311+
last_create_time: batch.messages.last.try(:create_time),
311312
offset_lag: batch.offset_lag,
312313
highwater_mark_offset: batch.highwater_mark_offset,
313314
message_count: batch.messages.count,

lib/kafka/datadog.rb

+6
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ def process_message(event)
160160
def process_batch(event)
161161
offset = event.payload.fetch(:last_offset)
162162
messages = event.payload.fetch(:message_count)
163+
create_time = event.payload.fetch(:last_create_time)
164+
time_lag = create_time && ((Time.now - create_time) * 1000).to_i
163165

164166
tags = {
165167
client: event.payload.fetch(:client_id),
@@ -176,6 +178,10 @@ def process_batch(event)
176178
end
177179

178180
gauge("consumer.offset", offset, tags: tags)
181+
182+
if time_lag
183+
gauge("consumer.time_lag", time_lag, tags: tags)
184+
end
179185
end
180186

181187
def fetch_batch(event)

spec/prometheus_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
topic: 'AAA',
115115
partition: 4,
116116
last_offset: 100,
117+
last_create_time: Time.now,
117118
message_count: 7
118119
}
119120
end

0 commit comments

Comments
 (0)