Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routes parametrize #2569

Merged
merged 2 commits into from
Nov 6, 2024
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
3 changes: 2 additions & 1 deletion lib/api/BackbeatAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,14 @@ class BackbeatAPI {
const rDetails = bbRequest.getRouteDetails();
const route = bbRequest.getRoute();
const addKeys = {};
const disableAdditionalRoutes = !this._queuePopulator.mongo;

this._updateConfigSites();
const routes = getRoutesFn({
crr: this._crrSites,
ingestion: this._ingestionSites,
lifecycle: this._lifecycleSites,
});
}, disableAdditionalRoutes);

// first validate healthcheck routes or prom routes since they do not
// have rDetails set
Expand Down
99 changes: 52 additions & 47 deletions lib/api/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
* @param {Array} locations.crr - The list of replication location names
* @param {Array} locations.ingestion - The list of ingestion location names
* @param {Array} locations.lifecycle - The list of lifecycle location names
* @param {Boolean} disableAdditionalRoutes - Whether to disable additional routes
* @return {Array} The array of route objects
*/
function routes(locations) {
function routes(locations, disableAdditionalRoutes) {
/* eslint-disable no-param-reassign */
locations.crr = locations.crr || [];
locations.ingestion = locations.ingestion || [];
locations.lifecycle = locations.lifecycle || [];
/* eslint-enable no-param-reassign */

return [
const routesArray = [
// Route: /_/healthcheck
{
httpMethod: 'GET',
Expand All @@ -26,19 +26,6 @@ function routes(locations) {
method: 'getHealthcheck',
extensions: {},
},
// Route: /_/metrics/crr/<location>/pending
// Route: /_/metrics/ingestion/<location>/pending
{
httpMethod: 'GET',
category: 'metrics',
type: 'pending',
extensions: {
crr: [...locations.crr, 'all'],
ingestion: [...locations.ingestion, 'all'],
},
method: 'getPending',
dataPoints: ['opsPending', 'bytesPending'],
},
// Route: /_/metrics/crr/<location>/backlog
{
httpMethod: 'GET',
Expand All @@ -61,15 +48,6 @@ function routes(locations) {
method: 'getCompletions',
dataPoints: ['opsDone', 'bytesDone'],
},
// Route: /_/metrics/crr/<location>/failures
{
httpMethod: 'GET',
category: 'metrics',
type: 'failures',
extensions: { crr: [...locations.crr, 'all'] },
method: 'getFailedMetrics',
dataPoints: ['opsFail', 'bytesFail'],
},
// Route: /_/metrics/crr/<location>/throughput
// Route: /_/metrics/ingestion/<location>/throughput
{
Expand All @@ -96,6 +74,52 @@ function routes(locations) {
method: 'getAllMetrics',
dataPoints: ['ops', 'opsDone', 'opsFail', 'bytes', 'bytesDone',
'bytesFail', 'opsPending', 'bytesPending'],
},
// Route: /_/crr/failed?site=<site>&marker=<marker>
{
httpMethod: 'GET',
type: 'all',
extensions: { crr: ['failed'] },
method: 'getSiteFailedCRR',
},
// Route: /_/crr/failed/<bucket>/<key>/<versionId>
{
httpMethod: 'GET',
type: 'specific',
extensions: { crr: ['failed'] },
method: 'getFailedCRR',
},
// Route: /_/crr/failed
{
httpMethod: 'POST',
type: 'all',
extensions: { crr: ['failed'] },
method: 'retryFailedCRR',
},
];
if (!disableAdditionalRoutes) {
routesArray.push(
// Route: /_/metrics/crr/<location>/pending
// Route: /_/metrics/ingestion/<location>/pending
{
httpMethod: 'GET',
category: 'metrics',
type: 'pending',
extensions: {
crr: [...locations.crr, 'all'],
ingestion: [...locations.ingestion, 'all'],
},
method: 'getPending',
dataPoints: ['opsPending', 'bytesPending'],
},
// Route: /_/metrics/crr/<location>/failures
{
httpMethod: 'GET',
category: 'metrics',
type: 'failures',
extensions: { crr: [...locations.crr, 'all'] },
method: 'getFailedMetrics',
dataPoints: ['opsFail', 'bytesFail'],
},
// Route: /_/metrics/crr/<site>/progress/<bucket>/<key>
{
Expand All @@ -117,27 +141,6 @@ function routes(locations) {
method: 'getObjectThroughput',
dataPoints: ['objectBytesDone'],
},
// Route: /_/crr/failed?site=<site>&marker=<marker>
{
httpMethod: 'GET',
type: 'all',
extensions: { crr: ['failed'] },
method: 'getSiteFailedCRR',
},
// Route: /_/crr/failed/<bucket>/<key>/<versionId>
{
httpMethod: 'GET',
type: 'specific',
extensions: { crr: ['failed'] },
method: 'getFailedCRR',
},
// Route: /_/crr/failed
{
httpMethod: 'POST',
type: 'all',
extensions: { crr: ['failed'] },
method: 'retryFailedCRR',
},
// Route: /_/monitoring/metrics
{
httpMethod: 'GET',
Expand Down Expand Up @@ -222,7 +225,9 @@ function routes(locations) {
method: 'applyWorkflowConfiguration',
extensions: {},
},
];
);
}
return routesArray;
}

module.exports = routes;
123 changes: 123 additions & 0 deletions tests/unit/api/routes.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
const assert = require('assert');
const routes = require('../../../lib/api/routes');

describe('routes', () => {
it('should generate the correct routes with default locations', () => {
const locations = {
crr: ['site1', 'site2'],
ingestion: ['site3'],
lifecycle: ['site4'],
};
const disableAdditionalRoutes = false;
const result = routes(locations, disableAdditionalRoutes);

assert.strictEqual(result.length, 19);

assert.deepStrictEqual(result[0], {
httpMethod: 'GET',
category: 'healthcheck',
type: 'basic',
method: 'getHealthcheck',
extensions: {},
});

assert.deepStrictEqual(result[1], {
httpMethod: 'GET',
category: 'metrics',
type: 'backlog',
extensions: { crr: ['site1', 'site2', 'all'] },
method: 'getBacklog',
dataPoints: ['opsPending', 'bytesPending'],
});

assert.deepStrictEqual(result[2], {
httpMethod: 'GET',
category: 'metrics',
type: 'completions',
extensions: {
crr: ['site1', 'site2', 'all'],
ingestion: ['site3', 'all'],
},
method: 'getCompletions',
dataPoints: ['opsDone', 'bytesDone'],
});
});

it('should generate the correct routes with additional routes disabled', () => {
const locations = {
crr: ['site1', 'site2'],
ingestion: ['site3'],
lifecycle: ['site4'],
};
const disableAdditionalRoutes = true;
const result = routes(locations, disableAdditionalRoutes);

assert.strictEqual(result.length, 8);
assert.deepStrictEqual(result[0], {
httpMethod: 'GET',
category: 'healthcheck',
type: 'basic',
method: 'getHealthcheck',
extensions: {},
});

assert.deepStrictEqual(result[1], {
httpMethod: 'GET',
category: 'metrics',
type: 'backlog',
extensions: { crr: ['site1', 'site2', 'all'] },
method: 'getBacklog',
dataPoints: ['opsPending', 'bytesPending'],
});

assert.deepStrictEqual(result[2], {
httpMethod: 'GET',
category: 'metrics',
type: 'completions',
extensions: {
crr: ['site1', 'site2', 'all'],
ingestion: ['site3', 'all'],
},
method: 'getCompletions',
dataPoints: ['opsDone', 'bytesDone'],
});
});

it('should handle empty locations', () => {
const locations = {};
const disableAdditionalRoutes = false;
const result = routes(locations, disableAdditionalRoutes);

assert.strictEqual(result.length, 19);

assert.deepStrictEqual(result[0], {
httpMethod: 'GET',
category: 'healthcheck',
type: 'basic',
method: 'getHealthcheck',
extensions: {},
});

assert.deepStrictEqual(result[1], {
httpMethod: 'GET',
category: 'metrics',
type: 'backlog',
extensions: { crr: ['all'] },
method: 'getBacklog',
dataPoints: ['opsPending', 'bytesPending'],
});

assert.deepStrictEqual(result[2], {
httpMethod: 'GET',
category: 'metrics',
type: 'completions',
extensions: {
crr: ['all'],
ingestion: ['all'],
},
method: 'getCompletions',
dataPoints: ['opsDone', 'bytesDone'],
});

});
});
Loading