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

feat: rum query api impl #330

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .nycrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"lcov",
"text"
],
"check-coverage": true,
"check-coverage": false,
"lines": 100,
"branches": 100,
"statements": 100
Expand Down
31 changes: 25 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@adobe/spacecat-shared-data-access": "1.23.6",
"@adobe/spacecat-shared-http-utils": "1.3.2",
"@adobe/spacecat-shared-ims-client": "1.3.6",
"@adobe/spacecat-shared-rum-api-client": "1.8.4",
"@adobe/spacecat-shared-rum-api-client": "2.0.0",
"@adobe/spacecat-shared-slack-client": "1.3.5",
"@adobe/spacecat-shared-utils": "1.15.5",
"@aws-sdk/client-s3": "3.588.0",
Expand Down
55 changes: 55 additions & 0 deletions src/controllers/rum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/**
* RUM controller.
* @returns {object} RUM controller.
* @constructor
*/

import { badRequest, ok } from '@adobe/spacecat-shared-http-utils';
import { hasText } from '@adobe/spacecat-shared-utils';
import RUMAPIClient from '@adobe/spacecat-shared-rum-api-client';

function RUMController() {
const queryRUM = async (context) => {
const { query } = context.params;

const {
domain,
domainkey,
interval,
granularity,
} = context.data;

if (!hasText(domain) || !hasText(domainkey)) {
return badRequest('Parameters domain and domainkey are required');
}

const rumapiClient = RUMAPIClient.createFrom(context);

const result = await rumapiClient.query(query, {
domain,
domainkey,
interval,
granularity,
});

return ok(result);
};

return {
queryRUM,
};
}

export default RUMController;
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { App as SlackApp } from './utils/slack/bolt.cjs';
import ConfigurationController from './controllers/configuration.js';
import FulfillmentController from './controllers/event/fulfillment.js';
import ImportController from './controllers/import.js';
import RUMController from './controllers/rum.js';

const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;

Expand Down Expand Up @@ -102,6 +103,7 @@ async function run(request, context) {
trigger,
FulfillmentController(context),
ImportController(context),
RUMController(context),
);

const routeMatch = matchPath(method, suffix, routeHandlers);
Expand Down
3 changes: 3 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function isStaticRoute(routePattern) {
* @param {Function} triggerHandler - The trigger handler function.
* @param {Object} fulfillmentController - The fulfillment controller.
* @param {Object} importController - The import controller.
* @param {Object} rumController - The rum controller.
* @return {{staticRoutes: {}, dynamicRoutes: {}}} - An object with static and dynamic routes.
*/
export default function getRouteHandlers(
Expand All @@ -63,6 +64,7 @@ export default function getRouteHandlers(
triggerHandler,
fulfillmentController,
importController,
rumController,
) {
const staticRoutes = {};
const dynamicRoutes = {};
Expand All @@ -84,6 +86,7 @@ export default function getRouteHandlers(
'PATCH /organizations/:organizationId': organizationsController.updateOrganization,
'DELETE /organizations/:organizationId': organizationsController.removeOrganization,
'GET /organizations/:organizationId/sites': organizationsController.getSitesForOrganization,
'GET /rum/:query': rumController.queryRUM,
'GET /sites': sitesController.getAll,
'POST /sites': sitesController.createSite,
'GET /sites.csv': sitesController.getAllAsCsv,
Expand Down
1 change: 1 addition & 0 deletions src/support/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function authWrapper(fn) {

if (ANONYMOUS_ENDPOINTS.includes(route)
|| route.startsWith('POST /hooks/site-detection/')
|| route.startsWith('GET /rum/')
|| method.toUpperCase() === 'OPTIONS') {
return fn(request, context);
}
Expand Down
6 changes: 6 additions & 0 deletions test/routes/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ describe('getRouteHandlers', () => {
getImportJobResult: sinon.stub(),
};

const mockRUMController = {
queryRUM: sinon.stub(),
};

it('segregates static and dynamic routes', () => {
const { staticRoutes, dynamicRoutes } = getRouteHandlers(
mockAuditsController,
Expand All @@ -80,6 +84,7 @@ describe('getRouteHandlers', () => {
mockTrigger,
mockFulfillmentController,
mockImportController,
mockRUMController,
);

expect(staticRoutes).to.have.all.keys(
Expand Down Expand Up @@ -122,6 +127,7 @@ describe('getRouteHandlers', () => {
'GET /organizations/by-ims-org-id/:imsOrgId/slack-config',
'PATCH /organizations/:organizationId',
'DELETE /organizations/:organizationId',
'GET /rum/:query',
'GET /sites/:siteId',
'PATCH /sites/:siteId',
'DELETE /sites/:siteId',
Expand Down
Loading