Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tmacro committed Nov 14, 2024
1 parent 6609296 commit 2c4f7ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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
```
Expand Down
18 changes: 10 additions & 8 deletions service-level-sidecar/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,20 @@ class MetricReport {


/**
* @param {Array<Number>} logIds - raft session ids to retrieve metrics for (only contains info if scuba backend is enabled)
* @param {Array<Number>} 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) {
Expand Down Expand Up @@ -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 });

Expand Down
24 changes: 5 additions & 19 deletions service-level-sidecar/scuba.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,29 @@ 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),
);
}

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);
Expand Down

0 comments on commit 2c4f7ad

Please sign in to comment.