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

fix: making the stats lambda ARN configurable for dev and prod #331

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
17 changes: 9 additions & 8 deletions src/experimentation-ess/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const EXPERIMENT_PLUGIN_OPTIONS = {
};

const METRIC_CHECKPOINTS = ['click', 'convert', 'formsubmit'];
const SPACECAT_STATISTICS_SERVICE_ARN = 'arn:aws:lambda:us-east-1:282898975672:function:spacecat-services--statistics-service';

let log = console;

Expand Down Expand Up @@ -351,21 +350,21 @@ function mergeData(experiment, experimentMetadata, url) {
return experiment;
}

async function invokeLambdaFunction(payload) {
async function invokeLambdaFunction(payload, lambdaARN) {
const lambdaClient = new LambdaClient({
region: 'us-east-1',
credentials: defaultProvider(),
});
const invokeParams = {
FunctionName: SPACECAT_STATISTICS_SERVICE_ARN,
FunctionName: lambdaARN,
InvocationType: 'RequestResponse',
Payload: JSON.stringify(payload),
};
const response = await lambdaClient.send(new InvokeCommand(invokeParams));
return JSON.parse(new TextDecoder().decode(response.Payload));
}

async function addPValues(experimentData) {
async function addPValues(experimentData, lambdaARN) {
const lambdaPayload = {
type: 'statsig',
payload: {
Expand All @@ -386,7 +385,7 @@ async function addPValues(experimentData) {
log.info('Lambda Payload: ', JSON.stringify(lambdaPayload, null, 2));
let lambdaResult;
try {
const lambdaResponse = await invokeLambdaFunction(lambdaPayload);
const lambdaResponse = await invokeLambdaFunction(lambdaPayload, lambdaARN);
log.info('Lambda Response: ', JSON.stringify(lambdaResponse, null, 2));
const lambdaResponseBody = typeof (lambdaResponse.body) === 'string' ? JSON.parse(lambdaResponse.body) : lambdaResponse.body;
lambdaResult = lambdaResponseBody.result;
Expand Down Expand Up @@ -502,10 +501,12 @@ async function convertToExperimentsSchema(experimentInsights) {
return experiments;
}

async function processExperimentRUMData(experimentInsights) {
async function processExperimentRUMData(experimentInsights, context) {
const lambdaARN = context.env.SPACECAT_STATISTICS_LAMBDA_ARN;
log.info('Lambda ARN: ', lambdaARN);
log.info('Experiment Insights: ', JSON.stringify(experimentInsights, null, 2));
const experimentData = await convertToExperimentsSchema(experimentInsights);
await addPValues(experimentData);
await addPValues(experimentData, lambdaARN);
return experimentData;
}

Expand All @@ -521,7 +522,7 @@ export async function processAudit(auditURL, context, site, days) {
granularity: 'hourly',
};
const experimentData = await rumAPIClient.query('experiment', options);
return processExperimentRUMData(experimentData);
return processExperimentRUMData(experimentData, context);
}

export async function postProcessor(auditUrl, auditData, context) {
Expand Down
Loading