-
Notifications
You must be signed in to change notification settings - Fork 19
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
Feature: BB-309 add oplog populator metrics #2357
Merged
bert-e
merged 5 commits into
development/8.4
from
feature/BB-309-add-oplog-populator-metrics
Jan 6, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
41d3022
BB-309 fix invalid buckets not getting properly removed from the allo…
Kerkesni 3c7c712
BB-309 fix mongoClient deprecation message
Kerkesni 2fdb871
BB-309 handle metrics route in the oplogPopulator
Kerkesni 831bf88
BB-309 add oplogPopulator metrics
Kerkesni 2621a81
BB-309 adapt oplogPopulator unit tests
Kerkesni 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 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 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,165 @@ | ||
const { ZenkoMetrics } = require('arsenal').metrics; | ||
|
||
const { getStringSizeInBytes } = require('../../lib/util/buffer'); | ||
|
||
class OplogPopulatorMetrics { | ||
/** | ||
* @param {Logger} logger logger instance | ||
*/ | ||
constructor(logger) { | ||
this.acknowledgementLag = null; | ||
this.connectorConfiguration = null; | ||
this.requestSize = null; | ||
this.connectors = null; | ||
this.reconfigurationLag = null; | ||
this.connectorConfigurationApplied = null; | ||
this._logger = logger; | ||
} | ||
|
||
registerMetrics() { | ||
this.acknowledgementLag = ZenkoMetrics.createHistogram({ | ||
name: 'oplog_populator_acknowledgement_lag_sec', | ||
help: 'Delay between a config change in mongo and the start of processing by the oplogPopulator in seconds', | ||
labelNames: ['opType'], | ||
buckets: [0.001, 0.01, 1, 10, 100, 1000, 10000], | ||
}); | ||
this.connectorConfiguration = ZenkoMetrics.createCounter({ | ||
Kerkesni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name: 'oplog_populator_connector_configuration', | ||
help: 'Number of times we update the configuration of a connector', | ||
labelNames: ['connector', 'opType'], | ||
}); | ||
this.buckets = ZenkoMetrics.createGauge({ | ||
name: 'oplog_populator_connector_buckets', | ||
help: 'Number of buckets per connector', | ||
labelNames: ['connector'], | ||
}); | ||
this.requestSize = ZenkoMetrics.createCounter({ | ||
name: 'oplog_populator_connector_request_bytes', | ||
help: 'Size of kafka connect request in bytes', | ||
labelNames: ['connector'], | ||
}); | ||
this.mongoPipelineSize = ZenkoMetrics.createGauge({ | ||
name: 'oplog_populator_connector_pipeline_bytes', | ||
help: 'Size of mongo pipeline in bytes', | ||
labelNames: ['connector'], | ||
}); | ||
this.connectors = ZenkoMetrics.createGauge({ | ||
name: 'oplog_populator_connectors', | ||
help: 'Total number of configured connectors', | ||
labelNames: ['isOld'], | ||
}); | ||
this.reconfigurationLag = ZenkoMetrics.createHistogram({ | ||
name: 'oplog_populator_reconfiguration_lag_sec', | ||
help: 'Time it takes kafka-connect to respond to a connector configuration request', | ||
labelNames: ['connector'], | ||
buckets: [0.001, 0.01, 1, 10, 100, 1000, 10000], | ||
}); | ||
this.connectorConfigurationApplied = ZenkoMetrics.createCounter({ | ||
name: 'oplog_populator_connector_configuration_applied', | ||
help: 'Number of times we submit the configuration of a connector to kafka-connect', | ||
labelNames: ['connector', 'success'], | ||
}); | ||
} | ||
|
||
/** | ||
* updates oplog_populator_acknowledgement_lag_sec metric | ||
* @param {string} opType oplog operation type | ||
* @param {number} delta delay between a config change | ||
* in mongo and it getting processed by the oplogPopulator | ||
* @returns {undefined} | ||
*/ | ||
onOplogEventProcessed(opType, delta) { | ||
try { | ||
this.acknowledgementLag.observe({ | ||
opType, | ||
}, delta); | ||
} catch (error) { | ||
this._logger.error('An error occured while pushing metric', { | ||
method: 'OplogPopulatorMetrics.onOplogEventProcessed', | ||
error: error.message, | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* updates oplog_populator_connector_configuration & | ||
* oplog_populator_connector_request_bytes metrics | ||
* @param {Connector} connector connector instance | ||
* @param {string} opType operation type, could be one of | ||
* "add" and "delete" | ||
* @param {number} buckets number of buckets updated | ||
* @returns {undefined} | ||
*/ | ||
onConnectorConfigured(connector, opType, buckets = 1) { | ||
try { | ||
this.connectorConfiguration.inc({ | ||
connector: connector.name, | ||
opType, | ||
}, buckets); | ||
const reqSize = getStringSizeInBytes(JSON.stringify(connector.config)); | ||
this.requestSize.inc({ | ||
connector: connector.name, | ||
}, reqSize); | ||
const pipelineSize = getStringSizeInBytes(JSON.stringify(connector.config.pipeline)); | ||
this.mongoPipelineSize.set({ | ||
connector: connector.name, | ||
}, pipelineSize); | ||
} catch (error) { | ||
this._logger.error('An error occured while pushing metrics', { | ||
method: 'OplogPopulatorMetrics.onConnectorConfigured', | ||
error: error.message, | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* updates oplog_populator_connectors metric | ||
* @param {boolean} isOld true if connectors were not | ||
* created by this OplogPopulator instance | ||
* @param {number} count number of connectors added | ||
* @returns {undefined} | ||
*/ | ||
onConnectorsInstantiated(isOld, count = 1) { | ||
try { | ||
this.connectors.inc({ | ||
isOld, | ||
}, count); | ||
} catch (error) { | ||
this._logger.error('An error occured while pushing metrics', { | ||
method: 'OplogPopulatorMetrics.onConnectorsInstantiated', | ||
error: error.message, | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* updates oplog_populator_reconfiguration_lag_sec metric | ||
* @param {Connector} connector connector instance | ||
* @param {Boolean} success true if reconfiguration was successful | ||
* @param {number} delta time it takes to reconfigure a connector | ||
* @returns {undefined} | ||
*/ | ||
onConnectorReconfiguration(connector, success, delta = null) { | ||
try { | ||
this.connectorConfigurationApplied.inc({ | ||
connector: connector.name, | ||
success, | ||
}); | ||
if (success) { | ||
this.reconfigurationLag.observe({ | ||
connector: connector.name, | ||
}, delta); | ||
this.buckets.set({ | ||
connector: connector.name, | ||
}, connector.bucketCount); | ||
} | ||
} catch (error) { | ||
this._logger.error('An error occured while pushing metrics', { | ||
method: 'OplogPopulatorMetrics.onConnectorReconfiguration', | ||
error: error.message, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
module.exports = OplogPopulatorMetrics; |
This file contains 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 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 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to make metrics optional?
i don't really see a use-case here or "precedent" in other modules, shouldn't metrics always be collected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In normal cases we always have the metrics enabled, that's why it's set to true by default.
The option was put there to be able to run unit tests with no issues, as otherwise we would get errors about the metrics being registered multiple times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may indeed have something for the tests, but it should not propagate to the config...