-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
impr(S3UTILS-181): Add scuba backend to service-lvl-sidecar
- Loading branch information
Showing
7 changed files
with
194 additions
and
25 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1972,14 +1972,31 @@ REST API to provide service level reports for UtapiV2 | |
|
||
## Usage | ||
|
||
|
||
**Using warp10 backend** | ||
|
||
```shell | ||
docker run -d \ | ||
--network=host \ | ||
-e SIDECAR_API_KEY=dev_key_change_me \ | ||
-e SIDECAR_SCALE_FACTOR=1.4 \ | ||
-e SIDECAR_WARP10_NODE="md1-cluster1:[email protected]:4802" \ | ||
scality/s3utils service-level-sidecar/index.js | ||
``` | ||
|
||
**Using Scuba backend** | ||
```shell | ||
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_SCUBA_BUCKETD_BOOTSTRAP=127.0.0.1:19000 \ | ||
scality/s3utils service-level-sidecar/index.js | ||
``` | ||
|
||
**Example output** | ||
```shell | ||
curl -X POST -H "Authorization: Bearer dev_key_change_me" localhost:24742/api/report | jq | ||
{ | ||
"account": [ | ||
|
@@ -2133,6 +2150,21 @@ docker run -d \ | |
scality/s3utils service-level-sidecar/index.js | ||
``` | ||
|
||
#### 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. | ||
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_SCUBA_BUCKETD_BOOTSTRAP=127.0.0.1:19000 \ | ||
scality/s3utils service-level-sidecar/index.js | ||
``` | ||
|
||
### Other Settings | ||
|
||
- Log level can be set using `SIDECAR_LOG_LEVEL` (defaults to `info`) | ||
|
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
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,80 @@ | ||
const arsenal = require('arsenal'); | ||
const bucketclient = require('bucketclient'); | ||
|
||
const { BucketClientInterface } = arsenal.storage.metadata.bucketclient; | ||
const { splitter } = arsenal.constants; | ||
|
||
const rootLogger = require('./log'); | ||
const env = require('./env'); | ||
const utils = require('./utils'); | ||
|
||
const params = { | ||
bucketdBootstrap: [env.scubaBucketd], | ||
https: env.scubaBucketdTls ? env.tls.certs : undefined, | ||
}; | ||
|
||
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'); | ||
|
||
function formatMetricsKey(resourceName, timestamp) { | ||
const ts = padLeft(MAX_TS - roundToDay(timestamp).getTime(), TEMPLATE_TS); | ||
return `${resourceName}/${ts}`; | ||
} | ||
|
||
async function getMetrics(classType, resourceName, logId, timestamp, log) { | ||
const listingParams = { | ||
maxKeys: 1, | ||
listingType: 'Basic', | ||
gte: formatMetricsKey(resourceName, timestamp), | ||
lte: `${resourceName}/${padLeft(MAX_TS, TEMPLATE_TS)}`, | ||
}; | ||
|
||
const bucket = `${classType}${splitter}${logId}`; | ||
|
||
try { | ||
const resp = await listObjects(bucket, listingParams, log); | ||
if (resp.length === 0) { | ||
return null; | ||
} | ||
|
||
const { key, value } = resp[0]; | ||
return { | ||
key, | ||
value: JSON.parse(value), | ||
}; | ||
} catch (error) { | ||
if (error.NoSuchBucket) { | ||
return null; | ||
} | ||
log.error('error during metric listing', { error: error.message }); | ||
throw error; | ||
} | ||
} | ||
|
||
module.exports = { | ||
getMetrics, | ||
}; |
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