Skip to content

Commit 51d0c91

Browse files
committed
source-mongodb: additional debug logs when discard documents
Debug logging for when documents are discarded because they are not for a tracked operation type, or because the full document is empty. Both of these event types should be fairly low-volume. Also adds a sanity check when combining fragments from a split event to make sure that a source MongoDB collection is determined, which could otherwise cause a false negative when checking if that collection is among the tracked collections. I have no present reason to think this will ever happen, but it seems worthwhile to verify.
1 parent ebc98fe commit 51d0c91

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

source-mongodb/change_stream.go

+19
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,20 @@ func (c *capture) readEvent(
338338
}
339339
}
340340

341+
var logFields log.Fields
342+
if log.GetLevel() == log.DebugLevel {
343+
logFields = log.Fields{
344+
"_id": idToString(ev.fields.DocumentKey.Id),
345+
"changeStreamDatabase": s.db,
346+
"operationType": ev.fields.OperationType,
347+
"fragments": ev.fragments,
348+
"requestedAnotherBatch": requestedAnotherBatch,
349+
}
350+
}
351+
341352
if !slices.Contains([]string{"insert", "update", "replace", "delete"}, ev.fields.OperationType) {
342353
// Event is not for a tracked operation type.
354+
log.WithFields(logFields).Debug("discarding event with un-tracked operation")
343355
return
344356
} else if ev.fields.OperationType != "delete" && ev.fields.FullDocument == nil {
345357
// FullDocument can be "null" for non-deletion events if another
@@ -350,6 +362,7 @@ func (c *capture) readEvent(
350362
// or different from the deltas in the update event. We ignore
351363
// events where FullDocument is null. Another change event of type
352364
// delete will eventually come and delete the document.
365+
log.WithFields(logFields).Debug("discarding event with no FullDocument")
353366
return
354367
}
355368

@@ -395,6 +408,12 @@ func readFragments(
395408
}
396409
}
397410

411+
if ev.fields.Ns.Collection == "" {
412+
// This should never happen, since split events should always be
413+
// collection documents.
414+
return 0, false, fmt.Errorf("reading fragments produced an event with no collection")
415+
}
416+
398417
return lastFragment, requestedAnotherBatch, nil
399418
}
400419

0 commit comments

Comments
 (0)