-
Notifications
You must be signed in to change notification settings - Fork 23
oplogPopulator: synthesise oplog key via $addFields in connector pipeline #2744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
delthas
wants to merge
2
commits into
development/9.4
Choose a base branch
from
improvement/BB-768/oplog-key-via-pipeline-addfields
base: development/9.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+233
−47
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
lib/queuePopulator/KafkaLogConsumer/KafkaLogConsumerMetrics.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| const { ZenkoMetrics } = require('arsenal').metrics; | ||
|
|
||
| // Counts consumed oplog events that downstream queue populators will | ||
| // process but that lack a top-level 'key' field — i.e., the synthesised | ||
| // partitioning key produced by the connector pipeline (see BB-768). | ||
| // Should stay at zero in steady-state; a non-zero rate signals that | ||
| // metadata grew a write path that doesn't $set the whole 'value' | ||
| // subdocument, regressing the per-object partitioning fix. | ||
| const oplogEventMissingKey = ZenkoMetrics.createCounter({ | ||
| name: 's3_oplog_event_missing_key_total', | ||
| help: 'Total number of oplog events processed by queue populators ' + | ||
| 'with the synthesised top-level "key" field missing or null', | ||
| labelNames: ['opType'], | ||
| }); | ||
|
|
||
| class KafkaLogConsumerMetrics { | ||
| static onMissingKey(log, opType) { | ||
| try { | ||
| oplogEventMissingKey.inc({ | ||
| opType: opType || 'unknown', | ||
| }); | ||
| } catch (err) { | ||
| KafkaLogConsumerMetrics.handleError( | ||
| log, err, 'KafkaLogConsumerMetrics.onMissingKey'); | ||
| } | ||
| } | ||
|
|
||
| static handleError(log, err, method) { | ||
| if (log && log.error) { | ||
| log.error('failed to update prometheus metrics', { | ||
| method, | ||
| error: err.message, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = KafkaLogConsumerMetrics; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/unit/lib/queuePopulator/kafkaLogConsumer/KafkaLogConsumerMetrics.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| const assert = require('assert'); | ||
| const sinon = require('sinon'); | ||
| const { ZenkoMetrics } = require('arsenal').metrics; | ||
| const KafkaLogConsumerMetrics = | ||
| require('../../../../../lib/queuePopulator/KafkaLogConsumer/KafkaLogConsumerMetrics'); | ||
|
|
||
| describe('KafkaLogConsumerMetrics', () => { | ||
| const log = { error: sinon.stub() }; | ||
|
|
||
| afterEach(() => { | ||
| sinon.restore(); | ||
| log.error.resetHistory(); | ||
| }); | ||
|
|
||
| describe('onMissingKey', () => { | ||
| it('should increment the s3_oplog_event_missing_key_total counter', () => { | ||
| const metric = ZenkoMetrics.getMetric('s3_oplog_event_missing_key_total'); | ||
| const incStub = sinon.stub(metric, 'inc'); | ||
| KafkaLogConsumerMetrics.onMissingKey(log, 'update'); | ||
| assert(incStub.calledOnceWith({ opType: 'update' })); | ||
| assert(log.error.notCalled); | ||
| }); | ||
|
|
||
| it('should label as "unknown" when opType is missing', () => { | ||
| const metric = ZenkoMetrics.getMetric('s3_oplog_event_missing_key_total'); | ||
| const incStub = sinon.stub(metric, 'inc'); | ||
| KafkaLogConsumerMetrics.onMissingKey(log, undefined); | ||
| assert(incStub.calledOnceWith({ opType: 'unknown' })); | ||
| }); | ||
|
|
||
| it('should swallow + log errors from inc', () => { | ||
| const metric = ZenkoMetrics.getMetric('s3_oplog_event_missing_key_total'); | ||
| sinon.stub(metric, 'inc').throws(new Error('boom')); | ||
| assert.doesNotThrow(() => KafkaLogConsumerMetrics.onMissingKey(log, 'insert')); | ||
| assert(log.error.calledOnce); | ||
| assert(log.error.calledWithMatch('failed to update prometheus metrics', { | ||
| method: 'KafkaLogConsumerMetrics.onMissingKey', | ||
| })); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.