MCPcopy
hub / github.com/scality/cloudserver / pushMetric

Function pushMetric

lib/utapi/utilities.js:253–348  ·  view source on GitHub ↗

* Call the Utapi Client `pushMetric` method with the associated parameters * @param {string} action - the metric action to push a metric for * @param {object} log - werelogs logger * @param {object} metricObj - the object containing the relevant data for * pushing metrics in Utapi * @param {str

(action, log, metricObj)

Source from the content-addressed store, hash-verified

251 * filtered out and not pushed to utapi.
252 */
253function pushMetric(action, log, metricObj) {
254 const {
255 bucket,
256 keys,
257 versionId,
258 byteLength,
259 newByteLength,
260 oldByteLength,
261 numberOfObjects,
262 authInfo,
263 canonicalID,
264 location,
265 isDelete,
266 removedDeleteMarkers,
267 } = metricObj;
268
269 if (utapiVersion === 2) {
270 const incomingBytes = action === 'getObject' ? 0 : newByteLength;
271 let sizeDelta = incomingBytes;
272 if (Number.isInteger(oldByteLength) && Number.isInteger(newByteLength)) {
273 sizeDelta = newByteLength - oldByteLength;
274 // Include oldByteLength in conditional so we don't end up with `-0`
275 } else if (action === 'completeMultipartUpload' && !versionId && oldByteLength) {
276 // If this is a non-versioned bucket we need to decrement
277 // the sizeDelta added by uploadPart when completeMPU is called.
278 sizeDelta = -oldByteLength;
279 } else if (action === 'abortMultipartUpload' && byteLength) {
280 sizeDelta = -byteLength;
281 } else if (action === 'putDeleteMarkerObject' && byteLength) {
282 sizeDelta = -byteLength;
283 }
284
285 let objectDelta = isDelete ? -numberOfObjects : numberOfObjects;
286 // putDeleteMarkerObject does not pass numberOfObjects
287 if ((action === 'putDeleteMarkerObject' && byteLength === null)
288 || action === 'replicateDelete'
289 || action === 'replicateObject') {
290 objectDelta = 1;
291 } else if (action === 'multiObjectDelete') {
292 objectDelta = -(numberOfObjects + removedDeleteMarkers);
293 }
294
295 const utapiObj = {
296 operationId: action,
297 bucket,
298 location,
299 objectDelta,
300 sizeDelta: isDelete ? -byteLength : sizeDelta,
301 incomingBytes,
302 outgoingBytes: action === 'getObject' ? newByteLength : 0,
303 };
304
305 // Any operation from lifecycle that does not change object count or size is dropped
306 const isLifecycle = _config.lifecycleRoleName
307 && authInfo && authInfo.arn.endsWith(`:assumed-role/${_config.lifecycleRoleName}/backbeat-lifecycle`);
308 if (isLifecycle && !objectDelta && !sizeDelta) {
309 log.trace('ignoring pushMetric from lifecycle service user', { action, bucket, keys });
310 return undefined;

Callers 15

pushReplicationMetricFunction · 0.85
bucketDeleteLifecycleFunction · 0.85
bucketPutCorsFunction · 0.85
objectPutFunction · 0.85
bucketDeleteEncryptionFunction · 0.85
objectGetLegalHoldFunction · 0.85
bucketPutVersioningFunction · 0.85
_getMPUBucketFunction · 0.85
listPartsFunction · 0.85
bucketDeleteTaggingFunction · 0.85
bucketDeleteFunction · 0.85
objectGetAttributesFunction · 0.85

Calls 3

evalAuthInfoFunction · 0.85
traceMethod · 0.80
getSerializedUidsMethod · 0.80

Tested by

no test coverage detected