diff --git a/README.md b/README.md index 32bce70a..7880687e 100644 --- a/README.md +++ b/README.md @@ -1990,7 +1990,7 @@ docker run -d \ --network=host \ -e SIDECAR_API_KEY=dev_key_change_me \ -e SIDECAR_SCALE_FACTOR=1.4 \ - -e SIDECAR_ENABLE_SCUBA=t \ + -e SIDECAR_ENABLE_SCUBA=true \ -e SIDECAR_SCUBA_BUCKETD_BOOTSTRAP=127.0.0.1:19000 \ scality/s3utils service-level-sidecar/index.js ``` @@ -2153,14 +2153,14 @@ docker run -d \ #### Scuba The scuba backend can be enabled by setting `SIDECAR_ENABLE_SCUBA`. -A bucketd bootstrap list can be provided using `SIDECAR_SCUBA_BUCKETD_BOOTSTRAP`. -If a bootstrap list is not provided `127.0.0.1:19000` will be used. +A bucketd address can be provided using `SIDECAR_SCUBA_BUCKETD_BOOTSTRAP`. +If a bucketd address is not provided `127.0.0.1:19000` will be used. Internal TLS support can be enabled using `SIDECAR_SCUBA_BUCKETD_ENABLE_TLS`. ```shell docker run -d \ --network=host \ - -e SIDECAR_ENABLE_SCUBA=t \ + -e SIDECAR_ENABLE_SCUBA=true \ -e SIDECAR_SCUBA_BUCKETD_BOOTSTRAP=127.0.0.1:19000 \ scality/s3utils service-level-sidecar/index.js ``` diff --git a/service-level-sidecar/report.js b/service-level-sidecar/report.js index 6b76cfee..9093030b 100644 --- a/service-level-sidecar/report.js +++ b/service-level-sidecar/report.js @@ -48,18 +48,20 @@ class MetricReport { /** - * @param {Array} logIds - raft session ids to retrieve metrics for (only contains info if scuba backend is enabled) + * @param {Array} sessionIds - raft session ids to retrieve metrics for (only contains info if scuba backend is enabled) * @param {integer} timestamp - timestamp to retrieve metrics in microseconds - * @param {string} bucket - bucket name to retrieve metrics for + * @param {object} bucket - bucket to retrieve metrics for + * @param {string} bucket.name - bucket name + * @param {string} bucket.account - bucket owner account canonical id * @param {object} log - werelogs logger instance * @returns {object} - object count and bytes stored for bucket */ -async function getMetricsForBucket(logIds, timestamp, bucket, log) { +async function getMetricsForBucket(sessionIds, timestamp, bucket, log) { log.debug('getting metrics for bucket', { bucket: bucket.name, timestamp }); if (env.enableScuba) { const resourceName = `${bucket.account}${splitter}${bucket.name}`; - const logResults = await util.promisify(async.mapLimit)(logIds, env.concurrencyLimit, async logId => { + const logResults = await util.promisify(async.mapLimit)(sessionIds, env.concurrencyLimit, async logId => { try { return await scuba.getMetrics('bucket', resourceName, logId, new Date(timestamp), log); } catch (err) { @@ -97,16 +99,16 @@ async function getServiceReport(timestamp, log) { const bucketReports = {}; const accountInfoCache = {}; - let logIds = []; + let sessionIds = []; if (env.enableScuba) { - logIds = await bucketd.getRaftSessionIds(log); - logIds = logIds.filter(id => id !== '0'); + sessionIds = await bucketd.getRaftSessionIds(log); + sessionIds = sessionIds.filter(id => id !== '0'); } for await (const buckets of bucketd.listBuckets(log)) { log.debug('got response from bucketd', { numBuckets: buckets.length }); await util.promisify(async.eachLimit)(buckets, env.concurrencyLimit, async bucket => { - const metrics = await getMetricsForBucket(logIds, timestamp, bucket, log); + const metrics = await getMetricsForBucket(sessionIds, timestamp, bucket, log); log.debug('fetched metrics for bucket', { bucket: bucket.name, accCanonicalId: bucket.account }); diff --git a/service-level-sidecar/scuba.js b/service-level-sidecar/scuba.js index aa31654a..d3df96f3 100644 --- a/service-level-sidecar/scuba.js +++ b/service-level-sidecar/scuba.js @@ -17,19 +17,6 @@ const metadata = new BucketClientInterface(params, bucketclient, rootLogger); const listObjects = utils.retryable(metadata.listObject.bind(metadata)); - -/** - * Left-pad a string representation of a value with a given template. - * For example: pad('foo', '00000') gives '00foo'. - * - * @param {any} value - value to pad - * @param {string} template - padding template - * @returns {string} - padded string - */ -function padLeft(value, template) { - return `${template}${value}`.slice(-template.length); -} - function roundToDay(timestamp) { return new Date( Date.UTC(timestamp.getUTCFullYear(), timestamp.getUTCMonth(), timestamp.getUTCDate(), 23, 59, 59, 999), @@ -37,23 +24,22 @@ function roundToDay(timestamp) { } const LENGTH_TS = 14; -const MAX_TS = 10 ** LENGTH_TS - 1; // good until 16 Nov 5138 -const TEMPLATE_TS = new Array(LENGTH_TS + 1).join('0'); +const MAX_TS = parseInt(('9'.repeat(LENGTH_TS)), 10); function formatMetricsKey(resourceName, timestamp) { - const ts = padLeft(MAX_TS - roundToDay(timestamp).getTime(), TEMPLATE_TS); + const ts = (MAX_TS - roundToDay(timestamp).getTime()).toString().padStart(LENGTH_TS, '0'); return `${resourceName}/${ts}`; } -async function getMetrics(classType, resourceName, logId, timestamp, log) { +async function getMetrics(classType, resourceName, sessionId, timestamp, log) { const listingParams = { maxKeys: 1, listingType: 'Basic', gte: formatMetricsKey(resourceName, timestamp), - lte: `${resourceName}/${padLeft(MAX_TS, TEMPLATE_TS)}`, + lte: `${resourceName}/${MAX_TS.toString()}`, }; - const bucket = `${classType}${splitter}${logId}`; + const bucket = `${classType}${splitter}${sessionId}`; try { const resp = await listObjects(bucket, listingParams, log);