-
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-level-sidecar
- Loading branch information
Showing
7 changed files
with
184 additions
and
27 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 Warp 10 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=true \ | ||
-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": [ | ||
|
@@ -2120,7 +2137,7 @@ docker run -d \ | |
scality/s3utils service-level-sidecar/index.js | ||
``` | ||
|
||
#### Warp10 | ||
#### Warp 10 | ||
|
||
The Warp 10 address is configured using `SIDECAR_WARP10_NODE`. | ||
The Warp 10 `nodeId` must be included (normally matches ansible inventory name plus port ie `md1-cluster1:4802`). | ||
|
@@ -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 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=true \ | ||
-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,66 @@ | ||
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)); | ||
|
||
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 = parseInt(('9'.repeat(LENGTH_TS)), 10); | ||
|
||
function formatMetricsKey(resourceName, timestamp) { | ||
const ts = (MAX_TS - roundToDay(timestamp).getTime()).toString().padStart(LENGTH_TS, '0'); | ||
return `${resourceName}/${ts}`; | ||
} | ||
|
||
async function getMetrics(classType, resourceName, sessionId, timestamp, log) { | ||
const listingParams = { | ||
maxKeys: 1, | ||
listingType: 'Basic', | ||
gte: formatMetricsKey(resourceName, timestamp), | ||
lte: `${resourceName}/${MAX_TS.toString()}`, | ||
}; | ||
|
||
const bucket = `${classType}${splitter}${sessionId}`; | ||
|
||
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