Skip to content

Commit efe210b

Browse files
committed
matching: prepare for REF-AUS: extend metrics and logging with labels 💥
1 parent e3c5d3e commit efe210b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/match.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,17 @@ const runGtfsMatching = async (cfg, opt = {}) => {
141141
name: 'nats_msg_seq',
142142
help: 'sequence number of the latest NATS message being processed',
143143
registers: [register],
144+
labelNames: [
145+
'topic_root', // first "segment" of the topic, e.g. `AUS` with `aus.istfahrt.foo.bar`
146+
],
144147
})
145148

146149
const successesTotal = new Counter({
147150
name: 'matching_successes_total',
148151
help: 'number of successfully matched movements/trips',
149152
registers: [register],
150153
labelNames: [
154+
'kind', // sollfahrt, istfahrt
151155
'cached',
152156
],
153157
})
@@ -156,20 +160,24 @@ const runGtfsMatching = async (cfg, opt = {}) => {
156160
help: 'number of matching failures',
157161
registers: [register],
158162
labelNames: [
163+
'kind', // sollfahrt, istfahrt
159164
'cached',
160165
],
161166
})
162167
const errorsTotal = new Counter({
163168
name: 'matching_errors_total',
164169
help: 'number of errors that have occured while matching',
165170
registers: [register],
166-
labelNames: [],
171+
labelNames: [
172+
'kind', // sollfahrt, istfahrt
173+
],
167174
})
168175
const matchingTimeSeconds = new Summary({
169176
name: 'matching_time_seconds',
170177
help: 'seconds trips need to be matched',
171178
registers: [register],
172179
labelNames: [
180+
'kind', // sollfahrt, istfahrt
173181
'matched',
174182
'cached',
175183
],
@@ -250,7 +258,7 @@ const runGtfsMatching = async (cfg, opt = {}) => {
250258
topic_root,
251259
redelivered,
252260
}, tReceived / 1000)
253-
natsMsgSeq.set(seq)
261+
natsMsgSeq.set(seq, {topic_root})
254262
}
255263

256264
let vdvItem = null
@@ -275,14 +283,17 @@ const runGtfsMatching = async (cfg, opt = {}) => {
275283

276284
if (isMatched) {
277285
successesTotal.inc({
286+
kind,
278287
cached: isCached ? '1' : '0',
279288
})
280289
} else {
281290
failuresTotal.inc({
291+
kind,
282292
cached: isCached ? '1' : '0',
283293
})
284294
}
285295
matchingTimeSeconds.observe({
296+
kind,
286297
matched: isMatched ? '1' : '0',
287298
cached: isCached ? '1' : '0',
288299
}, matchingTime / 1000)
@@ -305,7 +316,9 @@ const runGtfsMatching = async (cfg, opt = {}) => {
305316
[kind]: vdvItem,
306317
natsMsgSeq: msg.seq,
307318
}, `failed to match trip: ${err.message || (err + '')}`)
308-
errorsTotal.inc()
319+
errorsTotal.inc({
320+
kind,
321+
})
309322
}
310323

311324
// We catch all non-programmer errors in order not to abort the message processing (see below).
@@ -371,8 +384,9 @@ const runGtfsMatching = async (cfg, opt = {}) => {
371384
// query details of the (externally created) NATS JetStream consumer
372385
const consumerInfo = await istFahrtsConsumer.info()
373386
serviceLogger.debug({
387+
stream: NATS_JETSTREAM_AUS_ISTFAHRT_STREAM_NAME,
374388
consumerInfo,
375-
}, 'using NATS JetStream consumer')
389+
}, 'using NATS JetStream consumer for AUS IstFahrts')
376390
}
377391

378392
const istFahrtsSub = await istFahrtsConsumer.consume()

0 commit comments

Comments
 (0)