Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
"site": "us-east-2",
"type": "aws_s3"
}],
"backbeat": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it usable out of the box and ease testing, could we handle CRR_METRICS_HOST and CRR_METRICS_PORT environment variables to update this directly in docker-endpoint.sh?

Copy link
Author

@bennettbuchanan bennettbuchanan Mar 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got it! Updated so that you can run the image with a custom endpoint as such:

docker run -e CRR_METRICS_HOST=10.100.3.139 -e CRR_METRICS_PORT=1337 a7ae6fa66070

"host": "localhost",
"port": 8900
},
"cdmi": {
"host": "localhost",
"port": 81,
Expand Down
8 changes: 8 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ if [[ "$RECORDLOG_ENABLED" ]]; then
JQ_FILTERS_CONFIG="$JQ_FILTERS_CONFIG | .recordLog.enabled=true"
fi

if [[ "$CRR_METRICS_HOST" ]]; then
JQ_FILTERS_CONFIG="$JQ_FILTERS_CONFIG | .backbeat.host=\"$CRR_METRICS_HOST\""
fi

if [[ "$CRR_METRICS_PORT" ]]; then
JQ_FILTERS_CONFIG="$JQ_FILTERS_CONFIG | .backbeat.port=$CRR_METRICS_PORT"
fi

if [[ $JQ_FILTERS_CONFIG != "." ]]; then
jq "$JQ_FILTERS_CONFIG" config.json > config.json.tmp
mv config.json.tmp config.json
Expand Down
9 changes: 9 additions & 0 deletions lib/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,15 @@ class Config extends EventEmitter {
this.replicationEndpoints = replicationEndpoints;
}

if (config.backbeat) {
const { backbeat } = config;
assert.strictEqual(typeof backbeat.host, 'string',
'bad config: backbeat host must be a string');
assert(Number.isInteger(backbeat.port) && backbeat.port > 0,
'bad config: backbeat port must be a positive integer');
this.backbeat = backbeat;
}

// legacy
if (config.regions !== undefined) {
throw new Error('bad config: regions key is deprecated. ' +
Expand Down
42 changes: 42 additions & 0 deletions lib/utilities/reportHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const os = require('os');

const { errors, ipCheck } = require('arsenal');
const async = require('async');
const request = require('request');

const config = require('../Config').config;
const data = require('../data/wrapper');
Expand Down Expand Up @@ -73,6 +74,45 @@ function getSystemStats() {
};
}

function getCRRStats(log, cb) {
log.debug('getting CRR stats', { method: 'getCRRStats' });
// TODO: Reuse metrics code from Backbeat by moving it to Arsenal instead of
// making an HTTP request to the Backbeat metrics route.
const { host, port } = config.backbeat;
const params = { url: `http://${host}:${port}/_/metrics/crr/all` };
return request.get(params, (err, res) => {
if (err) {
log.error('failed to get CRR stats', {
method: 'getCRRStats',
error: err,
});
return cb(null, {});
}
const { completions, backlog, throughput } = res.body;
if (!completions || !backlog || !throughput) {
log.error('could not get metrics from backbeat', {
method: 'getCRRStats',
});
return cb(null, {});
}
const stats = {
completions: {
count: completions.results.count,
size: parseFloat(completions.results.size) * 1000,
},
backlog: {
count: backlog.results.count,
size: parseFloat(backlog.results.size) * 1000,
},
throughput: {
count: parseFloat(throughput.results.count) * 1000,
size: parseFloat(throughput.results.size) * 1000,
},
};
return cb(null, stats);
}).json();
}

/**
* Sends back a report
*
Expand All @@ -97,6 +137,7 @@ function reportHandler(clientIP, req, res, log) {
getDataDiskUsage: cb => data.getDiskUsage(log, cb),
getVersion: cb => getGitVersion(cb),
getObjectCount: cb => metadata.countItems(log, cb),
getCRRStats: cb => getCRRStats(log, cb),
},
(err, results) => {
if (err) {
Expand All @@ -114,6 +155,7 @@ function reportHandler(clientIP, req, res, log) {
serverVersion: results.getVersion,
systemStats: getSystemStats(),
itemCounts: results.getObjectCount,
crrStats: results.getCRRStats,

config: cleanup(config),
};
Expand Down