From 2a2ab494bde6f937d8f8cff3215f5bf54d9d0aed Mon Sep 17 00:00:00 2001 From: ekremney Date: Tue, 3 Sep 2024 11:56:53 +0200 Subject: [PATCH] fix(exp-opportunities): bump the rumapi client version and rename the audit --- package-lock.json | 16 +++++----- package.json | 2 +- .../experimentation-opportunities.js} | 31 +++++-------------- src/index.js | 10 +++--- ... => experimentation-opportunities.test.js} | 4 +-- 5 files changed, 24 insertions(+), 39 deletions(-) rename src/{opportunities/opportunities.js => experimentation-opportunities/experimentation-opportunities.js} (63%) rename test/audits/{opportunities.test.js => experimentation-opportunities.test.js} (95%) diff --git a/package-lock.json b/package-lock.json index d64b8aca..162c3d97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@adobe/spacecat-shared-data-access": "1.43.3", "@adobe/spacecat-shared-google-client": "1.2.2", "@adobe/spacecat-shared-http-utils": "1.6.8", - "@adobe/spacecat-shared-rum-api-client": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?0ffe830c28130f8ad8050a5c8ac0226ccd54e3b0", + "@adobe/spacecat-shared-rum-api-client": "2.9.0", "@adobe/spacecat-shared-rum-api-client-v1": "npm:@adobe/spacecat-shared-rum-api-client@1.8.4", "@adobe/spacecat-shared-utils": "1.19.6", "@aws-sdk/client-lambda": "3.637.0", @@ -5548,15 +5548,15 @@ } }, "node_modules/@adobe/spacecat-shared-rum-api-client": { - "version": "2.8.0", - "resolved": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?0ffe830c28130f8ad8050a5c8ac0226ccd54e3b0", - "integrity": "sha512-BBqrCh7fP+eWWReMjpI6lyCnAKJGx3PFpY/1ivhqIZIONYN6NOOxqbCpyQgR+/yAFu2k9aprbGjum2lEC9FtRg==", + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/@adobe/spacecat-shared-rum-api-client/-/spacecat-shared-rum-api-client-2.9.0.tgz", + "integrity": "sha512-VbtFFeQP/+/DJ9W+z09oMqLQfbGizmInScKv1xJs9di8lXRQislKofR/rC8Aak2Bu0d4odfdhjyywpxwLBggBg==", "dependencies": { "@adobe/fetch": "4.1.8", "@adobe/helix-shared-wrap": "2.0.2", "@adobe/helix-universal": "5.0.5", "@adobe/spacecat-shared-utils": "1.4.0", - "aws4": "1.13.1", + "aws4": "1.13.2", "d3-array": "3.2.4", "urijs": "^1.19.11" }, @@ -5663,9 +5663,9 @@ "license": "Apache-2.0" }, "node_modules/@adobe/spacecat-shared-rum-api-client/node_modules/aws4": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.13.1.tgz", - "integrity": "sha512-u5w79Rd7SU4JaIlA/zFqG+gOiuq25q5VLyZ8E+ijJeILuTxVzZgp2CaGw/UTw6pXYN9XMO9yiqj/nEHmhTG5CA==" + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.13.2.tgz", + "integrity": "sha512-lHe62zvbTB5eEABUVi/AwVh0ZKY9rMMDhmm+eeyuuUQbQ3+J+fONVQOZyj+DdrvD4BY33uYniyRJ4UJIaSKAfw==" }, "node_modules/@adobe/spacecat-shared-utils": { "version": "1.19.6", diff --git a/package.json b/package.json index 0b4ed547..26efbf15 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@adobe/spacecat-shared-data-access": "1.43.3", "@adobe/spacecat-shared-google-client": "1.2.2", "@adobe/spacecat-shared-http-utils": "1.6.8", - "@adobe/spacecat-shared-rum-api-client": "https://gitpkg.now.sh/adobe/spacecat-shared/packages/spacecat-shared-rum-api-client?0ffe830c28130f8ad8050a5c8ac0226ccd54e3b0", + "@adobe/spacecat-shared-rum-api-client": "2.9.0", "@adobe/spacecat-shared-rum-api-client-v1": "npm:@adobe/spacecat-shared-rum-api-client@1.8.4", "@aws-sdk/client-lambda": "3.637.0", "@aws-sdk/credential-provider-node": "3.637.0", diff --git a/src/opportunities/opportunities.js b/src/experimentation-opportunities/experimentation-opportunities.js similarity index 63% rename from src/opportunities/opportunities.js rename to src/experimentation-opportunities/experimentation-opportunities.js index 1d7b1008..28f38417 100644 --- a/src/opportunities/opportunities.js +++ b/src/experimentation-opportunities/experimentation-opportunities.js @@ -10,7 +10,6 @@ * governing permissions and limitations under the License. */ -/* c8 ignore start */ import RUMAPIClient from '@adobe/spacecat-shared-rum-api-client'; import { AuditBuilder } from '../common/audit-builder.js'; import { getRUMDomainkey } from '../support/utils.js'; @@ -22,8 +21,6 @@ const OPPTY_QUERIES = [ 'high-organic-low-ctr', ]; -let log = console; - /** * Audit handler container for all the opportunities * @param {*} auditUrl @@ -32,10 +29,8 @@ let log = console; * @returns */ -export async function opportunitiesHandler(auditUrl, context, site) { - log = context.log; - log.info(`Received Opportunities audit request for ${auditUrl}`); - const startTime = process.hrtime(); +export async function handler(auditUrl, context, site) { + const { log } = context; const rumAPIClient = RUMAPIClient.createFrom(context); const domainkey = await getRUMDomainkey(site.getBaseURL(), context); @@ -47,28 +42,18 @@ export async function opportunitiesHandler(auditUrl, context, site) { }; const queryResults = await rumAPIClient.queryMulti(OPPTY_QUERIES, options); - const auditData = { - experimentationOpportunities: [], - }; - for (const queryResult of Object.keys(queryResults)) { - if (OPPTY_QUERIES.includes(queryResult)) { - auditData.experimentationOpportunities.push(...queryResults[queryResult]); - } - } - - const endTime = process.hrtime(startTime); - const elapsedSeconds = endTime[0] + endTime[1] / 1e9; - const formattedElapsed = elapsedSeconds.toFixed(2); + const experimentationOpportunities = Object.values(queryResults).flatMap((oppty) => oppty); - log.info(`Opportunities Audit is completed in ${formattedElapsed} seconds for ${auditUrl}`); + log.info(`Found ${experimentationOpportunities.length} many experimentation opportunites for ${auditUrl}`); return { - auditResult: auditData, + auditResult: { + experimentationOpportunities, + }, fullAuditRef: auditUrl, }; } export default new AuditBuilder() - .withRunner(opportunitiesHandler) + .withRunner(handler) .build(); -/* c8 ignore stop */ diff --git a/src/index.js b/src/index.js index a99c7086..19b7cfd2 100644 --- a/src/index.js +++ b/src/index.js @@ -29,7 +29,7 @@ import experimentation from './experimentation/handler.js'; import conversion from './conversion/handler.js'; import essExperimentationDaily from './experimentation-ess/daily.js'; import essExperimentationAll from './experimentation-ess/all.js'; -import opportunities from './opportunities/opportunities.js'; +import experimentationOpportunities from './experimentation-opportunities/experimentation-opportunities.js'; import costs from './costs/handler.js'; import structuredData from './structured-data/handler.js'; @@ -46,7 +46,7 @@ const HANDLERS = { conversion, 'experimentation-ess-daily': essExperimentationDaily, 'experimentation-ess-all': essExperimentationAll, - opportunities, + 'experimentation-opportunities': experimentationOpportunities, costs, 'structured-data': structuredData, dummy: (message) => ok(message), @@ -68,7 +68,7 @@ async function run(message, context) { const { log } = context; const { type, url } = message; - log.info(`Audit req received for url: ${url}`); + log.info(`Received ${type} audit request for: ${url}`); const handler = HANDLERS[type]; if (!handler) { @@ -82,11 +82,11 @@ async function run(message, context) { try { const result = await (typeof handler.run === 'function' ? handler.run(message, context) : handler(message, context)); - log.info(`Audit for ${type} completed in ${getElapsedSeconds(startTime)} seconds`); + log.info(`${type} audit for ${url} completed in ${getElapsedSeconds(startTime)} seconds`); return result; } catch (e) { - log.error(`Audit failed after ${getElapsedSeconds(startTime)} seconds`, e); + log.error(`${type} audit for ${url} failed after ${getElapsedSeconds(startTime)} seconds`, e); return internalServerError(); } } diff --git a/test/audits/opportunities.test.js b/test/audits/experimentation-opportunities.test.js similarity index 95% rename from test/audits/opportunities.test.js rename to test/audits/experimentation-opportunities.test.js index bb2ef5df..dfd17478 100644 --- a/test/audits/opportunities.test.js +++ b/test/audits/experimentation-opportunities.test.js @@ -16,7 +16,7 @@ import { expect, use } from 'chai'; import sinon from 'sinon'; import sinonChai from 'sinon-chai'; import nock from 'nock'; -import { opportunitiesHandler } from '../../src/opportunities/opportunities.js'; +import { handler } from '../../src/experimentation-opportunities/experimentation-opportunities.js'; import { MockContextBuilder } from '../shared.js'; import opportunitiesData from '../fixtures/opportunitiesdata.json' assert { type: 'json' }; @@ -91,7 +91,7 @@ describe('Opportunities Tests', () => { const site = { getBaseURL: () => 'https://abc.com', }; - const auditData = await opportunitiesHandler(url, context, site); + const auditData = await handler(url, context, site); const expected = Object.values(opportunitiesData).flatMap((data) => data);